From: helly Date: Sun, 29 Apr 2007 22:23:29 +0000 (+0000) Subject: - Make -bc work X-Git-Tag: 0.13.6~170 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4982108909c8609c7cf1ecd99ed18df340a3966a;p=re2c - Make -bc work --- diff --git a/re2c/bootstrap/scanner.cc b/re2c/bootstrap/scanner.cc index d93b4e87..cdafd0d9 100644 --- a/re2c/bootstrap/scanner.cc +++ b/re2c/bootstrap/scanner.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.0.dev on Sat Apr 28 15:49:28 2007 */ +/* Generated by re2c 0.13.0.dev on Sun Apr 29 23:44:31 2007 */ #line 1 "scanner.re" /* $Id$ */ #include diff --git a/re2c/code.cc b/re2c/code.cc index d01c2b30..08a5428a 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -1600,7 +1600,7 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std:: o << "\n"; } } - if (bFlag) + if (bFlag && !cFlag) { BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256); } @@ -1611,11 +1611,19 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std:: genCondGoto(o, ind, *specMap); } - if (cFlag && (bFlag || !condName.empty())) + if (cFlag) { - // TODO: Drop marker - o << "/* *********************************** */\n"; - o << condPrefix << condName << ":\n"; + if (!condName.empty()) + { + // TODO: Drop marker + o << "/* *********************************** */\n"; + o << condPrefix << condName << ":\n"; + } + if (bFlag && BitMap::first) + { + o << indent(ind++) << "{\n"; + BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256); + } } // TODO: Shouldn't labels 0 and 1 be variable? @@ -1633,6 +1641,10 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std:: s->go.genGoto(o, ind, s, s->next, readCh); } + if (cFlag && bFlag && BitMap::first) + { + o << indent(--ind) << "}\n"; + } // Generate epilog if (!cFlag || isLastCond) { diff --git a/re2c/test/condition_07.cbi.c b/re2c/test/condition_07.cbi.c new file mode 100755 index 00000000..90b404f2 --- /dev/null +++ b/re2c/test/condition_07.cbi.c @@ -0,0 +1,255 @@ +/* Generated by re2c */ +#include +#include +#include + +#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; +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + + +enum YYCONDTYPE { + EStateR1, + EStateR2, +}; + + +void scan(Scanner *s) +{ + int state = EStateR1; + + fill(s, 0); + + for(;;) + { + s->tok = s->cur; + + { + unsigned char yych; + if (state < 1) { + goto yyc_R1; + } else { + goto yyc_R2; + } +/* *********************************** */ +yyc_R1: + { + static const unsigned char yybm[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 0, 0, 0, 0, 0, 0, + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 0, 0, 0, 0, 0, + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + }; + + if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; }; + yych = *s->cur; + if(yych <= '@') { + if(yych <= '/') goto yy4; + if(yych >= ':') goto yy4; + } else { + if(yych <= 'Z') goto yy2; + if(yych <= '`') goto yy4; + if(yych >= '{') goto yy4; + } +yy2: + ++s->cur; + yych = *s->cur; + goto yy7; +yy3: + { + continue; + } +yy4: + ++s->cur; + { + continue; + } +yy6: + ++s->cur; + if(s->lim == s->cur) { if(fill(s, 1) >= 0) break; }; + yych = *s->cur; +yy7: + if(yybm[0+yych] & 128) { + goto yy6; + } + goto yy3; + } +/* *********************************** */ +yyc_R2: + { + static const unsigned char yybm[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 0, 0, 0, 0, 0, 0, + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 0, 0, 0, 0, 0, + 0, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + }; + if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; }; + yych = *s->cur; + if(yych <= '@') { + if(yych <= '/') goto yy12; + if(yych >= ':') goto yy12; + } else { + if(yych <= 'Z') goto yy10; + if(yych <= '`') goto yy12; + if(yych >= '{') goto yy12; + } +yy10: + ++s->cur; + yych = *s->cur; + goto yy15; +yy11: + { + continue; + } +yy12: + ++s->cur; + { + continue; + } +yy14: + ++s->cur; + if(s->lim == s->cur) { if(fill(s, 1) >= 0) break; }; + yych = *s->cur; +yy15: + if(yybm[0+yych] & 128) { + goto yy14; + } + goto yy11; + } + } + + } +} + +int main(int argc, char **argv) +{ + Scanner in; + char c; + + if (argc != 2) + { + fprintf(stderr, "%s \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_07.cbi.re b/re2c/test/condition_07.cbi.re new file mode 100755 index 00000000..35f62508 --- /dev/null +++ b/re2c/test/condition_07.cbi.re @@ -0,0 +1,133 @@ +#include +#include +#include + +#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; +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + +/*!types:re2c */ + +void scan(Scanner *s) +{ + int state = EStateR1; + + 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->tok; +re2c:define:YYFILL:len = #; +re2c:define:YYFILL = "{ if(fill(s, #) >= 0) break; }"; +re2c:define:YYCONDITION = state; +re2c:yyfill:parameter = 0; +re2c:indent:top = 2; +re2c:condenumprefix = EState; + +NUM = [0-9]; +ALNUM = NUM|[a-zA-Z]; +ANY = [^]; + + ALNUM+ + { + continue; + } + ANY + { + continue; + } + + ALNUM+ + { + continue; + } + ANY + { + continue; + } +*/ + } +} + +int main(int argc, char **argv) +{ + Scanner in; + char c; + + if (argc != 2) + { + fprintf(stderr, "%s \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; +}