From: helly Date: Mon, 2 Jan 2006 11:19:31 +0000 (+0000) Subject: - Add configuration to generate yybm in hexadecimal (much better for manual X-Git-Tag: 0.13.6~511 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd76a6a2abcc010972455c3837ff91889fdb824f;p=re2c - Add configuration to generate yybm in hexadecimal (much better for manual verification) - Add tests --- diff --git a/bootstrap/scanner.cc b/bootstrap/scanner.cc index 4081285f..199da8fa 100644 --- a/bootstrap/scanner.cc +++ b/bootstrap/scanner.cc @@ -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 @@ -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 689d6708..a0478bed 100644 --- 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 8df1837d..d538afd8 100644 --- 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 58b7a65a..f72fbf56 100644 --- 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; diff --git a/globals.h b/globals.h index ea67f6ef..f81fc70a 100644 --- 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 6c3da1f9..9e5b8a42 100644 --- 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; diff --git a/re2c.1.in b/re2c.1.in index a1c52a5f..f78adaec 100644 --- 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 diff --git a/scanner.re b/scanner.re index c163a2eb..dca10227 100644 --- a/scanner.re +++ b/scanner.re @@ -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 index 00000000..0ba255f1 --- /dev/null +++ b/test/input10.b.c @@ -0,0 +1,40 @@ +/* Generated by re2c */ +#line 1 "input10.b.re" +{ + +#line 6 "" + { + 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 "" +yy4: + ++YYCURSOR; + goto yy5; +yy5: +#line 10 "input10.b.re" + { return -1; } +#line 37 "" + } +} +#line 12 "input10.b.re" + diff --git a/test/input10.b.re b/test/input10.b.re new file mode 100755 index 00000000..dc0a7713 --- /dev/null +++ b/test/input10.b.re @@ -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 index 00000000..fab7ea3f --- /dev/null +++ b/test/input11.b.c @@ -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 "" + { + 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 "" +yy4: + yych = *++YYCURSOR; + goto yy14; +yy5: + ++YYCURSOR; + goto yy6; +yy6: +#line 13 "input11.b.re" + { return 2; } +#line 86 "" +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 "" +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 "" + } +} +#line 17 "input11.b.re" + diff --git a/test/input11.b.re b/test/input11.b.re new file mode 100755 index 00000000..705eca76 --- /dev/null +++ b/test/input11.b.re @@ -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; } + +*/