mirror of https://github.com/yasm/yasm.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
517 lines
10 KiB
517 lines
10 KiB
/* Generated by re2c 0.9.1-C on Sat Oct 5 02:09:57 2002 |
|
*/ |
|
#line 1 "scanner.re" |
|
#include <config.h> |
|
|
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include "tools/re2c/scanner.h" |
|
#include "tools/re2c/parse.h" |
|
#include "tools/re2c/globals.h" |
|
#include "re2c-parser.h" |
|
|
|
#define BSIZE 8192 |
|
|
|
#define YYCTYPE unsigned char |
|
#define YYCURSOR cursor |
|
#define YYLIMIT s->lim |
|
#define YYMARKER s->ptr |
|
#define YYFILL(n) {cursor = fill(s, cursor);} |
|
|
|
#define RETURN(i) {s->cur = cursor; return i;} |
|
|
|
static unsigned char *fill(Scanner*, unsigned char*); |
|
|
|
void |
|
Scanner_init(Scanner *s, FILE *i) |
|
{ |
|
s->in = i; |
|
s->bot = s->tok = s->ptr = s->cur = s->pos = s->lim = s->top = |
|
s->eof = NULL; |
|
s->tchar = s->tline = 0; |
|
s->cline = 1; |
|
} |
|
|
|
static unsigned char * |
|
fill(Scanner *s, unsigned char *cursor) |
|
{ |
|
if(!s->eof){ |
|
unsigned int cnt = s->tok - s->bot; |
|
if(cnt){ |
|
memcpy(s->bot, s->tok, s->lim - s->tok); |
|
s->tok = s->bot; |
|
s->ptr -= cnt; |
|
cursor -= cnt; |
|
s->pos -= cnt; |
|
s->lim -= cnt; |
|
} |
|
if((s->top - s->lim) < BSIZE){ |
|
unsigned char *buf = malloc(((s->lim - s->bot) + BSIZE)); |
|
memcpy(buf, s->tok, s->lim - s->tok); |
|
s->tok = buf; |
|
s->ptr = &buf[s->ptr - s->bot]; |
|
cursor = &buf[cursor - s->bot]; |
|
s->pos = &buf[s->pos - s->bot]; |
|
s->lim = &buf[s->lim - s->bot]; |
|
s->top = &s->lim[BSIZE]; |
|
if (s->bot) |
|
free(s->bot); |
|
s->bot = buf; |
|
} |
|
if((cnt = fread(s->lim, 1, BSIZE, s->in)) != BSIZE){ |
|
s->eof = &s->lim[cnt]; *s->eof++ = '\n'; |
|
} |
|
s->lim += cnt; |
|
} |
|
return cursor; |
|
} |
|
|
|
#line 75 "scanner.re" |
|
|
|
|
|
int |
|
Scanner_echo(Scanner *s, FILE *out) |
|
{ |
|
unsigned char *cursor = s->cur; |
|
s->tok = cursor; |
|
echo: |
|
|
|
#line 80 "scanner.c" |
|
{ |
|
YYCTYPE yych; |
|
unsigned int yyaccept; |
|
goto yy0; |
|
++YYCURSOR; |
|
yy0: |
|
if((YYLIMIT - YYCURSOR) < 7) YYFILL(7); |
|
yych = *YYCURSOR; |
|
if(yych == '\n') goto yy4; |
|
if(yych != '/') goto yy6; |
|
yyaccept = 0; |
|
yych = *(YYMARKER = ++YYCURSOR); |
|
if(yych == '*') goto yy7; |
|
yy3: |
|
#line 91 "scanner.re" |
|
{ goto echo; } |
|
#line 97 "scanner.c" |
|
yy4: yych = *++YYCURSOR; |
|
|
|
#line 87 "scanner.re" |
|
{ if(cursor == s->eof) RETURN(0); |
|
fwrite(s->tok, 1, cursor - s->tok, out); |
|
s->tok = s->pos = cursor; s->cline++; oline++; |
|
goto echo; } |
|
#line 105 "scanner.c" |
|
yy6: yych = *++YYCURSOR; |
|
goto yy3; |
|
yy7: yych = *++YYCURSOR; |
|
if(yych == '!') goto yy9; |
|
yy8: YYCURSOR = YYMARKER; |
|
switch(yyaccept){ |
|
case 0: goto yy3; |
|
} |
|
yy9: yych = *++YYCURSOR; |
|
if(yych != 'r') goto yy8; |
|
yych = *++YYCURSOR; |
|
if(yych != 'e') goto yy8; |
|
yych = *++YYCURSOR; |
|
if(yych != '2') goto yy8; |
|
yych = *++YYCURSOR; |
|
if(yych != 'c') goto yy8; |
|
yych = *++YYCURSOR; |
|
|
|
#line 84 "scanner.re" |
|
{ fwrite(s->tok, 1, &cursor[-7] - s->tok, out); |
|
s->tok = cursor; |
|
RETURN(1); } |
|
#line 128 "scanner.c" |
|
} |
|
#line 92 "scanner.re" |
|
|
|
} |
|
|
|
|
|
int |
|
Scanner_scan(Scanner *s) |
|
{ |
|
unsigned char *cursor = s->cur; |
|
unsigned int depth; |
|
|
|
scan: |
|
s->tchar = cursor - s->pos; |
|
s->tline = s->cline; |
|
s->tok = cursor; |
|
|
|
#line 146 "scanner.c" |
|
{ |
|
YYCTYPE yych; |
|
unsigned int yyaccept; |
|
goto yy15; |
|
++YYCURSOR; |
|
yy15: |
|
if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); |
|
yych = *YYCURSOR; |
|
if(yych <= ':'){ |
|
if(yych <= '"'){ |
|
if(yych <= '\n'){ |
|
if(yych <= '\b') goto yy35; |
|
if(yych <= '\t') goto yy31; |
|
goto yy33; |
|
} else { |
|
if(yych == ' ') goto yy31; |
|
if(yych <= '!') goto yy35; |
|
goto yy23; |
|
} |
|
} else { |
|
if(yych <= '*'){ |
|
if(yych <= '\'') goto yy35; |
|
if(yych <= ')') goto yy27; |
|
goto yy21; |
|
} else { |
|
if(yych <= '+') goto yy28; |
|
if(yych == '/') goto yy19; |
|
goto yy35; |
|
} |
|
} |
|
} else { |
|
if(yych <= 'Z'){ |
|
if(yych <= '='){ |
|
if(yych == '<') goto yy35; |
|
goto yy27; |
|
} else { |
|
if(yych == '?') goto yy28; |
|
if(yych <= '@') goto yy35; |
|
goto yy29; |
|
} |
|
} else { |
|
if(yych <= '`'){ |
|
if(yych <= '[') goto yy25; |
|
if(yych <= '\\') goto yy27; |
|
goto yy35; |
|
} else { |
|
if(yych <= 'z') goto yy29; |
|
if(yych <= '{') goto yy17; |
|
if(yych <= '|') goto yy27; |
|
goto yy35; |
|
} |
|
} |
|
} |
|
yy17: yych = *++YYCURSOR; |
|
|
|
#line 107 "scanner.re" |
|
{ depth = 1; |
|
goto code; |
|
} |
|
#line 206 "scanner.c" |
|
yy19: yych = *++YYCURSOR; |
|
if(yych == '*') goto yy54; |
|
yy20: |
|
#line 126 "scanner.re" |
|
{ RETURN(*s->tok); } |
|
#line 212 "scanner.c" |
|
yy21: yych = *++YYCURSOR; |
|
if(yych == '/') goto yy52; |
|
yy22: |
|
#line 128 "scanner.re" |
|
{ yylval.op = *s->tok; |
|
RETURN(CLOSE); } |
|
#line 219 "scanner.c" |
|
yy23: yyaccept = 0; |
|
yych = *(YYMARKER = ++YYCURSOR); |
|
if(yych != '\n') goto yy48; |
|
yy24: |
|
#line 119 "scanner.re" |
|
{ Scanner_fatal(s, "bad string"); } |
|
#line 226 "scanner.c" |
|
yy25: yyaccept = 1; |
|
yych = *(YYMARKER = ++YYCURSOR); |
|
if(yych != '\n') goto yy42; |
|
yy26: |
|
#line 124 "scanner.re" |
|
{ Scanner_fatal(s, "bad character constant"); } |
|
#line 233 "scanner.c" |
|
yy27: yych = *++YYCURSOR; |
|
goto yy20; |
|
yy28: yych = *++YYCURSOR; |
|
goto yy22; |
|
yy29: yych = *++YYCURSOR; |
|
goto yy40; |
|
yy30: |
|
#line 131 "scanner.re" |
|
{ SubStr substr; |
|
s->cur = cursor; |
|
substr = Scanner_token(s); |
|
yylval.symbol = Symbol_find(&substr); |
|
return ID; } |
|
#line 247 "scanner.c" |
|
yy31: yych = *++YYCURSOR; |
|
goto yy38; |
|
yy32: |
|
#line 137 "scanner.re" |
|
{ goto scan; } |
|
#line 253 "scanner.c" |
|
yy33: yych = *++YYCURSOR; |
|
|
|
#line 139 "scanner.re" |
|
{ if(cursor == s->eof) RETURN(0); |
|
s->pos = cursor; s->cline++; |
|
goto scan; |
|
} |
|
#line 261 "scanner.c" |
|
yy35: yych = *++YYCURSOR; |
|
|
|
#line 144 "scanner.re" |
|
{ fprintf(stderr, "unexpected character: '%c'\n", *s->tok); |
|
goto scan; |
|
} |
|
#line 268 "scanner.c" |
|
yy37: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
yy38: if(yych == '\t') goto yy37; |
|
if(yych == ' ') goto yy37; |
|
goto yy32; |
|
yy39: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
yy40: if(yych <= '@'){ |
|
if(yych <= '/') goto yy30; |
|
if(yych <= '9') goto yy39; |
|
goto yy30; |
|
} else { |
|
if(yych <= 'Z') goto yy39; |
|
if(yych <= '`') goto yy30; |
|
if(yych <= 'z') goto yy39; |
|
goto yy30; |
|
} |
|
yy41: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
yy42: if(yych <= '['){ |
|
if(yych != '\n') goto yy41; |
|
} else { |
|
if(yych <= '\\') goto yy44; |
|
if(yych <= ']') goto yy45; |
|
goto yy41; |
|
} |
|
yy43: YYCURSOR = YYMARKER; |
|
switch(yyaccept){ |
|
case 0: goto yy24; |
|
case 1: goto yy26; |
|
} |
|
yy44: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
if(yych == '\n') goto yy43; |
|
goto yy41; |
|
yy45: yych = *++YYCURSOR; |
|
|
|
#line 121 "scanner.re" |
|
{ s->cur = cursor; |
|
yylval.regexp = ranToRE(Scanner_token(s)); |
|
return RANGE; } |
|
#line 314 "scanner.c" |
|
yy47: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
yy48: if(yych <= '!'){ |
|
if(yych == '\n') goto yy43; |
|
goto yy47; |
|
} else { |
|
if(yych <= '"') goto yy50; |
|
if(yych != '\\') goto yy47; |
|
} |
|
++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
if(yych == '\n') goto yy43; |
|
goto yy47; |
|
yy50: yych = *++YYCURSOR; |
|
|
|
#line 116 "scanner.re" |
|
{ s->cur = cursor; |
|
yylval.regexp = strToRE(Scanner_token(s)); |
|
return STRING; } |
|
#line 336 "scanner.c" |
|
yy52: yych = *++YYCURSOR; |
|
|
|
#line 113 "scanner.re" |
|
{ s->tok = cursor; |
|
RETURN(0); } |
|
#line 342 "scanner.c" |
|
yy54: yych = *++YYCURSOR; |
|
|
|
#line 110 "scanner.re" |
|
{ depth = 1; |
|
goto comment; } |
|
#line 348 "scanner.c" |
|
} |
|
#line 147 "scanner.re" |
|
|
|
|
|
code: |
|
|
|
#line 355 "scanner.c" |
|
{ |
|
YYCTYPE yych; |
|
unsigned int yyaccept; |
|
goto yy56; |
|
++YYCURSOR; |
|
yy56: |
|
if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); |
|
yych = *YYCURSOR; |
|
if(yych <= '&'){ |
|
if(yych <= '\n'){ |
|
if(yych <= '\t') goto yy64; |
|
goto yy62; |
|
} else { |
|
if(yych == '"') goto yy66; |
|
goto yy64; |
|
} |
|
} else { |
|
if(yych <= '{'){ |
|
if(yych <= '\'') goto yy67; |
|
if(yych <= 'z') goto yy64; |
|
goto yy60; |
|
} else { |
|
if(yych != '}') goto yy64; |
|
} |
|
} |
|
yych = *++YYCURSOR; |
|
|
|
#line 151 "scanner.re" |
|
{ if(--depth == 0){ |
|
s->cur = cursor; |
|
yylval.token = Token_new(Scanner_token(s), s->tline); |
|
return CODE; |
|
} |
|
goto code; } |
|
#line 390 "scanner.c" |
|
yy60: yych = *++YYCURSOR; |
|
|
|
#line 157 "scanner.re" |
|
{ ++depth; |
|
goto code; } |
|
#line 396 "scanner.c" |
|
yy62: yych = *++YYCURSOR; |
|
|
|
#line 159 "scanner.re" |
|
{ if(cursor == s->eof) Scanner_fatal(s, "missing '}'"); |
|
s->pos = cursor; s->cline++; |
|
goto code; |
|
} |
|
#line 404 "scanner.c" |
|
yy64: yych = *++YYCURSOR; |
|
yy65: |
|
#line 163 "scanner.re" |
|
{ goto code; } |
|
#line 409 "scanner.c" |
|
yy66: yyaccept = 0; |
|
yych = *(YYMARKER = ++YYCURSOR); |
|
if(yych == '\n') goto yy65; |
|
goto yy73; |
|
yy67: yyaccept = 0; |
|
yych = *(YYMARKER = ++YYCURSOR); |
|
if(yych == '\n') goto yy65; |
|
goto yy69; |
|
yy68: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
yy69: if(yych <= '&'){ |
|
if(yych != '\n') goto yy68; |
|
} else { |
|
if(yych <= '\'') goto yy64; |
|
if(yych == '\\') goto yy71; |
|
goto yy68; |
|
} |
|
yy70: YYCURSOR = YYMARKER; |
|
switch(yyaccept){ |
|
case 0: goto yy65; |
|
} |
|
yy71: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
if(yych == '\n') goto yy70; |
|
goto yy68; |
|
yy72: ++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
yy73: if(yych <= '!'){ |
|
if(yych == '\n') goto yy70; |
|
goto yy72; |
|
} else { |
|
if(yych <= '"') goto yy64; |
|
if(yych != '\\') goto yy72; |
|
} |
|
++YYCURSOR; |
|
if(YYLIMIT == YYCURSOR) YYFILL(1); |
|
yych = *YYCURSOR; |
|
if(yych == '\n') goto yy70; |
|
goto yy72; |
|
} |
|
#line 164 "scanner.re" |
|
|
|
|
|
comment: |
|
|
|
#line 458 "scanner.c" |
|
{ |
|
YYCTYPE yych; |
|
unsigned int yyaccept; |
|
goto yy75; |
|
++YYCURSOR; |
|
yy75: |
|
if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); |
|
yych = *YYCURSOR; |
|
if(yych <= ')'){ |
|
if(yych == '\n') goto yy80; |
|
goto yy82; |
|
} else { |
|
if(yych <= '*') goto yy77; |
|
if(yych == '/') goto yy79; |
|
goto yy82; |
|
} |
|
yy77: yych = *++YYCURSOR; |
|
if(yych == '/') goto yy85; |
|
yy78: |
|
#line 178 "scanner.re" |
|
{ goto comment; } |
|
#line 480 "scanner.c" |
|
yy79: yych = *++YYCURSOR; |
|
if(yych == '*') goto yy83; |
|
goto yy78; |
|
yy80: yych = *++YYCURSOR; |
|
|
|
#line 174 "scanner.re" |
|
{ if(cursor == s->eof) RETURN(0); |
|
s->tok = s->pos = cursor; s->cline++; |
|
goto comment; |
|
} |
|
#line 491 "scanner.c" |
|
yy82: yych = *++YYCURSOR; |
|
goto yy78; |
|
yy83: yych = *++YYCURSOR; |
|
|
|
#line 172 "scanner.re" |
|
{ ++depth; |
|
goto comment; } |
|
#line 499 "scanner.c" |
|
yy85: yych = *++YYCURSOR; |
|
|
|
#line 168 "scanner.re" |
|
{ if(--depth == 0) |
|
goto scan; |
|
else |
|
goto comment; } |
|
#line 507 "scanner.c" |
|
} |
|
#line 179 "scanner.re" |
|
|
|
} |
|
|
|
void |
|
Scanner_fatal(Scanner *s, const char *msg) |
|
{ |
|
fprintf(stderr, "line %d, column %d: %s\n", s->tline, s->tchar + 1, msg); |
|
exit(1); |
|
}
|
|
|