From: Peter Johnson Date: Sun, 9 Oct 2005 20:29:00 +0000 (-0000) Subject: re2c: Fix yyaccept warnings. X-Git-Tag: v0.5.0rc1~104 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ccec93a51e0d38d90efb2c20f8b9e4b2811c07b5;p=yasm re2c: Fix yyaccept warnings. svn path=/trunk/yasm/; revision=1274 --- diff --git a/tools/re2c/code.c b/tools/re2c/code.c index bf6ce429..55d001a4 100644 --- a/tools/re2c/code.c +++ b/tools/re2c/code.c @@ -215,12 +215,26 @@ static void indent(FILE *o, unsigned int i){ static void need(FILE *o, unsigned int n, int *readCh) { + unsigned int fillIndex; + int hasFillIndex = (0<=vFillIndexes); + if (hasFillIndex) { + fillIndex = vFillIndexes++; + fprintf(o, "\tYYSETSTATE(%u);\n", fillIndex); + ++oline; + } + if(n == 1) { fputs("\tif(YYLIMIT == YYCURSOR) YYFILL(1);\n", o); oline++; } else { fprintf(o, "\tif((YYLIMIT - YYCURSOR) < %u) YYFILL(%u);\n", n, n); oline++; } + + if (hasFillIndex) { + fprintf(o, "yyFillLabel%u:\n", fillIndex); + ++oline; + } + fputs("\tyych = *YYCURSOR;\n", o); oline++; *readCh = 0; } @@ -262,7 +276,10 @@ Action_emit(Action *a, FILE *o, int *readCh) } break; case SAVEMATCHACT: - fprintf(o, "\tyyaccept = %u;\n", a->d.selector); oline++; + if (bUsedYYAccept) { + fprintf(o, "\tyyaccept = %u;\n", a->d.selector); + oline++; + } if(a->state->link){ fputs("\tYYMARKER = ++YYCURSOR;\n", o); oline++; need(o, a->state->depth, readCh); @@ -278,6 +295,7 @@ Action_emit(Action *a, FILE *o, int *readCh) if(a->d.Accept.saves[i] != ~0u){ if(first){ first = 0; + bUsedYYAccept = 1; fputs("\tYYCURSOR = YYMARKER;\n", o); fputs("\tswitch(yyaccept){\n", o); oline+=2; } @@ -614,8 +632,11 @@ static unsigned int maxDist(State *s){ State *t = s->go.span[i].to; if(t){ unsigned int m = 1; - if(!t->link) - m += maxDist(t); + if(!t->link) { + if (t->depth == -1) + t->depth = maxDist(t); + m += t->depth; + } if(m > mm) mm = m; } @@ -677,7 +698,7 @@ void DFA_split(DFA *d, State *s){ void DFA_emit(DFA *d, FILE *o){ static unsigned int label = 0; State *s; - unsigned int i; + unsigned int i, bitmap_brace = 0; unsigned int nRules = 0; unsigned int nSaves = 0; unsigned int *saves; @@ -686,14 +707,21 @@ void DFA_emit(DFA *d, FILE *o){ State *accept = NULL; Span *span; FILE *tmpo; + int hasFillLabels; + int maxFillIndexes, orgVFillIndexes; + unsigned int start_label; DFA_findSCCs(d); d->head->link = d->head; - d->head->depth = maxDist(d->head); - for(s = d->head; s; s = s->next) + maxFill = 1; + for(s = d->head; s; s = s->next) { + s->depth = maxDist(s); + if (maxFill < s->depth) + maxFill = s->depth; if(s->rule && s->rule->d.RuleOp.accept >= nRules) nRules = s->rule->d.RuleOp.accept + 1; + } saves = malloc(sizeof(unsigned int)*nRules); memset(saves, ~0, (nRules)*sizeof(unsigned int)); @@ -783,38 +811,84 @@ void DFA_emit(DFA *d, FILE *o){ free(d->head->action); - oline++; - fprintf(o, "\n#line %u \"%s\"\n", ++oline, outputFileName); + if(bFlag) { + fputs("{\n", o); + oline++; + bitmap_brace = 1; + BitMap_gen(o, d->lbChar, d->ubChar); + } - fputs("{\n\tYYCTYPE yych;\n\tunsigned int yyaccept;\n", o); oline+=3; + bUsedYYAccept = 0; - if(bFlag) - BitMap_gen(o, d->lbChar, d->ubChar); + start_label = label; - fprintf(o, "\tgoto yy%u;\n", label); oline++; - useLabel(label); Action_new_Enter(d->head, label++); for(s = d->head; s; s = s->next) s->label = label++; nOrgOline = oline; + maxFillIndexes = vFillIndexes; + orgVFillIndexes = vFillIndexes; tmpo = fopen("re2c.tmp", "wt"); for(s = d->head; s; s = s->next){ int readCh = 0; State_emit(s, tmpo, &readCh); - Go_genGoto(&s->go, o, s, s->next, &readCh); + Go_genGoto(&s->go, tmpo, s, s->next, &readCh); } fclose(tmpo); unlink("re2c.tmp"); + maxFillIndexes = vFillIndexes; + vFillIndexes = orgVFillIndexes; oline = nOrgOline; + hasFillLabels = (0<=vFillIndexes); + + oline++; + fprintf(o, "\n#line %u \"%s\"\n", ++oline, outputFileName); + + if (!hasFillLabels) { + fputs("{\n\tYYCTYPE yych;\n", o); + oline += 2; + if (bUsedYYAccept) { + fputs("\tunsigned int yyaccept;\n", o); + oline++; + } + } else { + fputs("{\n\n", o); + oline += 2; + } + + if (!hasFillLabels) { + fprintf(o, "\tgoto yy%u;\n", start_label); + oline++; + useLabel(label); + } else { + unsigned int i; + fputs("\tswitch(YYGETSTATE()) {\n", o); + fputs("\t\tcase -1: goto yy0;\n", o); + + for (i=0; ihead; s; s = s->next){ int readCh = 0; State_emit(s, o, &readCh); Go_genGoto(&s->go, o, s, s->next, &readCh); } fputs("}\n", o); oline++; + if (bitmap_brace) { + fputs("}\n", o); + oline++; + } BitMap_first = NULL; diff --git a/tools/re2c/globals.h b/tools/re2c/globals.h index 9f88f69c..2a1c1118 100644 --- a/tools/re2c/globals.h +++ b/tools/re2c/globals.h @@ -7,7 +7,10 @@ extern const char *fileName; extern const char *outputFileName; extern int sFlag; extern int bFlag; +extern int bUsedYYAccept; extern unsigned int oline; +extern unsigned int maxFill; +extern int vFillIndexes; extern unsigned char *vUsedLabels; extern unsigned int vUsedLabelAlloc; diff --git a/tools/re2c/main.c b/tools/re2c/main.c index aa1199d6..a4872e22 100644 --- a/tools/re2c/main.c +++ b/tools/re2c/main.c @@ -10,7 +10,10 @@ const char *fileName = 0; const char *outputFileName = 0; int sFlag = 0; int bFlag = 0; +int bUsedYYAccept = 0; unsigned int oline = 1; +unsigned int maxFill = 1; +int vFillIndexes = -1; unsigned char *vUsedLabels; unsigned int vUsedLabelAlloc = 1000; @@ -23,6 +26,7 @@ static const mbo_opt_struct OPTIONS[] = { {'e', 0, "ecb"}, {'h', 0, "help"}, {'s', 0, "nested-ifs"}, + {'f', 0, "storable-state"}, {'o', 1, "output"}, {'v', 0, "version"}, {'-', 0, NULL} /* end of args */ @@ -46,6 +50,8 @@ static void usage() "-s --nested-ifs Generate nested ifs for some switches. Many compilers\n" " need this assist to generate better code.\n" "\n" + "-f --storable-state Generate a scanner with support for storable state\n" + "\n" "-o --output=output Specify the output file instead of stdout\n" "\n" "-v --version Show version information.\n" @@ -77,6 +83,9 @@ int main(int argc, char *argv[]) case 's': sFlag = 1; break; + case 'f': + vFillIndexes = 0; + break; case 'o': outputFileName = opt_arg; break; diff --git a/tools/re2c/scanner.c b/tools/re2c/scanner.c index 6991fdda..8c9b5c7d 100644 --- a/tools/re2c/scanner.c +++ b/tools/re2c/scanner.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.9.1-C on Sun Oct 9 00:12:08 2005 +/* Generated by re2c 0.9.1-C on Sun Oct 9 01:08:48 2005 */ #line 1 "scanner.re" #include @@ -7,6 +7,7 @@ #include "tools/re2c/parse.h" #include "tools/re2c/globals.h" #include "re2c-parser.h" +#include "globals.h" #ifndef MAX #define MAX(a,b) (((a)>(b))?(a):(b)) @@ -68,13 +69,14 @@ fill(Scanner *s, unsigned char *cursor) return cursor; } -#line 78 "scanner.re" +#line 79 "scanner.re" int Scanner_echo(Scanner *s, FILE *out) { unsigned char *cursor = s->cur; + int ignore_eoc = 0; /* Catch EOF */ if (s->eof && cursor == s->eof) @@ -83,101 +85,128 @@ Scanner_echo(Scanner *s, FILE *out) s->tok = cursor; echo: -#line 87 "scanner.c" +#line 89 "scanner.c" { YYCTYPE yych; unsigned int yyaccept; goto yy0; - if(yych <= '\n'){ - if(yych <= '\000') goto yy6; - if(yych <= '\t') goto yy8; - goto yy4; - } else { - if(yych != '/') goto yy8; - goto yy2; - } - if(yych == '*') goto yy9; - goto yy3; - goto yy5; - goto yy7; - goto yy3; - if(yych == '!') goto yy11; - goto yy10; - if(yych != 'r') goto yy10; - goto yy12; - if(yych != 'e') goto yy10; - goto yy13; - if(yych != '2') goto yy10; - goto yy14; - if(yych != 'c') goto yy10; - goto yy15; - goto yy16; ++YYCURSOR; yy0: - if((YYLIMIT - YYCURSOR) < 7) YYFILL(7); + if((YYLIMIT - YYCURSOR) < 11) YYFILL(11); yych = *YYCURSOR; - if(yych <= '\n'){ - if(yych <= '\000') goto yy6; - if(yych <= '\t') goto yy8; - goto yy4; + if(yych <= ')'){ + if(yych <= '\000') goto yy7; + if(yych == '\n') goto yy5; + goto yy9; } else { - if(yych != '/') goto yy8; + if(yych <= '*') goto yy4; + if(yych != '/') goto yy9; goto yy2; } yy2: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if(yych == '*') goto yy9; + if(yych == '*') goto yy12; goto yy3; yy3: -#line 100 "scanner.re" +#line 117 "scanner.re" { goto echo; } -#line 111 "scanner.c" +#line 114 "scanner.c" yy4: yych = *++YYCURSOR; - goto yy5; -yy5: -#line 95 "scanner.re" + if(yych == '/') goto yy10; + goto yy3; +yy5: yych = *++YYCURSOR; + goto yy6; +yy6: +#line 112 "scanner.re" { fwrite(s->tok, 1, cursor - s->tok, out); s->tok = s->pos = cursor; s->cline++; oline++; goto echo; } -#line 119 "scanner.c" -yy6: yych = *++YYCURSOR; - goto yy7; -yy7: -#line 98 "scanner.re" +#line 125 "scanner.c" +yy7: yych = *++YYCURSOR; + goto yy8; +yy8: +#line 115 "scanner.re" { fwrite(s->tok, 1, cursor - s->tok - 1, out); /* -1 so we don't write out the \0 */ if(cursor == s->eof) { RETURN(0); } } -#line 126 "scanner.c" -yy8: yych = *++YYCURSOR; - goto yy3; +#line 132 "scanner.c" yy9: yych = *++YYCURSOR; - if(yych == '!') goto yy11; - goto yy10; -yy10: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy3; + goto yy3; +yy10: yych = *++YYCURSOR; + goto yy11; +yy11: +#line 103 "scanner.re" +{ + if (ignore_eoc) { + ignore_eoc = 0; + } else { + fwrite(s->tok, 1, cursor - s->tok, out); + } + s->tok = s->pos = cursor; + goto echo; } -yy11: yych = *++YYCURSOR; - if(yych != 'r') goto yy10; - goto yy12; +#line 148 "scanner.c" yy12: yych = *++YYCURSOR; - if(yych != 'e') goto yy10; + if(yych == '!') goto yy14; goto yy13; -yy13: yych = *++YYCURSOR; - if(yych != '2') goto yy10; - goto yy14; +yy13: YYCURSOR = YYMARKER; + switch(yyaccept){ + case 0: goto yy3; + } yy14: yych = *++YYCURSOR; - if(yych != 'c') goto yy10; - goto yy15; + if(yych == 'm') goto yy15; + if(yych == 'r') goto yy16; + goto yy13; yy15: yych = *++YYCURSOR; - goto yy16; -yy16: -#line 92 "scanner.re" + if(yych == 'a') goto yy21; + goto yy13; +yy16: yych = *++YYCURSOR; + if(yych != 'e') goto yy13; + goto yy17; +yy17: yych = *++YYCURSOR; + if(yych != '2') goto yy13; + goto yy18; +yy18: yych = *++YYCURSOR; + if(yych != 'c') goto yy13; + goto yy19; +yy19: yych = *++YYCURSOR; + goto yy20; +yy20: +#line 94 "scanner.re" { fwrite(s->tok, 1, &cursor[-7] - s->tok, out); s->tok = cursor; RETURN(1); } -#line 155 "scanner.c" +#line 179 "scanner.c" +yy21: yych = *++YYCURSOR; + if(yych != 'x') goto yy13; + goto yy22; +yy22: yych = *++YYCURSOR; + if(yych != ':') goto yy13; + goto yy23; +yy23: yych = *++YYCURSOR; + if(yych != 'r') goto yy13; + goto yy24; +yy24: yych = *++YYCURSOR; + if(yych != 'e') goto yy13; + goto yy25; +yy25: yych = *++YYCURSOR; + if(yych != '2') goto yy13; + goto yy26; +yy26: yych = *++YYCURSOR; + if(yych != 'c') goto yy13; + goto yy27; +yy27: yych = *++YYCURSOR; + goto yy28; +yy28: +#line 97 "scanner.re" +{ + fprintf(out, "#define YYMAXFILL %u\n", maxFill); + s->tok = s->pos = cursor; + ignore_eoc = 1; + goto echo; + } +#line 208 "scanner.c" } -#line 101 "scanner.re" +#line 118 "scanner.re" } @@ -193,689 +222,486 @@ scan: s->tline = s->cline; s->tok = cursor; -#line 173 "scanner.c" +#line 226 "scanner.c" { YYCTYPE yych; unsigned int yyaccept; - goto yy17; - if(yych <= '/'){ - if(yych <= '"'){ - if(yych <= '\n'){ - if(yych <= '\b') goto yy39; - if(yych <= '\t') goto yy35; - goto yy37; - } else { - if(yych == ' ') goto yy35; - if(yych <= '!') goto yy39; - goto yy25; - } - } else { - if(yych <= ')'){ - if(yych <= '&') goto yy39; - if(yych <= '\'') goto yy27; - goto yy31; - } else { - if(yych <= '*') goto yy23; - if(yych <= '+') goto yy32; - if(yych <= '.') goto yy39; - goto yy21; - } - } - } else { - if(yych <= '@'){ - if(yych <= '<'){ - if(yych == ';') goto yy31; - goto yy39; - } else { - if(yych <= '=') goto yy31; - if(yych == '?') goto yy32; - goto yy39; - } - } else { - if(yych <= '`'){ - if(yych <= 'Z') goto yy33; - if(yych <= '[') goto yy29; - if(yych <= '\\') goto yy31; - goto yy39; - } else { - if(yych <= 'z') goto yy33; - if(yych <= '{') goto yy19; - if(yych <= '|') goto yy31; - goto yy39; - } - } - } - if(yych <= '/') goto yy20; - if(yych <= '9') goto yy65; - goto yy20; - if(yych == '*') goto yy63; - goto yy22; - if(yych == '/') goto yy61; - goto yy24; - if(yych != '\n') goto yy57; - goto yy26; - if(yych != '\n') goto yy52; - goto yy28; - if(yych != '\n') goto yy46; - goto yy30; - goto yy22; - goto yy24; - goto yy44; - goto yy42; - goto yy38; - goto yy40; - goto yy42; - if(yych == '\t') goto yy41; - if(yych == ' ') goto yy41; - goto yy36; - goto yy44; - if(yych <= '@'){ - if(yych <= '/') goto yy34; - if(yych <= '9') goto yy43; - goto yy34; - } else { - if(yych <= 'Z') goto yy43; - if(yych <= '`') goto yy34; - if(yych <= 'z') goto yy43; - goto yy34; - } - goto yy46; - if(yych <= '['){ - if(yych != '\n') goto yy45; - goto yy47; - } else { - if(yych <= '\\') goto yy48; - if(yych <= ']') goto yy49; - goto yy45; - } - if(yych == '\n') goto yy47; - goto yy45; - goto yy50; - goto yy52; - if(yych <= '&'){ - if(yych == '\n') goto yy47; - goto yy51; - } else { - if(yych <= '\'') goto yy54; - if(yych != '\\') goto yy51; - goto yy53; - } - if(yych == '\n') goto yy47; - goto yy51; - goto yy55; - goto yy57; - if(yych <= '!'){ - if(yych == '\n') goto yy47; - goto yy56; - } else { - if(yych <= '"') goto yy59; - if(yych != '\\') goto yy56; - goto yy58; - } - if(yych == '\n') goto yy47; - goto yy56; - goto yy60; - goto yy62; - goto yy64; - goto yy66; - if(yych <= '/'){ - if(yych == ',') goto yy69; - goto yy47; - } else { - if(yych <= '9') goto yy65; - if(yych != '}') goto yy47; - goto yy67; - } - goto yy68; - if(yych != '}') goto yy73; - goto yy70; - goto yy71; - goto yy73; - if(yych <= '/') goto yy47; - if(yych <= '9') goto yy72; - if(yych != '}') goto yy47; - goto yy74; - goto yy75; + goto yy29; ++YYCURSOR; -yy17: +yy29: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; if(yych <= '/'){ if(yych <= '"'){ if(yych <= '\n'){ - if(yych <= '\b') goto yy39; - if(yych <= '\t') goto yy35; - goto yy37; + if(yych <= '\b') goto yy51; + if(yych <= '\t') goto yy47; + goto yy49; } else { - if(yych == ' ') goto yy35; - if(yych <= '!') goto yy39; - goto yy25; + if(yych == ' ') goto yy47; + if(yych <= '!') goto yy51; + goto yy37; } } else { if(yych <= ')'){ - if(yych <= '&') goto yy39; - if(yych <= '\'') goto yy27; - goto yy31; + if(yych <= '&') goto yy51; + if(yych <= '\'') goto yy39; + goto yy43; } else { - if(yych <= '*') goto yy23; - if(yych <= '+') goto yy32; - if(yych <= '.') goto yy39; - goto yy21; + if(yych <= '*') goto yy35; + if(yych <= '+') goto yy44; + if(yych <= '.') goto yy51; + goto yy33; } } } else { if(yych <= '@'){ if(yych <= '<'){ - if(yych == ';') goto yy31; - goto yy39; + if(yych == ';') goto yy43; + goto yy51; } else { - if(yych <= '=') goto yy31; - if(yych == '?') goto yy32; - goto yy39; + if(yych <= '=') goto yy43; + if(yych == '?') goto yy44; + goto yy51; } } else { if(yych <= '`'){ - if(yych <= 'Z') goto yy33; - if(yych <= '[') goto yy29; - if(yych <= '\\') goto yy31; - goto yy39; + if(yych <= 'Z') goto yy45; + if(yych <= '[') goto yy41; + if(yych <= '\\') goto yy43; + goto yy51; } else { - if(yych <= 'z') goto yy33; - if(yych <= '{') goto yy19; - if(yych <= '|') goto yy31; - goto yy39; + if(yych <= 'z') goto yy45; + if(yych <= '{') goto yy31; + if(yych <= '|') goto yy43; + goto yy51; } } } -yy19: yyaccept = 0; +yy31: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if(yych <= '/') goto yy20; - if(yych <= '9') goto yy65; - goto yy20; -yy20: -#line 116 "scanner.re" + if(yych <= '/') goto yy32; + if(yych <= '9') goto yy77; + goto yy32; +yy32: +#line 133 "scanner.re" { depth = 1; goto code; } -#line 239 "scanner.c" -yy21: yych = *++YYCURSOR; - if(yych == '*') goto yy63; - goto yy22; -yy22: -#line 142 "scanner.re" +#line 292 "scanner.c" +yy33: yych = *++YYCURSOR; + if(yych == '*') goto yy75; + goto yy34; +yy34: +#line 159 "scanner.re" { RETURN(*s->tok); } -#line 246 "scanner.c" -yy23: yych = *++YYCURSOR; - if(yych == '/') goto yy61; - goto yy24; -yy24: -#line 144 "scanner.re" +#line 299 "scanner.c" +yy35: yych = *++YYCURSOR; + if(yych == '/') goto yy73; + goto yy36; +yy36: +#line 161 "scanner.re" { yylval.op = *s->tok; RETURN(CLOSE); } -#line 254 "scanner.c" -yy25: yyaccept = 1; +#line 307 "scanner.c" +yy37: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); - if(yych != '\n') goto yy57; - goto yy26; -yy26: -#line 133 "scanner.re" + if(yych != '\n') goto yy69; + goto yy38; +yy38: +#line 150 "scanner.re" { Scanner_fatal(s, "unterminated string constant (missing \")"); } -#line 262 "scanner.c" -yy27: yyaccept = 2; +#line 315 "scanner.c" +yy39: yyaccept = 2; yych = *(YYMARKER = ++YYCURSOR); - if(yych != '\n') goto yy52; - goto yy28; -yy28: -#line 134 "scanner.re" + if(yych != '\n') goto yy64; + goto yy40; +yy40: +#line 151 "scanner.re" { Scanner_fatal(s, "unterminated string constant (missing ')"); } -#line 270 "scanner.c" -yy29: yyaccept = 3; +#line 323 "scanner.c" +yy41: yyaccept = 3; yych = *(YYMARKER = ++YYCURSOR); - if(yych != '\n') goto yy46; - goto yy30; -yy30: -#line 140 "scanner.re" + if(yych != '\n') goto yy58; + goto yy42; +yy42: +#line 157 "scanner.re" { Scanner_fatal(s, "unterminated range (missing ])"); } -#line 278 "scanner.c" -yy31: yych = *++YYCURSOR; - goto yy22; -yy32: yych = *++YYCURSOR; - goto yy24; -yy33: yych = *++YYCURSOR; - goto yy44; -yy34: -#line 159 "scanner.re" +#line 331 "scanner.c" +yy43: yych = *++YYCURSOR; + goto yy34; +yy44: yych = *++YYCURSOR; + goto yy36; +yy45: yych = *++YYCURSOR; + goto yy56; +yy46: +#line 176 "scanner.re" { SubStr substr; s->cur = cursor; substr = Scanner_token(s); yylval.symbol = Symbol_find(&substr); return ID; } -#line 292 "scanner.c" -yy35: yych = *++YYCURSOR; - goto yy42; -yy36: -#line 165 "scanner.re" +#line 345 "scanner.c" +yy47: yych = *++YYCURSOR; + goto yy54; +yy48: +#line 182 "scanner.re" { goto scan; } -#line 298 "scanner.c" -yy37: yych = *++YYCURSOR; - goto yy38; -yy38: -#line 167 "scanner.re" +#line 351 "scanner.c" +yy49: yych = *++YYCURSOR; + goto yy50; +yy50: +#line 184 "scanner.re" { if(cursor == s->eof) RETURN(0); s->pos = cursor; s->cline++; goto scan; } -#line 307 "scanner.c" -yy39: yych = *++YYCURSOR; - goto yy40; -yy40: -#line 172 "scanner.re" +#line 360 "scanner.c" +yy51: yych = *++YYCURSOR; + goto yy52; +yy52: +#line 189 "scanner.re" { fprintf(stderr, "unexpected character: '%c'\n", *s->tok); goto scan; } -#line 315 "scanner.c" -yy41: ++YYCURSOR; +#line 368 "scanner.c" +yy53: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy42; -yy42: if(yych == '\t') goto yy41; - if(yych == ' ') goto yy41; - goto yy36; -yy43: ++YYCURSOR; + goto yy54; +yy54: if(yych == '\t') goto yy53; + if(yych == ' ') goto yy53; + goto yy48; +yy55: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy44; -yy44: if(yych <= '@'){ - if(yych <= '/') goto yy34; - if(yych <= '9') goto yy43; - goto yy34; + goto yy56; +yy56: if(yych <= '@'){ + if(yych <= '/') goto yy46; + if(yych <= '9') goto yy55; + goto yy46; } else { - if(yych <= 'Z') goto yy43; - if(yych <= '`') goto yy34; - if(yych <= 'z') goto yy43; - goto yy34; + if(yych <= 'Z') goto yy55; + if(yych <= '`') goto yy46; + if(yych <= 'z') goto yy55; + goto yy46; } -yy45: ++YYCURSOR; +yy57: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy46; -yy46: if(yych <= '['){ - if(yych != '\n') goto yy45; - goto yy47; + goto yy58; +yy58: if(yych <= '['){ + if(yych != '\n') goto yy57; + goto yy59; } else { - if(yych <= '\\') goto yy48; - if(yych <= ']') goto yy49; - goto yy45; + if(yych <= '\\') goto yy60; + if(yych <= ']') goto yy61; + goto yy57; } -yy47: YYCURSOR = YYMARKER; +yy59: YYCURSOR = YYMARKER; switch(yyaccept){ - case 0: goto yy20; - case 1: goto yy26; - case 2: goto yy28; - case 3: goto yy30; + case 0: goto yy32; + case 1: goto yy38; + case 2: goto yy40; + case 3: goto yy42; } -yy48: ++YYCURSOR; +yy60: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == '\n') goto yy47; - goto yy45; -yy49: yych = *++YYCURSOR; - goto yy50; -yy50: -#line 136 "scanner.re" + if(yych == '\n') goto yy59; + goto yy57; +yy61: yych = *++YYCURSOR; + goto yy62; +yy62: +#line 153 "scanner.re" { s->cur = cursor; yylval.regexp = ranToRE(Scanner_token(s)); return RANGE; } -#line 368 "scanner.c" -yy51: ++YYCURSOR; +#line 421 "scanner.c" +yy63: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy52; -yy52: if(yych <= '&'){ - if(yych == '\n') goto yy47; - goto yy51; + goto yy64; +yy64: if(yych <= '&'){ + if(yych == '\n') goto yy59; + goto yy63; } else { - if(yych <= '\'') goto yy54; - if(yych != '\\') goto yy51; - goto yy53; + if(yych <= '\'') goto yy66; + if(yych != '\\') goto yy63; + goto yy65; } -yy53: ++YYCURSOR; +yy65: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == '\n') goto yy47; - goto yy51; -yy54: yych = *++YYCURSOR; - goto yy55; -yy55: -#line 129 "scanner.re" + if(yych == '\n') goto yy59; + goto yy63; +yy66: yych = *++YYCURSOR; + goto yy67; +yy67: +#line 146 "scanner.re" { s->cur = cursor; yylval.regexp = strToCaseInsensitiveRE(Scanner_token(s)); return STRING; } -#line 393 "scanner.c" -yy56: ++YYCURSOR; +#line 446 "scanner.c" +yy68: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy57; -yy57: if(yych <= '!'){ - if(yych == '\n') goto yy47; - goto yy56; + goto yy69; +yy69: if(yych <= '!'){ + if(yych == '\n') goto yy59; + goto yy68; } else { - if(yych <= '"') goto yy59; - if(yych != '\\') goto yy56; - goto yy58; + if(yych <= '"') goto yy71; + if(yych != '\\') goto yy68; + goto yy70; } -yy58: ++YYCURSOR; +yy70: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == '\n') goto yy47; - goto yy56; -yy59: yych = *++YYCURSOR; - goto yy60; -yy60: -#line 125 "scanner.re" + if(yych == '\n') goto yy59; + goto yy68; +yy71: yych = *++YYCURSOR; + goto yy72; +yy72: +#line 142 "scanner.re" { s->cur = cursor; yylval.regexp = strToRE(Scanner_token(s)); return STRING; } -#line 418 "scanner.c" -yy61: yych = *++YYCURSOR; - goto yy62; -yy62: -#line 122 "scanner.re" +#line 471 "scanner.c" +yy73: yych = *++YYCURSOR; + goto yy74; +yy74: +#line 139 "scanner.re" { s->tok = cursor; RETURN(0); } -#line 425 "scanner.c" -yy63: yych = *++YYCURSOR; - goto yy64; -yy64: -#line 119 "scanner.re" +#line 478 "scanner.c" +yy75: yych = *++YYCURSOR; + goto yy76; +yy76: +#line 136 "scanner.re" { depth = 1; goto comment; } -#line 432 "scanner.c" -yy65: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); +#line 485 "scanner.c" +yy77: ++YYCURSOR; + if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - goto yy66; -yy66: if(yych <= '/'){ - if(yych == ',') goto yy69; - goto yy47; + goto yy78; +yy78: if(yych <= '/'){ + if(yych == ',') goto yy81; + goto yy59; } else { - if(yych <= '9') goto yy65; - if(yych != '}') goto yy47; - goto yy67; + if(yych <= '9') goto yy77; + if(yych != '}') goto yy59; + goto yy79; } -yy67: yych = *++YYCURSOR; - goto yy68; -yy68: -#line 147 "scanner.re" +yy79: yych = *++YYCURSOR; + goto yy80; +yy80: +#line 164 "scanner.re" { yylval.extop.minsize = atoi((char *)s->tok+1); yylval.extop.maxsize = atoi((char *)s->tok+1); RETURN(CLOSESIZE); } -#line 452 "scanner.c" -yy69: yych = *++YYCURSOR; - if(yych != '}') goto yy73; - goto yy70; -yy70: yych = *++YYCURSOR; - goto yy71; -yy71: -#line 155 "scanner.re" +#line 505 "scanner.c" +yy81: yych = *++YYCURSOR; + if(yych != '}') goto yy85; + goto yy82; +yy82: yych = *++YYCURSOR; + goto yy83; +yy83: +#line 172 "scanner.re" { yylval.extop.minsize = atoi((char *)s->tok+1); yylval.extop.maxsize = -1; RETURN(CLOSESIZE); } -#line 463 "scanner.c" -yy72: ++YYCURSOR; +#line 516 "scanner.c" +yy84: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy73; -yy73: if(yych <= '/') goto yy47; - if(yych <= '9') goto yy72; - if(yych != '}') goto yy47; - goto yy74; -yy74: yych = *++YYCURSOR; - goto yy75; -yy75: -#line 151 "scanner.re" + goto yy85; +yy85: if(yych <= '/') goto yy59; + if(yych <= '9') goto yy84; + if(yych != '}') goto yy59; + goto yy86; +yy86: yych = *++YYCURSOR; + goto yy87; +yy87: +#line 168 "scanner.re" { yylval.extop.minsize = atoi((char *)s->tok+1); yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)s->tok, ',')+1)); RETURN(CLOSESIZE); } -#line 479 "scanner.c" +#line 532 "scanner.c" } -#line 175 "scanner.re" +#line 192 "scanner.re" code: -#line 486 "scanner.c" +#line 539 "scanner.c" { YYCTYPE yych; unsigned int yyaccept; - goto yy76; - if(yych <= '&'){ - if(yych <= '\n'){ - if(yych <= '\t') goto yy84; - goto yy82; - } else { - if(yych == '"') goto yy86; - goto yy84; - } - } else { - if(yych <= '{'){ - if(yych <= '\'') goto yy87; - if(yych <= 'z') goto yy84; - goto yy80; - } else { - if(yych != '}') goto yy84; - goto yy78; - } - } - goto yy79; - goto yy81; - goto yy83; - goto yy85; - if(yych == '\n') goto yy85; - goto yy93; - if(yych == '\n') goto yy85; - goto yy89; - goto yy89; - if(yych <= '&'){ - if(yych != '\n') goto yy88; - goto yy90; - } else { - if(yych <= '\'') goto yy84; - if(yych == '\\') goto yy91; - goto yy88; - } - if(yych == '\n') goto yy90; goto yy88; - goto yy93; - if(yych <= '!'){ - if(yych == '\n') goto yy90; - goto yy92; - } else { - if(yych <= '"') goto yy84; - if(yych != '\\') goto yy92; - goto yy94; - } - if(yych == '\n') goto yy90; - goto yy92; ++YYCURSOR; -yy76: +yy88: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; if(yych <= '&'){ if(yych <= '\n'){ - if(yych <= '\t') goto yy84; - goto yy82; + if(yych <= '\t') goto yy96; + goto yy94; } else { - if(yych == '"') goto yy86; - goto yy84; + if(yych == '"') goto yy98; + goto yy96; } } else { if(yych <= '{'){ - if(yych <= '\'') goto yy87; - if(yych <= 'z') goto yy84; - goto yy80; + if(yych <= '\'') goto yy99; + if(yych <= 'z') goto yy96; + goto yy92; } else { - if(yych != '}') goto yy84; - goto yy78; + if(yych != '}') goto yy96; + goto yy90; } } -yy78: yych = *++YYCURSOR; - goto yy79; -yy79: -#line 179 "scanner.re" +yy90: yych = *++YYCURSOR; + goto yy91; +yy91: +#line 196 "scanner.re" { if(--depth == 0){ s->cur = cursor; yylval.token = Token_new(Scanner_token(s), s->tline); return CODE; } goto code; } -#line 523 "scanner.c" -yy80: yych = *++YYCURSOR; - goto yy81; -yy81: -#line 185 "scanner.re" +#line 576 "scanner.c" +yy92: yych = *++YYCURSOR; + goto yy93; +yy93: +#line 202 "scanner.re" { ++depth; goto code; } -#line 530 "scanner.c" -yy82: yych = *++YYCURSOR; - goto yy83; -yy83: -#line 187 "scanner.re" +#line 583 "scanner.c" +yy94: yych = *++YYCURSOR; + goto yy95; +yy95: +#line 204 "scanner.re" { if(cursor == s->eof) Scanner_fatal(s, "missing '}'"); s->pos = cursor; s->cline++; goto code; } -#line 539 "scanner.c" -yy84: yych = *++YYCURSOR; - goto yy85; -yy85: -#line 191 "scanner.re" +#line 592 "scanner.c" +yy96: yych = *++YYCURSOR; + goto yy97; +yy97: +#line 208 "scanner.re" { goto code; } -#line 545 "scanner.c" -yy86: yyaccept = 0; +#line 598 "scanner.c" +yy98: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if(yych == '\n') goto yy85; - goto yy93; -yy87: yyaccept = 0; + if(yych == '\n') goto yy97; + goto yy105; +yy99: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - if(yych == '\n') goto yy85; - goto yy89; -yy88: ++YYCURSOR; + if(yych == '\n') goto yy97; + goto yy101; +yy100: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy89; -yy89: if(yych <= '&'){ - if(yych != '\n') goto yy88; - goto yy90; + goto yy101; +yy101: if(yych <= '&'){ + if(yych != '\n') goto yy100; + goto yy102; } else { - if(yych <= '\'') goto yy84; - if(yych == '\\') goto yy91; - goto yy88; + if(yych <= '\'') goto yy96; + if(yych == '\\') goto yy103; + goto yy100; } -yy90: YYCURSOR = YYMARKER; +yy102: YYCURSOR = YYMARKER; switch(yyaccept){ - case 0: goto yy85; + case 0: goto yy97; } -yy91: ++YYCURSOR; +yy103: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == '\n') goto yy90; - goto yy88; -yy92: ++YYCURSOR; + if(yych == '\n') goto yy102; + goto yy100; +yy104: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - goto yy93; -yy93: if(yych <= '!'){ - if(yych == '\n') goto yy90; - goto yy92; + goto yy105; +yy105: if(yych <= '!'){ + if(yych == '\n') goto yy102; + goto yy104; } else { - if(yych <= '"') goto yy84; - if(yych != '\\') goto yy92; - goto yy94; + if(yych <= '"') goto yy96; + if(yych != '\\') goto yy104; + goto yy106; } -yy94: ++YYCURSOR; +yy106: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if(yych == '\n') goto yy90; - goto yy92; + if(yych == '\n') goto yy102; + goto yy104; } -#line 192 "scanner.re" +#line 209 "scanner.re" comment: -#line 598 "scanner.c" +#line 651 "scanner.c" { YYCTYPE yych; - unsigned int yyaccept; - goto yy95; - if(yych <= ')'){ - if(yych == '\n') goto yy100; - goto yy102; - } else { - if(yych <= '*') goto yy97; - if(yych == '/') goto yy99; - goto yy102; - } - if(yych == '/') goto yy105; - goto yy98; - if(yych == '*') goto yy103; - goto yy98; - goto yy101; - goto yy98; - goto yy104; - goto yy106; + goto yy107; ++YYCURSOR; -yy95: +yy107: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; if(yych <= ')'){ - if(yych == '\n') goto yy100; - goto yy102; + if(yych == '\n') goto yy112; + goto yy114; } else { - if(yych <= '*') goto yy97; - if(yych == '/') goto yy99; - goto yy102; + if(yych <= '*') goto yy109; + if(yych == '/') goto yy111; + goto yy114; } -yy97: yych = *++YYCURSOR; - if(yych == '/') goto yy105; - goto yy98; -yy98: -#line 206 "scanner.re" +yy109: yych = *++YYCURSOR; + if(yych == '/') goto yy117; + goto yy110; +yy110: +#line 223 "scanner.re" { goto comment; } -#line 621 "scanner.c" -yy99: yych = *++YYCURSOR; - if(yych == '*') goto yy103; - goto yy98; -yy100: yych = *++YYCURSOR; - goto yy101; -yy101: -#line 202 "scanner.re" +#line 673 "scanner.c" +yy111: yych = *++YYCURSOR; + if(yych == '*') goto yy115; + goto yy110; +yy112: yych = *++YYCURSOR; + goto yy113; +yy113: +#line 219 "scanner.re" { if(cursor == s->eof) RETURN(0); s->tok = s->pos = cursor; s->cline++; goto comment; } -#line 633 "scanner.c" -yy102: yych = *++YYCURSOR; - goto yy98; -yy103: yych = *++YYCURSOR; - goto yy104; -yy104: -#line 200 "scanner.re" +#line 685 "scanner.c" +yy114: yych = *++YYCURSOR; + goto yy110; +yy115: yych = *++YYCURSOR; + goto yy116; +yy116: +#line 217 "scanner.re" { ++depth; goto comment; } -#line 642 "scanner.c" -yy105: yych = *++YYCURSOR; - goto yy106; -yy106: -#line 196 "scanner.re" +#line 694 "scanner.c" +yy117: yych = *++YYCURSOR; + goto yy118; +yy118: +#line 213 "scanner.re" { if(--depth == 0) goto scan; else goto comment; } -#line 651 "scanner.c" +#line 703 "scanner.c" } -#line 207 "scanner.re" +#line 224 "scanner.re" } diff --git a/tools/re2c/scanner.re b/tools/re2c/scanner.re index 676d856a..d6c69bfa 100644 --- a/tools/re2c/scanner.re +++ b/tools/re2c/scanner.re @@ -4,6 +4,7 @@ #include "tools/re2c/parse.h" #include "tools/re2c/globals.h" #include "re2c-parser.h" +#include "globals.h" #ifndef MAX #define MAX(a,b) (((a)>(b))?(a):(b)) @@ -81,6 +82,7 @@ int Scanner_echo(Scanner *s, FILE *out) { unsigned char *cursor = s->cur; + int ignore_eoc = 0; /* Catch EOF */ if (s->eof && cursor == s->eof) @@ -92,6 +94,21 @@ echo: "/*!re2c" { fwrite(s->tok, 1, &cursor[-7] - s->tok, out); s->tok = cursor; RETURN(1); } + "/*!max:re2c" { + fprintf(out, "#define YYMAXFILL %u\n", maxFill); + s->tok = s->pos = cursor; + ignore_eoc = 1; + goto echo; + } + "*" "/" { + if (ignore_eoc) { + ignore_eoc = 0; + } else { + fwrite(s->tok, 1, cursor - s->tok, out); + } + s->tok = s->pos = cursor; + goto echo; + } "\n" { fwrite(s->tok, 1, cursor - s->tok, out); s->tok = s->pos = cursor; s->cline++; oline++; goto echo; }