]> granicus.if.org Git - re2c/commitdiff
- Improve names for condition jump table and condition state variable
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Thu, 19 Apr 2007 01:08:03 +0000 (01:08 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Thu, 19 Apr 2007 01:08:03 +0000 (01:08 +0000)
- Add first working test (as it uses -g it only works with newer gcc)

re2c/code.cc
re2c/test/condition_01.c.c
re2c/test/condition_02.c.c
re2c/test/condition_02.cg.c
re2c/test/condition_03.cg.c
re2c/test/condition_04.cg.c
re2c/test/condition_05.cg.c [new file with mode: 0755]
re2c/test/condition_05.cg.re [new file with mode: 0755]

index 3be5d3f6cab1da175426387e07e4905b4555cc42..45b854329901b0d715e34e4857491479a9b82f50 100644 (file)
@@ -1666,7 +1666,7 @@ void genCondTable(std::ostream &o, uint ind, const RegExpMap* specMap)
 {
        if (cFlag && !bWroteCondCheck && gFlag)
        {
-               o << indent(ind++) << "static void *" << mapCodeName["yycond"] << "[" << specMap->size() << "] = {\n";
+               o << indent(ind++) << "static void *" << mapCodeName["yyctable"] << "[" << specMap->size() << "] = {\n";
 
                for(RegExpMap::const_iterator it = specMap->begin(); it != specMap->end(); ++it)
                {
@@ -1682,11 +1682,11 @@ void genCondGoto(std::ostream &o, uint ind, const RegExpMap* specMap)
        {
                if (gFlag)
                {
-                       o << indent(ind) << "goto *" << mapCodeName["yycond"] << "[" << mapCodeName["YYCOND"] << "];\n";
+                       o << indent(ind) << "goto *" << mapCodeName["yyctable"] << "[" << mapCodeName["YYCONDITION"] << "];\n";
                }
                else
                {
-                       o << indent(ind) << "switch(" << mapCodeName["YYCOND"] << ") {\n";
+                       o << indent(ind) << "switch(" << mapCodeName["YYCONDITION"] << ") {\n";
                        for(RegExpMap::const_iterator it = specMap->begin(); it != specMap->end(); ++it)
                        {
                                o << indent(ind) << "case " << it->first << ": goto " << condPrefix << it->first << ";\n";
@@ -1780,7 +1780,9 @@ void Scanner::config(const Str& cfg, const Str& val)
                mapVariableKeys.insert("variable:yyaccept");
                mapVariableKeys.insert("variable:yybm");
                mapVariableKeys.insert("variable:yych");
+               mapVariableKeys.insert("variable:yyctable");
                mapVariableKeys.insert("variable:yytarget");
+               mapDefineKeys.insert("define:YYCONDITION");
                mapDefineKeys.insert("define:YYCTXMARKER");
                mapDefineKeys.insert("define:YYCTYPE");
                mapDefineKeys.insert("define:YYCURSOR");
index b3f1d2147ffa6396b008155a2ed7f41e64b2dc68..0343dfafefa1268d60b26c26632a0e8ee0b5b793 100755 (executable)
@@ -4,7 +4,7 @@
 #line 5 "<stdout>"
 {
        YYCTYPE yych;
-       switch(YYCOND) {
+       switch(YYCONDITION) {
        case a: goto yyc_a;
        case b: goto yyc_b;
        }
index 8d8a1db2bb4f9ac3af110e99560553b0824a8e2a..7644fbcfe6e8c7de9ca09d74e9431977586deaba 100755 (executable)
@@ -4,7 +4,7 @@
 #line 5 "<stdout>"
 {
        YYCTYPE yych;
-       switch(YYCOND) {
+       switch(YYCONDITION) {
        case 0: goto yyc_0;
        case r1: goto yyc_r1;
        case r2: goto yyc_r2;
index da0d59e36c1527f36968f7826dccc298510dad0e..dfb1816f4f4ca727bfb5c2abdbce7fcc646ae326 100755 (executable)
@@ -4,12 +4,12 @@
 #line 5 "<stdout>"
 {
        YYCTYPE yych;
-       static void *yycond[3] = {
+       static void *yyctable[3] = {
                &&yyc_0,
                &&yyc_r1,
                &&yyc_r2,
        };
-       goto *yycond[YYCOND];
+       goto *yyctable[YYCONDITION];
 /* *********************************** */
 yyc_0:
 
index e477542543368efa5698e3312bfa1577852f816f..76a0da7e6b7c5faf7b097e62b96386515d0cb3ba 100755 (executable)
@@ -4,12 +4,12 @@
 #line 5 "<stdout>"
 {
        YYCTYPE yych;
-       static void *yycond[3] = {
+       static void *yyctable[3] = {
                &&yyc_0,
                &&yyc_r1,
                &&yyc_r2,
        };
-       goto *yycond[YYCOND];
+       goto *yyctable[YYCONDITION];
 /* *********************************** */
 yyc_0:
 
index da1b8ce243246bbc0eee29d42895e97bb5dcc723..b996a8d13b166d48b2d06cc1b9da7fbdfd751561 100755 (executable)
@@ -4,11 +4,11 @@
 #line 5 "<stdout>"
 {
        YYCTYPE yych;
-       static void *yycond[2] = {
+       static void *yyctable[2] = {
                &&yyc_r1,
                &&yyc_r2,
        };
-       goto *yycond[YYCOND];
+       goto *yyctable[YYCONDITION];
 /* *********************************** */
 yyc_r1:
 
diff --git a/re2c/test/condition_05.cg.c b/re2c/test/condition_05.cg.c
new file mode 100755 (executable)
index 0000000..162e3c3
--- /dev/null
@@ -0,0 +1,150 @@
+/* Generated by re2c */
+#line 1 "condition_05.cg.re"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define        BSIZE   8192
+
+typedef struct Scanner
+{
+       FILE                    *fp;
+       unsigned char   *cur, *tok, *lim, *eof;
+       unsigned char   buffer[BSIZE];
+} Scanner;
+
+int fill(Scanner *s, int len)
+{
+       if (!len)
+       {
+               s->cur = s->tok = s->lim = s->buffer;
+               s->eof = 0;
+       }
+       if (!s->eof)
+       {
+               int got, cnt = s->tok - s->buffer;
+
+               if (cnt > 0)
+               {
+                       memcpy(s->buffer, s->tok, s->lim - s->tok);
+                       s->tok -= cnt;
+                       s->cur -= cnt;
+                       s->lim -= cnt;
+               }
+               cnt = BSIZE - cnt;
+               if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
+               {
+                       s->eof = &s->lim[got];
+               }
+               s->lim += got;
+       }
+       else if (s->cur + len > s->eof)
+       {
+               return 0; /* not enough input data */
+       }
+       return -1;
+}
+
+char scan(Scanner *s)
+{
+       int state = 1;
+       
+       fill(s, 0);
+
+       for(;;)
+       {
+               s->tok = s->cur;
+
+#line 59 "<stdout>"
+{
+       unsigned char yych;
+       static void *yyctable[2] = {
+               &&yyc_comment,
+               &&yyc_normal,
+       };
+       goto *yyctable[state];
+/* *********************************** */
+yyc_comment:
+
+       if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; };
+       yych = *s->cur;
+       if(yych != '*') goto yy4;
+       ++s->cur;
+       if((yych = *s->cur) == '/') goto yy5;
+yy3:
+#line 79 "condition_05.cg.re"
+       {
+                               goto yyc_comment;
+                       }
+#line 80 "<stdout>"
+yy4:
+       yych = *++s->cur;
+       goto yy3;
+yy5:
+       ++s->cur;
+#line 75 "condition_05.cg.re"
+       {
+                               continue;
+                       }
+#line 90 "<stdout>"
+/* *********************************** */
+yyc_normal:
+       if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; };
+       yych = *s->cur;
+       if(yych != '/') goto yy11;
+       ++s->cur;
+       if((yych = *s->cur) == '*') goto yy12;
+yy10:
+#line 70 "condition_05.cg.re"
+       {
+                               fputc(*s->tok, stdout);
+                               continue;
+                       }
+#line 104 "<stdout>"
+yy11:
+       yych = *++s->cur;
+       goto yy10;
+yy12:
+       ++s->cur;
+#line 66 "condition_05.cg.re"
+       {
+                               goto yyc_comment;
+                       }
+#line 114 "<stdout>"
+}
+#line 83 "condition_05.cg.re"
+
+       }
+}
+
+int main(int argc, char **argv)
+{
+       Scanner in;
+       char c;
+
+       if (argc != 2)
+       {
+               fprintf(stderr, "%s <file>\n", argv[0]);
+               return 1;;
+       }
+
+       memset((char*) &in, 0, sizeof(in));
+
+       if (!strcmp(argv[1], "-"))
+       {
+               in.fp = stdin;
+       }
+       else if ((in.fp = fopen(argv[1], "r")) == NULL)
+       {
+               fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
+               return 1;
+       }
+
+       scan(&in);
+
+       if (in.fp != stdin)
+       {
+               fclose(in.fp);
+       }
+       return 0;
+}
diff --git a/re2c/test/condition_05.cg.re b/re2c/test/condition_05.cg.re
new file mode 100755 (executable)
index 0000000..32db8d5
--- /dev/null
@@ -0,0 +1,117 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define        BSIZE   8192
+
+typedef struct Scanner
+{
+       FILE                    *fp;
+       unsigned char   *cur, *tok, *lim, *eof;
+       unsigned char   buffer[BSIZE];
+} Scanner;
+
+int fill(Scanner *s, int len)
+{
+       if (!len)
+       {
+               s->cur = s->tok = s->lim = s->buffer;
+               s->eof = 0;
+       }
+       if (!s->eof)
+       {
+               int got, cnt = s->tok - s->buffer;
+
+               if (cnt > 0)
+               {
+                       memcpy(s->buffer, s->tok, s->lim - s->tok);
+                       s->tok -= cnt;
+                       s->cur -= cnt;
+                       s->lim -= cnt;
+               }
+               cnt = BSIZE - cnt;
+               if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
+               {
+                       s->eof = &s->lim[got];
+               }
+               s->lim += got;
+       }
+       else if (s->cur + len > s->eof)
+       {
+               return 0; /* not enough input data */
+       }
+       return -1;
+}
+
+char scan(Scanner *s)
+{
+       int state = 1;
+       
+       fill(s, 0);
+
+       for(;;)
+       {
+               s->tok = s->cur;
+/*!re2c
+
+re2c:define:YYCTYPE     = "unsigned char";
+re2c:define:YYCURSOR    = s->cur;
+re2c:define:YYLIMIT     = s->lim;
+re2c:define:YYMARKER    = s->ptr;
+re2c:define:YYFILL      = "{ if(fill(s, 2) >= 0) break; }";
+re2c:define:YYCONDITION = state;
+re2c:yyfill:parameter   = 0;
+
+<normal>       "/*"
+                       {
+                               goto yyc_comment;
+                       }
+<normal>       [^]
+                       {
+                               fputc(*s->tok, stdout);
+                               continue;
+                       }
+<comment>      "*" "/"
+                       {
+                               continue;
+                       }
+<comment>      [^]
+                       {
+                               goto yyc_comment;
+                       }
+
+*/
+       }
+}
+
+int main(int argc, char **argv)
+{
+       Scanner in;
+       char c;
+
+       if (argc != 2)
+       {
+               fprintf(stderr, "%s <file>\n", argv[0]);
+               return 1;;
+       }
+
+       memset((char*) &in, 0, sizeof(in));
+
+       if (!strcmp(argv[1], "-"))
+       {
+               in.fp = stdin;
+       }
+       else if ((in.fp = fopen(argv[1], "r")) == NULL)
+       {
+               fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
+               return 1;
+       }
+
+       scan(&in);
+
+       if (in.fp != stdin)
+       {
+               fclose(in.fp);
+       }
+       return 0;
+}