From c080aaba3f73c85fed1321a8405091fba2fe66f4 Mon Sep 17 00:00:00 2001 From: helly Date: Tue, 22 Jan 2008 16:11:49 +0000 Subject: [PATCH] - Add/fix tests --- re2c/test/condition_14.cbif.c | 376 ++++++++++++++++++++++++++++++ re2c/test/condition_14.cbif.re | 198 ++++++++++++++++ re2c/test/condition_14.cgif.c | 8 +- re2c/test/condition_14.cgif.re | 2 +- re2c/test/condition_14.cif.c | 403 +++++++++++++++++++++++++++++++++ re2c/test/condition_14.cif.re | 198 ++++++++++++++++ re2c/test/condition_14.csif.c | 366 ++++++++++++++++++++++++++++++ re2c/test/condition_14.csif.re | 198 ++++++++++++++++ 8 files changed, 1744 insertions(+), 5 deletions(-) create mode 100644 re2c/test/condition_14.cbif.c create mode 100755 re2c/test/condition_14.cbif.re create mode 100644 re2c/test/condition_14.cif.c create mode 100755 re2c/test/condition_14.cif.re create mode 100644 re2c/test/condition_14.csif.c create mode 100755 re2c/test/condition_14.csif.re diff --git a/re2c/test/condition_14.cbif.c b/re2c/test/condition_14.cbif.c new file mode 100644 index 00000000..21a89c4a --- /dev/null +++ b/re2c/test/condition_14.cbif.c @@ -0,0 +1,376 @@ +/* Generated by re2c */ +#include +#include +#include + +#define BSIZE 8192 + + +enum ScanContition { + EStateNormal, + EStateComment, + EStateSkiptoeol, + EStateString, +}; + + +typedef struct Scanner +{ + FILE *fp; + unsigned char *cur, *tok, *lim, *eof; + unsigned char buffer[BSIZE]; + unsigned char yych; + enum ScanContition cond; + int state; +} Scanner; + +size_t fill(Scanner *s, size_t len) +{ + size_t got = ~0, cnt; + + if (!s->eof && s->lim - s->tok < len) + { + if (s->tok > s->buffer) + { + cnt = s->tok - s->buffer; + memcpy(s->buffer, s->tok, s->lim - s->tok); + s->tok -= cnt; + s->cur -= cnt; + s->lim -= cnt; + cnt = &s->buffer[BSIZE] - s->lim; + } + else + { + cnt = BSIZE; + } + if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) + { + s->eof = &s->lim[got]; + } + s->lim += got; + } + if (s->eof && s->cur + len > s->eof) + { + return ~0; /* not enough input data */ + } + return got; +} + +size_t init(Scanner *s) +{ + s->cur = s->tok = s->lim = s->buffer; + s->eof = 0; + s->cond = EStateNormal; + s->state = -1; + + return fill(s, 0); +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + +void scan(Scanner *s) +{ + s->tok = s->cur; + + if (s->state < 1) { + if (s->state < 0) { + goto yy0; + } else { + goto yyFillLabel0; + } + } else { + if (s->state < 2) { + goto yyFillLabel1; + } else { + if (s->state < 3) { + goto yyFillLabel2; + } else { + goto yyFillLabel3; + } + } + } + for(;;) + { + s->tok = s->cur; + + +yy0: + if (s->cond < 2) { + if (s->cond < 1) { + goto yyc_Normal; + } else { + goto yyc_Comment; + } + } else { + if (s->cond < 3) { + goto yyc_Skiptoeol; + } else { + goto yyc_String; + } + } +/* *********************************** */ +yyc_Comment: + + s->state = 0; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; +yyFillLabel0: + s->yych = *s->cur; + if (s->yych != '*') goto yy4; + ++s->cur; + if ((s->yych = *s->cur) == '/') goto yy5; +yy3: + continue; +yy4: + s->yych = *++s->cur; + goto yy3; +yy5: + ++s->cur; + s->cond = EStateNormal; + continue; +/* *********************************** */ +yyc_Normal: + s->state = 1; + if ((s->lim - s->cur) < 4) if (fill(s, 4) == ~0) break; +yyFillLabel1: + s->yych = *s->cur; + if (s->yych <= '\'') { + if (s->yych == '"') goto yy13; + if (s->yych <= '&') goto yy15; + goto yy12; + } else { + if (s->yych <= '/') { + if (s->yych <= '.') goto yy15; + goto yy11; + } else { + if (s->yych != '?') goto yy15; + } + } + s->yych = *(s->tok = ++s->cur); + if (s->yych == '?') goto yy26; +yy10: + fputc(s->cur[-1], stdout); + continue; +yy11: + s->yych = *++s->cur; + if (s->yych == '*') goto yy24; + if (s->yych == '/') goto yy22; + goto yy10; +yy12: + s->yych = *(s->tok = ++s->cur); + if (s->yych == '"') goto yy16; + if (s->yych == '\\') goto yy18; + goto yy10; +yy13: + ++s->cur; + s->cond = EStateString; + fputc(s->cur[-1], stdout); + continue; +yy15: + s->yych = *++s->cur; + goto yy10; +yy16: + s->yych = *++s->cur; + if (s->yych == '\'') goto yy20; +yy17: + s->cur = s->tok; + goto yy10; +yy18: + s->yych = *++s->cur; + if (s->yych != '"') goto yy17; + s->yych = *++s->cur; + if (s->yych != '\'') goto yy17; +yy20: + ++s->cur; + fputl("'\"'", 3, stdout); + continue; +yy22: + ++s->cur; + s->cond = EStateSkiptoeol; + continue; +yy24: + ++s->cur; + s->cond = EStateComment; + continue; +yy26: + s->yych = *++s->cur; + switch(s->yych) { + case '!': goto yy41; + case '\'': goto yy39; + case '(': goto yy27; + case ')': goto yy29; + case '-': goto yy43; + case '/': goto yy37; + case '<': goto yy31; + case '=': goto yy35; + case '>': goto yy33; + default: goto yy17; + } +yy27: + ++s->cur; + fputc('[', stdout); + continue; +yy29: + ++s->cur; + fputc(']', stdout); + continue; +yy31: + ++s->cur; + fputc('{', stdout); + continue; +yy33: + ++s->cur; + fputc('}', stdout); + continue; +yy35: + ++s->cur; + fputc('#', stdout); + continue; +yy37: + ++s->cur; + fputc('\\', stdout); + continue; +yy39: + ++s->cur; + fputc('^', stdout); + continue; +yy41: + ++s->cur; + fputc('|', stdout); + continue; +yy43: + ++s->cur; + fputc('~', stdout); + continue; +/* *********************************** */ +yyc_Skiptoeol: + s->state = 2; + if ((s->lim - s->cur) < 5) if (fill(s, 5) == ~0) break; +yyFillLabel2: + s->yych = *s->cur; + if (s->yych <= 0x0D) { + if (s->yych == 0x0A) goto yy51; + if (s->yych <= 0x0C) goto yy53; + goto yy50; + } else { + if (s->yych <= '?') { + if (s->yych <= '>') goto yy53; + } else { + if (s->yych == '\\') goto yy49; + goto yy53; + } + } + s->yych = *(s->tok = ++s->cur); + if (s->yych == '?') goto yy60; +yy48: + continue; +yy49: + s->yych = *(s->tok = ++s->cur); + if (s->yych == 0x0A) goto yy58; + if (s->yych == 0x0D) goto yy56; + goto yy48; +yy50: + s->yych = *++s->cur; + if (s->yych == 0x0A) goto yy54; + goto yy48; +yy51: + ++s->cur; + s->cond = EStateNormal; + fputc('\n', stdout); + continue; +yy53: + s->yych = *++s->cur; + goto yy48; +yy54: + ++s->cur; + s->cond = EStateNormal; + fputc('\r', stdout); + fputc('\n', stdout); + continue; +yy56: + s->yych = *++s->cur; + if (s->yych == 0x0A) goto yy58; +yy57: + s->cur = s->tok; + goto yy48; +yy58: + ++s->cur; + continue; +yy60: + s->yych = *++s->cur; + if (s->yych != '/') goto yy57; + s->yych = *++s->cur; + if (s->yych == 0x0A) goto yy63; + if (s->yych != 0x0D) goto yy57; + s->yych = *++s->cur; + if (s->yych != 0x0A) goto yy57; +yy63: + ++s->cur; + continue; +/* *********************************** */ +yyc_String: + s->state = 3; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; +yyFillLabel3: + s->yych = *s->cur; + if (s->yych == '"') goto yy69; + if (s->yych != '\\') goto yy71; + ++s->cur; + if ((s->yych = *s->cur) != 0x0A) goto yy72; +yy68: + fputc(s->cur[-1], stdout); + continue; +yy69: + ++s->cur; + s->cond = EStateNormal; + fputc(s->cur[-1], stdout); + continue; +yy71: + s->yych = *++s->cur; + goto yy68; +yy72: + ++s->cur; + fputl((const char*)s->cur-2, 2, stdout); + continue; + + } +} + +int main(int argc, char **argv) +{ + Scanner in; + + 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; + } + + if (init(&in) > 0) + { + scan(&in); + } + + if (in.fp != stdin) + { + fclose(in.fp); + } + return 0; +} diff --git a/re2c/test/condition_14.cbif.re b/re2c/test/condition_14.cbif.re new file mode 100755 index 00000000..fbb87ebc --- /dev/null +++ b/re2c/test/condition_14.cbif.re @@ -0,0 +1,198 @@ +#include +#include +#include + +#define BSIZE 8192 + +/*!types:re2c */ + +typedef struct Scanner +{ + FILE *fp; + unsigned char *cur, *tok, *lim, *eof; + unsigned char buffer[BSIZE]; + unsigned char yych; + enum ScanContition cond; + int state; +} Scanner; + +size_t fill(Scanner *s, size_t len) +{ + size_t got = ~0, cnt; + + if (!s->eof && s->lim - s->tok < len) + { + if (s->tok > s->buffer) + { + cnt = s->tok - s->buffer; + memcpy(s->buffer, s->tok, s->lim - s->tok); + s->tok -= cnt; + s->cur -= cnt; + s->lim -= cnt; + cnt = &s->buffer[BSIZE] - s->lim; + } + else + { + cnt = BSIZE; + } + if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) + { + s->eof = &s->lim[got]; + } + s->lim += got; + } + if (s->eof && s->cur + len > s->eof) + { + return ~0; /* not enough input data */ + } + return got; +} + +size_t init(Scanner *s) +{ + s->cur = s->tok = s->lim = s->buffer; + s->eof = 0; + s->cond = EStateNormal; + s->state = -1; + + return fill(s, 0); +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + +void scan(Scanner *s) +{ + s->tok = s->cur; +/*!re2c +re2c:define:YYGETSTATE = "s->state"; +re2c:define:YYGETSTATE:naked = 1; +re2c:define:YYCONDTYPE = ScanContition; +re2c:indent:top = 1; +re2c:cond:goto = "continue;"; +*/ +/*!getstate:re2c */ + 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:naked = 1; +re2c:define:YYFILL = "if (fill(s, #) == ~0) break;"; +re2c:define:YYSETSTATE@state = #; +re2c:define:YYSETSTATE = "s->state = #;"; +re2c:define:YYSETCONDITION = "s->cond = #;"; +re2c:define:YYSETCONDITION@cond = #; +re2c:define:YYGETCONDITION = s->cond; +re2c:define:YYGETCONDITION:naked = 1; +re2c:variable:yych = s->yych; +re2c:yych:emit = 0; +re2c:indent:top = 2; +re2c:condenumprefix = EState; + + "??(" := + fputc('[', stdout); + continue; + "??)" := + fputc(']', stdout); + continue; + "??<" := + fputc('{', stdout); + continue; + "??>" := + fputc('}', stdout); + continue; + "??=" := + fputc('#', stdout); + continue; + "??/" := + fputc('\\', stdout); + continue; + "??'" := + fputc('^', stdout); + continue; + "??!" := + fputc('|', stdout); + continue; + "??-" := + fputc('~', stdout); + continue; + "/*" :=> Comment + "//" :=> Skiptoeol + "'\\\"'"|"'\"'" := + fputl("'\"'", 3, stdout); + continue; + '"' => String := + fputc(s->cur[-1], stdout); + continue; + [^] := + fputc(s->cur[-1], stdout); + continue; + "*" "/" :=> Normal + [^] :=> Comment + "??/" "\r"? "\n" :=> Skiptoeol + "\\" "\r"? "\n" :=> Skiptoeol + "\r" "\n" => Normal := + fputc('\r', stdout); + fputc('\n', stdout); + continue; + "\n" => Normal := + fputc('\n', stdout); + continue; + [^] :=> Skiptoeol + '\\' . := + fputl((const char*)s->cur-2, 2, stdout); + continue; + '"' => Normal := + fputc(s->cur[-1], stdout); + continue; + [^] := + fputc(s->cur[-1], stdout); + continue; +*/ + } +} + +int main(int argc, char **argv) +{ + Scanner in; + + 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; + } + + if (init(&in) > 0) + { + scan(&in); + } + + if (in.fp != stdin) + { + fclose(in.fp); + } + return 0; +} diff --git a/re2c/test/condition_14.cgif.c b/re2c/test/condition_14.cgif.c index aa07c1f5..48b75ac9 100755 --- a/re2c/test/condition_14.cgif.c +++ b/re2c/test/condition_14.cgif.c @@ -107,7 +107,7 @@ yy0: yyc_Comment: s->state = 0; - if ((s->lim - s->cur) < 2) if(fill(s, 2) == ~0) break; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; yyFillLabel0: s->yych = *s->cur; if (s->yych != '*') goto yy4; @@ -125,7 +125,7 @@ yy5: /* *********************************** */ yyc_Normal: s->state = 1; - if ((s->lim - s->cur) < 4) if(fill(s, 4) == ~0) break; + if ((s->lim - s->cur) < 4) if (fill(s, 4) == ~0) break; yyFillLabel1: s->yych = *s->cur; { @@ -290,7 +290,7 @@ yy43: /* *********************************** */ yyc_Skiptoeol: s->state = 2; - if ((s->lim - s->cur) < 5) if(fill(s, 5) == ~0) break; + if ((s->lim - s->cur) < 5) if (fill(s, 5) == ~0) break; yyFillLabel2: s->yych = *s->cur; { @@ -381,7 +381,7 @@ yy63: /* *********************************** */ yyc_String: s->state = 3; - if ((s->lim - s->cur) < 2) if(fill(s, 2) == ~0) break; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; yyFillLabel3: s->yych = *s->cur; if (s->yych == '"') goto yy69; diff --git a/re2c/test/condition_14.cgif.re b/re2c/test/condition_14.cgif.re index 5e9d168a..6e31cf01 100755 --- a/re2c/test/condition_14.cgif.re +++ b/re2c/test/condition_14.cgif.re @@ -88,7 +88,7 @@ re2c:define:YYLIMIT = s->lim; re2c:define:YYMARKER = s->tok; re2c:define:YYFILL@len = #; re2c:define:YYFILL:naked = 1; -re2c:define:YYFILL = "if(fill(s, #) == ~0) break;"; +re2c:define:YYFILL = "if (fill(s, #) == ~0) break;"; re2c:define:YYSETSTATE@state = #; re2c:define:YYSETSTATE = "s->state = #;"; re2c:define:YYSETCONDITION = "s->cond = #;"; diff --git a/re2c/test/condition_14.cif.c b/re2c/test/condition_14.cif.c new file mode 100644 index 00000000..933bf86a --- /dev/null +++ b/re2c/test/condition_14.cif.c @@ -0,0 +1,403 @@ +/* Generated by re2c */ +#include +#include +#include + +#define BSIZE 8192 + + +enum ScanContition { + EStateNormal, + EStateComment, + EStateSkiptoeol, + EStateString, +}; + + +typedef struct Scanner +{ + FILE *fp; + unsigned char *cur, *tok, *lim, *eof; + unsigned char buffer[BSIZE]; + unsigned char yych; + enum ScanContition cond; + int state; +} Scanner; + +size_t fill(Scanner *s, size_t len) +{ + size_t got = ~0, cnt; + + if (!s->eof && s->lim - s->tok < len) + { + if (s->tok > s->buffer) + { + cnt = s->tok - s->buffer; + memcpy(s->buffer, s->tok, s->lim - s->tok); + s->tok -= cnt; + s->cur -= cnt; + s->lim -= cnt; + cnt = &s->buffer[BSIZE] - s->lim; + } + else + { + cnt = BSIZE; + } + if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) + { + s->eof = &s->lim[got]; + } + s->lim += got; + } + if (s->eof && s->cur + len > s->eof) + { + return ~0; /* not enough input data */ + } + return got; +} + +size_t init(Scanner *s) +{ + s->cur = s->tok = s->lim = s->buffer; + s->eof = 0; + s->cond = EStateNormal; + s->state = -1; + + return fill(s, 0); +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + +void scan(Scanner *s) +{ + s->tok = s->cur; + + switch(s->state) { + default: goto yy0; + case 0: goto yyFillLabel0; + case 1: goto yyFillLabel1; + case 2: goto yyFillLabel2; + case 3: goto yyFillLabel3; + } + for(;;) + { + s->tok = s->cur; + + +yy0: + switch(s->cond) { + case EStateComment: goto yyc_Comment; + case EStateNormal: goto yyc_Normal; + case EStateSkiptoeol: goto yyc_Skiptoeol; + case EStateString: goto yyc_String; + } +/* *********************************** */ +yyc_Comment: + + s->state = 0; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; +yyFillLabel0: + s->yych = *s->cur; + switch(s->yych) { + case '*': goto yy2; + default: goto yy4; + } +yy2: + ++s->cur; + switch((s->yych = *s->cur)) { + case '/': goto yy5; + default: goto yy3; + } +yy3: + continue; +yy4: + s->yych = *++s->cur; + goto yy3; +yy5: + ++s->cur; + s->cond = EStateNormal; + continue; +/* *********************************** */ +yyc_Normal: + s->state = 1; + if ((s->lim - s->cur) < 4) if (fill(s, 4) == ~0) break; +yyFillLabel1: + s->yych = *s->cur; + switch(s->yych) { + case '"': goto yy13; + case '\'': goto yy12; + case '/': goto yy11; + case '?': goto yy9; + default: goto yy15; + } +yy9: + s->yych = *(s->tok = ++s->cur); + switch(s->yych) { + case '?': goto yy26; + default: goto yy10; + } +yy10: + fputc(s->cur[-1], stdout); + continue; +yy11: + s->yych = *++s->cur; + switch(s->yych) { + case '*': goto yy24; + case '/': goto yy22; + default: goto yy10; + } +yy12: + s->yych = *(s->tok = ++s->cur); + switch(s->yych) { + case '"': goto yy16; + case '\\': goto yy18; + default: goto yy10; + } +yy13: + ++s->cur; + s->cond = EStateString; + fputc(s->cur[-1], stdout); + continue; +yy15: + s->yych = *++s->cur; + goto yy10; +yy16: + s->yych = *++s->cur; + switch(s->yych) { + case '\'': goto yy20; + default: goto yy17; + } +yy17: + s->cur = s->tok; + goto yy10; +yy18: + s->yych = *++s->cur; + switch(s->yych) { + case '"': goto yy19; + default: goto yy17; + } +yy19: + s->yych = *++s->cur; + switch(s->yych) { + case '\'': goto yy20; + default: goto yy17; + } +yy20: + ++s->cur; + fputl("'\"'", 3, stdout); + continue; +yy22: + ++s->cur; + s->cond = EStateSkiptoeol; + continue; +yy24: + ++s->cur; + s->cond = EStateComment; + continue; +yy26: + s->yych = *++s->cur; + switch(s->yych) { + case '!': goto yy41; + case '\'': goto yy39; + case '(': goto yy27; + case ')': goto yy29; + case '-': goto yy43; + case '/': goto yy37; + case '<': goto yy31; + case '=': goto yy35; + case '>': goto yy33; + default: goto yy17; + } +yy27: + ++s->cur; + fputc('[', stdout); + continue; +yy29: + ++s->cur; + fputc(']', stdout); + continue; +yy31: + ++s->cur; + fputc('{', stdout); + continue; +yy33: + ++s->cur; + fputc('}', stdout); + continue; +yy35: + ++s->cur; + fputc('#', stdout); + continue; +yy37: + ++s->cur; + fputc('\\', stdout); + continue; +yy39: + ++s->cur; + fputc('^', stdout); + continue; +yy41: + ++s->cur; + fputc('|', stdout); + continue; +yy43: + ++s->cur; + fputc('~', stdout); + continue; +/* *********************************** */ +yyc_Skiptoeol: + s->state = 2; + if ((s->lim - s->cur) < 5) if (fill(s, 5) == ~0) break; +yyFillLabel2: + s->yych = *s->cur; + switch(s->yych) { + case 0x0A: goto yy51; + case 0x0D: goto yy50; + case '?': goto yy47; + case '\\': goto yy49; + default: goto yy53; + } +yy47: + s->yych = *(s->tok = ++s->cur); + switch(s->yych) { + case '?': goto yy60; + default: goto yy48; + } +yy48: + continue; +yy49: + s->yych = *(s->tok = ++s->cur); + switch(s->yych) { + case 0x0A: goto yy58; + case 0x0D: goto yy56; + default: goto yy48; + } +yy50: + s->yych = *++s->cur; + switch(s->yych) { + case 0x0A: goto yy54; + default: goto yy48; + } +yy51: + ++s->cur; + s->cond = EStateNormal; + fputc('\n', stdout); + continue; +yy53: + s->yych = *++s->cur; + goto yy48; +yy54: + ++s->cur; + s->cond = EStateNormal; + fputc('\r', stdout); + fputc('\n', stdout); + continue; +yy56: + s->yych = *++s->cur; + switch(s->yych) { + case 0x0A: goto yy58; + default: goto yy57; + } +yy57: + s->cur = s->tok; + goto yy48; +yy58: + ++s->cur; + continue; +yy60: + s->yych = *++s->cur; + switch(s->yych) { + case '/': goto yy61; + default: goto yy57; + } +yy61: + s->yych = *++s->cur; + switch(s->yych) { + case 0x0A: goto yy63; + case 0x0D: goto yy62; + default: goto yy57; + } +yy62: + s->yych = *++s->cur; + switch(s->yych) { + case 0x0A: goto yy63; + default: goto yy57; + } +yy63: + ++s->cur; + continue; +/* *********************************** */ +yyc_String: + s->state = 3; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; +yyFillLabel3: + s->yych = *s->cur; + switch(s->yych) { + case '"': goto yy69; + case '\\': goto yy67; + default: goto yy71; + } +yy67: + ++s->cur; + switch((s->yych = *s->cur)) { + case 0x0A: goto yy68; + default: goto yy72; + } +yy68: + fputc(s->cur[-1], stdout); + continue; +yy69: + ++s->cur; + s->cond = EStateNormal; + fputc(s->cur[-1], stdout); + continue; +yy71: + s->yych = *++s->cur; + goto yy68; +yy72: + ++s->cur; + fputl((const char*)s->cur-2, 2, stdout); + continue; + + } +} + +int main(int argc, char **argv) +{ + Scanner in; + + 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; + } + + if (init(&in) > 0) + { + scan(&in); + } + + if (in.fp != stdin) + { + fclose(in.fp); + } + return 0; +} diff --git a/re2c/test/condition_14.cif.re b/re2c/test/condition_14.cif.re new file mode 100755 index 00000000..fbb87ebc --- /dev/null +++ b/re2c/test/condition_14.cif.re @@ -0,0 +1,198 @@ +#include +#include +#include + +#define BSIZE 8192 + +/*!types:re2c */ + +typedef struct Scanner +{ + FILE *fp; + unsigned char *cur, *tok, *lim, *eof; + unsigned char buffer[BSIZE]; + unsigned char yych; + enum ScanContition cond; + int state; +} Scanner; + +size_t fill(Scanner *s, size_t len) +{ + size_t got = ~0, cnt; + + if (!s->eof && s->lim - s->tok < len) + { + if (s->tok > s->buffer) + { + cnt = s->tok - s->buffer; + memcpy(s->buffer, s->tok, s->lim - s->tok); + s->tok -= cnt; + s->cur -= cnt; + s->lim -= cnt; + cnt = &s->buffer[BSIZE] - s->lim; + } + else + { + cnt = BSIZE; + } + if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) + { + s->eof = &s->lim[got]; + } + s->lim += got; + } + if (s->eof && s->cur + len > s->eof) + { + return ~0; /* not enough input data */ + } + return got; +} + +size_t init(Scanner *s) +{ + s->cur = s->tok = s->lim = s->buffer; + s->eof = 0; + s->cond = EStateNormal; + s->state = -1; + + return fill(s, 0); +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + +void scan(Scanner *s) +{ + s->tok = s->cur; +/*!re2c +re2c:define:YYGETSTATE = "s->state"; +re2c:define:YYGETSTATE:naked = 1; +re2c:define:YYCONDTYPE = ScanContition; +re2c:indent:top = 1; +re2c:cond:goto = "continue;"; +*/ +/*!getstate:re2c */ + 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:naked = 1; +re2c:define:YYFILL = "if (fill(s, #) == ~0) break;"; +re2c:define:YYSETSTATE@state = #; +re2c:define:YYSETSTATE = "s->state = #;"; +re2c:define:YYSETCONDITION = "s->cond = #;"; +re2c:define:YYSETCONDITION@cond = #; +re2c:define:YYGETCONDITION = s->cond; +re2c:define:YYGETCONDITION:naked = 1; +re2c:variable:yych = s->yych; +re2c:yych:emit = 0; +re2c:indent:top = 2; +re2c:condenumprefix = EState; + + "??(" := + fputc('[', stdout); + continue; + "??)" := + fputc(']', stdout); + continue; + "??<" := + fputc('{', stdout); + continue; + "??>" := + fputc('}', stdout); + continue; + "??=" := + fputc('#', stdout); + continue; + "??/" := + fputc('\\', stdout); + continue; + "??'" := + fputc('^', stdout); + continue; + "??!" := + fputc('|', stdout); + continue; + "??-" := + fputc('~', stdout); + continue; + "/*" :=> Comment + "//" :=> Skiptoeol + "'\\\"'"|"'\"'" := + fputl("'\"'", 3, stdout); + continue; + '"' => String := + fputc(s->cur[-1], stdout); + continue; + [^] := + fputc(s->cur[-1], stdout); + continue; + "*" "/" :=> Normal + [^] :=> Comment + "??/" "\r"? "\n" :=> Skiptoeol + "\\" "\r"? "\n" :=> Skiptoeol + "\r" "\n" => Normal := + fputc('\r', stdout); + fputc('\n', stdout); + continue; + "\n" => Normal := + fputc('\n', stdout); + continue; + [^] :=> Skiptoeol + '\\' . := + fputl((const char*)s->cur-2, 2, stdout); + continue; + '"' => Normal := + fputc(s->cur[-1], stdout); + continue; + [^] := + fputc(s->cur[-1], stdout); + continue; +*/ + } +} + +int main(int argc, char **argv) +{ + Scanner in; + + 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; + } + + if (init(&in) > 0) + { + scan(&in); + } + + if (in.fp != stdin) + { + fclose(in.fp); + } + return 0; +} diff --git a/re2c/test/condition_14.csif.c b/re2c/test/condition_14.csif.c new file mode 100644 index 00000000..c44386f0 --- /dev/null +++ b/re2c/test/condition_14.csif.c @@ -0,0 +1,366 @@ +/* Generated by re2c */ +#include +#include +#include + +#define BSIZE 8192 + + +enum ScanContition { + EStateNormal, + EStateComment, + EStateSkiptoeol, + EStateString, +}; + + +typedef struct Scanner +{ + FILE *fp; + unsigned char *cur, *tok, *lim, *eof; + unsigned char buffer[BSIZE]; + unsigned char yych; + enum ScanContition cond; + int state; +} Scanner; + +size_t fill(Scanner *s, size_t len) +{ + size_t got = ~0, cnt; + + if (!s->eof && s->lim - s->tok < len) + { + if (s->tok > s->buffer) + { + cnt = s->tok - s->buffer; + memcpy(s->buffer, s->tok, s->lim - s->tok); + s->tok -= cnt; + s->cur -= cnt; + s->lim -= cnt; + cnt = &s->buffer[BSIZE] - s->lim; + } + else + { + cnt = BSIZE; + } + if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) + { + s->eof = &s->lim[got]; + } + s->lim += got; + } + if (s->eof && s->cur + len > s->eof) + { + return ~0; /* not enough input data */ + } + return got; +} + +size_t init(Scanner *s) +{ + s->cur = s->tok = s->lim = s->buffer; + s->eof = 0; + s->cond = EStateNormal; + s->state = -1; + + return fill(s, 0); +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + +void scan(Scanner *s) +{ + s->tok = s->cur; + + switch(s->state) { + default: goto yy0; + case 0: goto yyFillLabel0; + case 1: goto yyFillLabel1; + case 2: goto yyFillLabel2; + case 3: goto yyFillLabel3; + } + for(;;) + { + s->tok = s->cur; + + +yy0: + if (s->cond < 2) { + if (s->cond < 1) { + goto yyc_Normal; + } else { + goto yyc_Comment; + } + } else { + if (s->cond < 3) { + goto yyc_Skiptoeol; + } else { + goto yyc_String; + } + } +/* *********************************** */ +yyc_Comment: + + s->state = 0; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; +yyFillLabel0: + s->yych = *s->cur; + if (s->yych != '*') goto yy4; + ++s->cur; + if ((s->yych = *s->cur) == '/') goto yy5; +yy3: + continue; +yy4: + s->yych = *++s->cur; + goto yy3; +yy5: + ++s->cur; + s->cond = EStateNormal; + continue; +/* *********************************** */ +yyc_Normal: + s->state = 1; + if ((s->lim - s->cur) < 4) if (fill(s, 4) == ~0) break; +yyFillLabel1: + s->yych = *s->cur; + if (s->yych <= '\'') { + if (s->yych == '"') goto yy13; + if (s->yych <= '&') goto yy15; + goto yy12; + } else { + if (s->yych <= '/') { + if (s->yych <= '.') goto yy15; + goto yy11; + } else { + if (s->yych != '?') goto yy15; + } + } + s->yych = *(s->tok = ++s->cur); + if (s->yych == '?') goto yy26; +yy10: + fputc(s->cur[-1], stdout); + continue; +yy11: + s->yych = *++s->cur; + if (s->yych == '*') goto yy24; + if (s->yych == '/') goto yy22; + goto yy10; +yy12: + s->yych = *(s->tok = ++s->cur); + if (s->yych == '"') goto yy16; + if (s->yych == '\\') goto yy18; + goto yy10; +yy13: + ++s->cur; + s->cond = EStateString; + fputc(s->cur[-1], stdout); + continue; +yy15: + s->yych = *++s->cur; + goto yy10; +yy16: + s->yych = *++s->cur; + if (s->yych == '\'') goto yy20; +yy17: + s->cur = s->tok; + goto yy10; +yy18: + s->yych = *++s->cur; + if (s->yych != '"') goto yy17; + s->yych = *++s->cur; + if (s->yych != '\'') goto yy17; +yy20: + ++s->cur; + fputl("'\"'", 3, stdout); + continue; +yy22: + ++s->cur; + s->cond = EStateSkiptoeol; + continue; +yy24: + ++s->cur; + s->cond = EStateComment; + continue; +yy26: + s->yych = *++s->cur; + switch(s->yych) { + case '!': goto yy41; + case '\'': goto yy39; + case '(': goto yy27; + case ')': goto yy29; + case '-': goto yy43; + case '/': goto yy37; + case '<': goto yy31; + case '=': goto yy35; + case '>': goto yy33; + default: goto yy17; + } +yy27: + ++s->cur; + fputc('[', stdout); + continue; +yy29: + ++s->cur; + fputc(']', stdout); + continue; +yy31: + ++s->cur; + fputc('{', stdout); + continue; +yy33: + ++s->cur; + fputc('}', stdout); + continue; +yy35: + ++s->cur; + fputc('#', stdout); + continue; +yy37: + ++s->cur; + fputc('\\', stdout); + continue; +yy39: + ++s->cur; + fputc('^', stdout); + continue; +yy41: + ++s->cur; + fputc('|', stdout); + continue; +yy43: + ++s->cur; + fputc('~', stdout); + continue; +/* *********************************** */ +yyc_Skiptoeol: + s->state = 2; + if ((s->lim - s->cur) < 5) if (fill(s, 5) == ~0) break; +yyFillLabel2: + s->yych = *s->cur; + if (s->yych <= 0x0D) { + if (s->yych == 0x0A) goto yy51; + if (s->yych <= 0x0C) goto yy53; + goto yy50; + } else { + if (s->yych <= '?') { + if (s->yych <= '>') goto yy53; + } else { + if (s->yych == '\\') goto yy49; + goto yy53; + } + } + s->yych = *(s->tok = ++s->cur); + if (s->yych == '?') goto yy60; +yy48: + continue; +yy49: + s->yych = *(s->tok = ++s->cur); + if (s->yych == 0x0A) goto yy58; + if (s->yych == 0x0D) goto yy56; + goto yy48; +yy50: + s->yych = *++s->cur; + if (s->yych == 0x0A) goto yy54; + goto yy48; +yy51: + ++s->cur; + s->cond = EStateNormal; + fputc('\n', stdout); + continue; +yy53: + s->yych = *++s->cur; + goto yy48; +yy54: + ++s->cur; + s->cond = EStateNormal; + fputc('\r', stdout); + fputc('\n', stdout); + continue; +yy56: + s->yych = *++s->cur; + if (s->yych == 0x0A) goto yy58; +yy57: + s->cur = s->tok; + goto yy48; +yy58: + ++s->cur; + continue; +yy60: + s->yych = *++s->cur; + if (s->yych != '/') goto yy57; + s->yych = *++s->cur; + if (s->yych == 0x0A) goto yy63; + if (s->yych != 0x0D) goto yy57; + s->yych = *++s->cur; + if (s->yych != 0x0A) goto yy57; +yy63: + ++s->cur; + continue; +/* *********************************** */ +yyc_String: + s->state = 3; + if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break; +yyFillLabel3: + s->yych = *s->cur; + if (s->yych == '"') goto yy69; + if (s->yych != '\\') goto yy71; + ++s->cur; + if ((s->yych = *s->cur) != 0x0A) goto yy72; +yy68: + fputc(s->cur[-1], stdout); + continue; +yy69: + ++s->cur; + s->cond = EStateNormal; + fputc(s->cur[-1], stdout); + continue; +yy71: + s->yych = *++s->cur; + goto yy68; +yy72: + ++s->cur; + fputl((const char*)s->cur-2, 2, stdout); + continue; + + } +} + +int main(int argc, char **argv) +{ + Scanner in; + + 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; + } + + if (init(&in) > 0) + { + scan(&in); + } + + if (in.fp != stdin) + { + fclose(in.fp); + } + return 0; +} diff --git a/re2c/test/condition_14.csif.re b/re2c/test/condition_14.csif.re new file mode 100755 index 00000000..fbb87ebc --- /dev/null +++ b/re2c/test/condition_14.csif.re @@ -0,0 +1,198 @@ +#include +#include +#include + +#define BSIZE 8192 + +/*!types:re2c */ + +typedef struct Scanner +{ + FILE *fp; + unsigned char *cur, *tok, *lim, *eof; + unsigned char buffer[BSIZE]; + unsigned char yych; + enum ScanContition cond; + int state; +} Scanner; + +size_t fill(Scanner *s, size_t len) +{ + size_t got = ~0, cnt; + + if (!s->eof && s->lim - s->tok < len) + { + if (s->tok > s->buffer) + { + cnt = s->tok - s->buffer; + memcpy(s->buffer, s->tok, s->lim - s->tok); + s->tok -= cnt; + s->cur -= cnt; + s->lim -= cnt; + cnt = &s->buffer[BSIZE] - s->lim; + } + else + { + cnt = BSIZE; + } + if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt) + { + s->eof = &s->lim[got]; + } + s->lim += got; + } + if (s->eof && s->cur + len > s->eof) + { + return ~0; /* not enough input data */ + } + return got; +} + +size_t init(Scanner *s) +{ + s->cur = s->tok = s->lim = s->buffer; + s->eof = 0; + s->cond = EStateNormal; + s->state = -1; + + return fill(s, 0); +} + +void fputl(const char *s, size_t len, FILE *stream) +{ + while(len-- > 0) + { + fputc(*s++, stream); + } +} + +void scan(Scanner *s) +{ + s->tok = s->cur; +/*!re2c +re2c:define:YYGETSTATE = "s->state"; +re2c:define:YYGETSTATE:naked = 1; +re2c:define:YYCONDTYPE = ScanContition; +re2c:indent:top = 1; +re2c:cond:goto = "continue;"; +*/ +/*!getstate:re2c */ + 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:naked = 1; +re2c:define:YYFILL = "if (fill(s, #) == ~0) break;"; +re2c:define:YYSETSTATE@state = #; +re2c:define:YYSETSTATE = "s->state = #;"; +re2c:define:YYSETCONDITION = "s->cond = #;"; +re2c:define:YYSETCONDITION@cond = #; +re2c:define:YYGETCONDITION = s->cond; +re2c:define:YYGETCONDITION:naked = 1; +re2c:variable:yych = s->yych; +re2c:yych:emit = 0; +re2c:indent:top = 2; +re2c:condenumprefix = EState; + + "??(" := + fputc('[', stdout); + continue; + "??)" := + fputc(']', stdout); + continue; + "??<" := + fputc('{', stdout); + continue; + "??>" := + fputc('}', stdout); + continue; + "??=" := + fputc('#', stdout); + continue; + "??/" := + fputc('\\', stdout); + continue; + "??'" := + fputc('^', stdout); + continue; + "??!" := + fputc('|', stdout); + continue; + "??-" := + fputc('~', stdout); + continue; + "/*" :=> Comment + "//" :=> Skiptoeol + "'\\\"'"|"'\"'" := + fputl("'\"'", 3, stdout); + continue; + '"' => String := + fputc(s->cur[-1], stdout); + continue; + [^] := + fputc(s->cur[-1], stdout); + continue; + "*" "/" :=> Normal + [^] :=> Comment + "??/" "\r"? "\n" :=> Skiptoeol + "\\" "\r"? "\n" :=> Skiptoeol + "\r" "\n" => Normal := + fputc('\r', stdout); + fputc('\n', stdout); + continue; + "\n" => Normal := + fputc('\n', stdout); + continue; + [^] :=> Skiptoeol + '\\' . := + fputl((const char*)s->cur-2, 2, stdout); + continue; + '"' => Normal := + fputc(s->cur[-1], stdout); + continue; + [^] := + fputc(s->cur[-1], stdout); + continue; +*/ + } +} + +int main(int argc, char **argv) +{ + Scanner in; + + 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; + } + + if (init(&in) > 0) + { + scan(&in); + } + + if (in.fp != stdin) + { + fclose(in.fp); + } + return 0; +} -- 2.50.1