]> granicus.if.org Git - re2c/commitdiff
- Add configuration to generate yybm in hexadecimal (much better for manual
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Mon, 2 Jan 2006 11:19:31 +0000 (11:19 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Mon, 2 Jan 2006 11:19:31 +0000 (11:19 +0000)
  verification)
- Add tests

12 files changed:
bootstrap/scanner.cc
code.cc
dfa.cc
dfa.h
globals.h
main.cc
re2c.1.in
scanner.re
test/input10.b.c [new file with mode: 0755]
test/input10.b.re [new file with mode: 0755]
test/input11.b.c [new file with mode: 0755]
test/input11.b.re [new file with mode: 0755]

index 4081285f4532175ceaeabd6e1a9f5cbecc2b2023..199da8fa0a501bcc1be0bbd558c01ada2f58f8db 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.10.0.dev on Mon Jan  2 11:47:26 2006 */
+/* Generated by re2c 0.10.0.dev on Mon Jan  2 12:03:02 2006 */
 #line 1 "scanner.re"
 /* $Id$ */
 #include <stdlib.h>
@@ -1329,9 +1329,15 @@ void Scanner::config(const Str& cfg, int num)
                        fatal("configuration 'indent:top' must be a positive integer");
                }
                topIndent = num;
-               return;
        }
-       fatal("unrecognized configuration name or illegal integer value");
+       else if (cfg.to_string() == "yybm:hex")
+       {
+               yybmHexTable = num != 0;
+       }
+       else
+       {
+               fatal("unrecognized configuration name or illegal integer value");
+       }
 }
 
 void Scanner::config(const Str& cfg, const Str& val)
@@ -1350,7 +1356,10 @@ void Scanner::config(const Str& cfg, const Str& val)
                }
                return;
        }
-       fatal("unrecognized configuration name or illegal string value");
+       else
+       {
+               fatal("unrecognized configuration name or illegal string value");
+       }
 }
 
 } // end namespace re2c
diff --git a/code.cc b/code.cc
index 689d6708f3407dd0ff33ca20fdd4d6c954cae905..a0478bedf472c3ca88c446403d8cf278ce85c3b6 100644 (file)
--- a/code.cc
+++ b/code.cc
@@ -232,7 +232,15 @@ void BitMap::gen(std::ostream &o, uint ind, uint lb, uint ub)
                                        ++oline;
                                }
 
-                               o << std::setw(3) << (uint) bm[j] << ", ";
+                               if (yybmHexTable)
+                               {
+                                       prtHex(o, bm[j], false);
+                               }
+                               else
+                               {
+                                       o << std::setw(3) << (uint)bm[j];
+                               }
+                               o  << ", ";
                        }
                }
 
@@ -781,7 +789,16 @@ void Go::genGoto(std::ostream &o, uint ind, const State *from, const State *next
                                                sYych = "yych";
                                                o << indent(ind);
                                        }
-                                       o << "if(yybm[" << b->i << "+" << sYych << "] & " << (uint) b->m << ") {\n";
+                                       o << "if(yybm[" << b->i << "+" << sYych << "] & ";
+                                       if (yybmHexTable)
+                                       {
+                                               prtHex(o, b->m, false);
+                                       }
+                                       else
+                                       {
+                                               o << (uint) b->m;
+                                       }
+                                       o << ") {\n";
                                        oline++;
                                        genGoTo(o, ind+1, from, to, readCh);
                                        o << indent(ind) << "}\n";
diff --git a/dfa.cc b/dfa.cc
index 8df1837d45507690f92332d149f6b80c499a5832..d538afd86e81196be6585be8c8aff8a69ec18bd8 100644 (file)
--- a/dfa.cc
+++ b/dfa.cc
@@ -8,9 +8,9 @@
 namespace re2c
 {
 
-void prtChOrHex(std::ostream& o, uint c)
+void prtChOrHex(std::ostream& o, uint c, bool useTalx)
 {
-       int oc = (int)(re2c::wFlag ? c : re2c::talx[c]);
+       int oc = (int)(re2c::wFlag || !useTalx ? c : re2c::talx[c]);
 
        if ((oc < 256) && isprint(oc))
        {
@@ -18,7 +18,17 @@ void prtChOrHex(std::ostream& o, uint c)
                prtCh(o, oc);
                o << '\'';
        }
-       else if (re2c::wFlag)
+       else
+       {
+               prtHex(o, c);
+       }
+}
+
+void prtHex(std::ostream& o, uint c, bool useTalx)
+{
+       int oc = (int)(re2c::wFlag || !useTalx ? c : re2c::talx[c]);
+
+       if (re2c::wFlag)
        {
                o << "0x"
                  << hexCh(oc >> 12)
@@ -34,9 +44,9 @@ void prtChOrHex(std::ostream& o, uint c)
        }
 }
 
-void prtCh(std::ostream &o, uint c)
+void prtCh(std::ostream &o, uint c, bool useTalx)
 {
-       int oc = (int)(re2c::wFlag ? c : re2c::talx[c]);
+       int oc = (int)(re2c::wFlag || !useTalx ? c : re2c::talx[c]);
 
        switch (oc)
        {
diff --git a/dfa.h b/dfa.h
index 58b7a65aff486aebcff6cd4bf0f628f0058faf49..f72fbf562c614205653b3ab1daae095c71789131 100644 (file)
--- a/dfa.h
+++ b/dfa.h
@@ -8,8 +8,9 @@
 namespace re2c
 {
 
-extern void prtCh(std::ostream&, uint);
-extern void prtChOrHex(std::ostream&, uint);
+extern void prtCh(std::ostream&, uint, bool useTalx = true);
+extern void prtHex(std::ostream&, uint, bool useTalx = true);
+extern void prtChOrHex(std::ostream&, uint, bool useTalx = true);
 extern void printSpan(std::ostream&, uint, uint);
 
 class DFA;
index ea67f6ef3fbe8f34bd9ea951c06d793d26f52f17..f81fc70a3aa7ad7fb276da44d97aa73959e0495d 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -22,8 +22,11 @@ extern bool wFlag;
 extern bool bUsedYYAccept;
 extern unsigned int oline;
 extern uint maxFill;
+
+/* configurations */
 extern uint topIndent;
 extern std::string indString;
+extern bool yybmHexTable;
 
 extern uint asc2ebc[256];
 extern uint ebc2asc[256];
diff --git a/main.cc b/main.cc
index 6c3da1f9b2edc4a4fcfc05a5c215266c20a51922..9e5b8a422951b476baa01dfcaa3b0ad38885ede0 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -29,8 +29,11 @@ bool wFlag = false;
 bool bUsedYYAccept = false;
 unsigned int oline = 1;
 uint maxFill = 1;
+
 uint topIndent = 0;
 std::string indString("\t");
+bool yybmHexTable = false;
+
 uint nRealChars = 256;
 
 int vFillIndexes = -1;
index a1c52a5fa9b66adfa6148808120d61eee4d3ca6a..f78adaec10742625d389b228621befe9ce29d9eb 100644 (file)
--- a/re2c.1.in
+++ b/re2c.1.in
@@ -7,6 +7,11 @@
 .ds rx regular expression
 .ds lx \fIl\fP-expression
 \"$Log$
+\"Revision 1.35  2006/01/02 11:19:31  helly
+\"- Add configuration to generate yybm in hexadecimal (much better for manual
+\"  verification)
+\"- Add tests
+\"
 \"Revision 1.34  2006/01/01 18:29:46  helly
 \"- Added ability to control indendation string
 \"
@@ -484,6 +489,10 @@ Specifies the minimum number of indendation to use (default is 0).
 .TP
 \fIre2c:indent:string\fP
 Specifies the string to use for indendation (default is "\\t").
+.TP
+\fIre2c:yybm:hex\fP
+If set to zero then a  decimal table is being used else a hexadecimal table 
+will be generated (default is 0).
 
 .SH "A LARGER EXAMPLE"
 .LP
index c163a2ebbe859f950a72b1c408bc23149f3accec..dca102275171d5f9fbbbe683b088c9a7e0e89156 100644 (file)
@@ -326,9 +326,15 @@ void Scanner::config(const Str& cfg, int num)
                        fatal("configuration 'indent:top' must be a positive integer");
                }
                topIndent = num;
-               return;
        }
-       fatal("unrecognized configuration name or illegal integer value");
+       else if (cfg.to_string() == "yybm:hex")
+       {
+               yybmHexTable = num != 0;
+       }
+       else
+       {
+               fatal("unrecognized configuration name or illegal integer value");
+       }
 }
 
 void Scanner::config(const Str& cfg, const Str& val)
@@ -347,7 +353,10 @@ void Scanner::config(const Str& cfg, const Str& val)
                }
                return;
        }
-       fatal("unrecognized configuration name or illegal string value");
+       else
+       {
+               fatal("unrecognized configuration name or illegal string value");
+       }
 }
 
 } // end namespace re2c
diff --git a/test/input10.b.c b/test/input10.b.c
new file mode 100755 (executable)
index 0000000..0ba255f
--- /dev/null
@@ -0,0 +1,40 @@
+/* Generated by re2c */
+#line 1 "input10.b.re"
+{
+
+#line 6 "<stdout>"
+       {
+               YYCTYPE yych;
+               goto yy0;
+               ++YYCURSOR;
+yy0:
+               if(YYLIMIT == YYCURSOR) YYFILL(1);
+               yych = *YYCURSOR;
+               if(yych <= 'E') {
+                       if(yych <= '@') goto yy4;
+                       if(yych >= 'E') goto yy4;
+                       goto yy2;
+               } else {
+                       if(yych <= 'G') goto yy2;
+                       if(yych <= '`') goto yy4;
+                       if(yych >= 'h') goto yy4;
+                       goto yy2;
+               }
+yy2:
+               ++YYCURSOR;
+               goto yy3;
+yy3:
+#line 8 "input10.b.re"
+               { return 1; }
+#line 30 "<stdout>"
+yy4:
+               ++YYCURSOR;
+               goto yy5;
+yy5:
+#line 10 "input10.b.re"
+               { return -1; }
+#line 37 "<stdout>"
+       }
+}
+#line 12 "input10.b.re"
+
diff --git a/test/input10.b.re b/test/input10.b.re
new file mode 100755 (executable)
index 0000000..dc0a771
--- /dev/null
@@ -0,0 +1,12 @@
+/*!re2c
+
+a = [aA];
+b = [bB];
+c = [cC];
+d = [dD];
+
+(a|b|c|d|"e"|'f'|[gG])  { return 1; }
+
+.|"\n"                         { return -1; }
+
+*/
diff --git a/test/input11.b.c b/test/input11.b.c
new file mode 100755 (executable)
index 0000000..fab7ea3
--- /dev/null
@@ -0,0 +1,167 @@
+/* Generated by re2c */
+#line 1 "input11.b.re"
+{
+       static unsigned char yybm[] = {
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 
+               0xE0, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 
+               0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 
+               0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 
+               0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x80, 
+               0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 
+               0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 
+               0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 
+               0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+       };
+
+#line 40 "<stdout>"
+       {
+               YYCTYPE yych;
+               unsigned int yyaccept = 0;
+               goto yy0;
+               ++YYCURSOR;
+yy0:
+               if((YYLIMIT - YYCURSOR) < 6) YYFILL(6);
+               yych = *YYCURSOR;
+               if(yych <= '@') {
+                       if(yych <= '/') {
+                               if(yych == '-') goto yy7;
+                               goto yy10;
+                       } else {
+                               if(yych <= '0') goto yy5;
+                               if(yych <= '9') goto yy9;
+                               goto yy10;
+                       }
+               } else {
+                       if(yych <= 'q') {
+                               if(yych <= 'Z') goto yy4;
+                               if(yych <= '`') goto yy10;
+                               goto yy4;
+                       } else {
+                               if(yych <= 'r') goto yy2;
+                               if(yych <= 'z') goto yy4;
+                               goto yy10;
+                       }
+               }
+yy2:
+               ++YYCURSOR;
+               if((yych = *YYCURSOR) == 'e') goto yy15;
+               goto yy14;
+yy3:
+#line 12 "input11.b.re"
+               { return 1; }
+#line 76 "<stdout>"
+yy4:
+               yych = *++YYCURSOR;
+               goto yy14;
+yy5:
+               ++YYCURSOR;
+               goto yy6;
+yy6:
+#line 13 "input11.b.re"
+               { return 2; }
+#line 86 "<stdout>"
+yy7:
+               ++YYCURSOR;
+               if((yych = *YYCURSOR) <= '0') goto yy8;
+               if(yych <= '9') goto yy11;
+               goto yy8;
+yy8:
+#line 15 "input11.b.re"
+               { return -1; }
+#line 95 "<stdout>"
+yy9:
+               yych = *++YYCURSOR;
+               goto yy12;
+yy10:
+               yych = *++YYCURSOR;
+               goto yy8;
+yy11:
+               ++YYCURSOR;
+               if(YYLIMIT == YYCURSOR) YYFILL(1);
+               yych = *YYCURSOR;
+               goto yy12;
+yy12:
+               if(yybm[0+yych] & 0x20) {
+                       goto yy11;
+               }
+               goto yy6;
+yy13:
+               ++YYCURSOR;
+               if(YYLIMIT == YYCURSOR) YYFILL(1);
+               yych = *YYCURSOR;
+               goto yy14;
+yy14:
+               if(yybm[0+yych] & 0x40) {
+                       goto yy13;
+               }
+               goto yy3;
+yy15:
+               yych = *++YYCURSOR;
+               if(yych != '2') goto yy14;
+               goto yy16;
+yy16:
+               yych = *++YYCURSOR;
+               if(yych != 'c') goto yy14;
+               goto yy17;
+yy17:
+               yyaccept = 0;
+               yych = *(YYMARKER = ++YYCURSOR);
+               if(yych != ':') goto yy14;
+               goto yy18;
+yy18:
+               yych = *++YYCURSOR;
+               if(yych <= '^') {
+                       if(yych <= '@') goto yy19;
+                       if(yych <= 'Z') goto yy20;
+                       goto yy19;
+               } else {
+                       if(yych == '`') goto yy19;
+                       if(yych <= 'z') goto yy20;
+                       goto yy19;
+               }
+yy19:
+               YYCURSOR = YYMARKER;
+               switch(yyaccept){
+               case 0: goto yy3;
+               }
+yy20:
+               ++YYCURSOR;
+               if(YYLIMIT == YYCURSOR) YYFILL(1);
+               yych = *YYCURSOR;
+               goto yy21;
+yy21:
+               if(yybm[0+yych] & 0x80) {
+                       goto yy20;
+               }
+               goto yy22;
+yy22:
+#line 11 "input11.b.re"
+               { return 0; }
+#line 164 "<stdout>"
+       }
+}
+#line 17 "input11.b.re"
+
diff --git a/test/input11.b.re b/test/input11.b.re
new file mode 100755 (executable)
index 0000000..705eca7
--- /dev/null
@@ -0,0 +1,17 @@
+/*!re2c
+
+re2c:yybm:hex = 1;
+
+letter  = [a-zA-Z];
+digit   = [0-9];
+number  = "0" | ("-"? [1-9] digit*);
+name    = letter (letter|digit)*;
+config  = "re2c:" (letter|"_") (letter|digit|"_"|":")*;
+
+config { return 0; }
+name   { return 1; }
+number { return 2; }
+
+.|"\n" { return -1; }
+
+*/