* src/scan-gram.l (YY_OBS_INIT): Remove, replace with...

[SC_COMMENT,SC_STRING,SC_CHARACTER,SC_BRACED_CODE,SC_PROLOGUE]
[SC_EPILOGUE]: Output the quadrigraphs only when not in a comment.
* src/reader.h, src/scan-gram.l (scanner_initialize): this.
* src/reader.c (reader): Use it.
This commit is contained in:
Akim Demaille
2002-06-11 21:46:16 +00:00
parent 4cdb01db9b
commit 1d6412adeb
5 changed files with 160 additions and 145 deletions

View File

@@ -1,3 +1,12 @@
2002-06-11 Akim Demaille <akim@epita.fr>
* src/scan-gram.l (YY_OBS_INIT): Remove, replace with...
[SC_COMMENT,SC_STRING,SC_CHARACTER,SC_BRACED_CODE,SC_PROLOGUE]
[SC_EPILOGUE]: Output the quadrigraphs only when not in a comment.
* src/reader.h, src/scan-gram.l (scanner_initialize): this.
* src/reader.c (reader): Use it.
2002-06-11 Akim Demaille <akim@epita.fr> 2002-06-11 Akim Demaille <akim@epita.fr>
* src/scan-gram.l (YY_OBS_FINISH): Don't set yylval. * src/scan-gram.l (YY_OBS_FINISH): Don't set yylval.

View File

@@ -481,6 +481,7 @@ reader (void)
gram_debug = !!getenv ("parse"); gram_debug = !!getenv ("parse");
gram__flex_debug = !!getenv ("scan"); gram__flex_debug = !!getenv ("scan");
scanner_initialize ();
gram_parse (&gram_control); gram_parse (&gram_control);
/* Grammar has been read. Do some checking */ /* Grammar has been read. Do some checking */

View File

@@ -79,6 +79,7 @@ typedef struct gram_control_s
extern FILE *gram_in; extern FILE *gram_in;
extern int gram__flex_debug; extern int gram__flex_debug;
void scanner_last_string_free PARAMS ((void)); void scanner_last_string_free PARAMS ((void));
void scanner_initialize PARAMS ((void));
void scanner_free PARAMS ((void)); void scanner_free PARAMS ((void));
# define YY_DECL \ # define YY_DECL \

View File

@@ -689,16 +689,16 @@ int yy_flex_debug = 1;
static yyconst short int yy_rule_linenum[92] = static yyconst short int yy_rule_linenum[92] =
{ 0, { 0,
121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
141, 142, 143, 144, 145, 146, 147, 149, 150, 151, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147,
152, 154, 155, 156, 161, 164, 167, 170, 171, 174, 148, 150, 151, 152, 157, 160, 163, 166, 167, 170,
177, 180, 189, 195, 211, 212, 223, 235, 236, 237, 173, 176, 184, 190, 206, 207, 218, 230, 231, 232,
254, 263, 265, 285, 299, 301, 321, 333, 337, 338, 249, 258, 260, 280, 294, 296, 316, 328, 332, 333,
339, 340, 341, 342, 343, 344, 345, 360, 366, 367, 334, 335, 336, 337, 338, 339, 340, 355, 361, 362,
369, 387, 393, 394, 396, 414, 417, 420, 421, 432, 364, 382, 388, 389, 391, 409, 412, 415, 416, 427,
443, 445, 446, 448, 449, 452, 472, 479, 480, 481, 438, 440, 441, 443, 444, 447, 467, 474, 475, 476,
502 497
} ; } ;
@@ -753,18 +753,14 @@ char *yytext;
keep (to construct ID, STRINGS etc.). Use the following macros to keep (to construct ID, STRINGS etc.). Use the following macros to
use it. use it.
Use YY_OBS_INIT to initialize a new growing string, YY_OBS_GROW to Use YY_OBS_GROW to append what has just been matched, and
append what has just been matched, and YY_OBS_FINISH to end the YY_OBS_FINISH to end the string (it puts the ending 0).
string (it puts the ending 0). YY_OBS_FINISH also stores this YY_OBS_FINISH also stores this string in LAST_STRING, which can be
string in LAST_STRING, which can be used, and which is used by used, and which is used by YY_OBS_FREE to free the last string. */
YY_OBS_FREE to free the last string. */
static struct obstack string_obstack; static struct obstack string_obstack;
char *last_string; char *last_string;
#define YY_OBS_INIT \
obstack_init (&string_obstack)
#define YY_OBS_GROW \ #define YY_OBS_GROW \
obstack_grow (&string_obstack, yytext, yyleng) obstack_grow (&string_obstack, yytext, yyleng)
@@ -808,7 +804,7 @@ static void handle_at PARAMS ((char *cp));
#define SC_PROLOGUE 7 #define SC_PROLOGUE 7
#define SC_EPILOGUE 8 #define SC_EPILOGUE 8
#line 812 "scan-gram.c" #line 808 "scan-gram.c"
/* Macros after this point can all be overridden by user definitions in /* Macros after this point can all be overridden by user definitions in
* section 1. * section 1.
@@ -970,7 +966,7 @@ YY_DECL
register char *yy_cp, *yy_bp; register char *yy_cp, *yy_bp;
register int yy_act; register int yy_act;
#line 97 "scan-gram.l" #line 93 "scan-gram.l"
/* At each yylex invocation, mark the current position as the /* At each yylex invocation, mark the current position as the
@@ -993,7 +989,7 @@ YY_DECL
/*----------------------------. /*----------------------------.
| Scanning Bison directives. | | Scanning Bison directives. |
`----------------------------*/ `----------------------------*/
#line 997 "scan-gram.c" #line 993 "scan-gram.c"
if ( yy_init ) if ( yy_init )
{ {
@@ -1095,172 +1091,172 @@ do_action: /* This label is used only to access EOF actions. */
case 1: case 1:
YY_RULE_SETUP YY_RULE_SETUP
#line 121 "scan-gram.l" #line 117 "scan-gram.l"
return PERCENT_NONASSOC; return PERCENT_NONASSOC;
YY_BREAK YY_BREAK
case 2: case 2:
YY_RULE_SETUP YY_RULE_SETUP
#line 122 "scan-gram.l" #line 118 "scan-gram.l"
return PERCENT_DEBUG; return PERCENT_DEBUG;
YY_BREAK YY_BREAK
case 3: case 3:
YY_RULE_SETUP YY_RULE_SETUP
#line 123 "scan-gram.l" #line 119 "scan-gram.l"
return PERCENT_DEFINE; return PERCENT_DEFINE;
YY_BREAK YY_BREAK
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
#line 124 "scan-gram.l" #line 120 "scan-gram.l"
return PERCENT_DEFINES; return PERCENT_DEFINES;
YY_BREAK YY_BREAK
case 5: case 5:
YY_RULE_SETUP YY_RULE_SETUP
#line 125 "scan-gram.l" #line 121 "scan-gram.l"
return PERCENT_ERROR_VERBOSE; return PERCENT_ERROR_VERBOSE;
YY_BREAK YY_BREAK
case 6: case 6:
YY_RULE_SETUP YY_RULE_SETUP
#line 126 "scan-gram.l" #line 122 "scan-gram.l"
return PERCENT_EXPECT; return PERCENT_EXPECT;
YY_BREAK YY_BREAK
case 7: case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 127 "scan-gram.l" #line 123 "scan-gram.l"
return PERCENT_FILE_PREFIX; return PERCENT_FILE_PREFIX;
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 128 "scan-gram.l" #line 124 "scan-gram.l"
return PERCENT_YACC; return PERCENT_YACC;
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
#line 129 "scan-gram.l" #line 125 "scan-gram.l"
return PERCENT_LEFT; return PERCENT_LEFT;
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 130 "scan-gram.l" #line 126 "scan-gram.l"
return PERCENT_LOCATIONS; return PERCENT_LOCATIONS;
YY_BREAK YY_BREAK
case 11: case 11:
YY_RULE_SETUP YY_RULE_SETUP
#line 131 "scan-gram.l" #line 127 "scan-gram.l"
return PERCENT_NAME_PREFIX; return PERCENT_NAME_PREFIX;
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 132 "scan-gram.l" #line 128 "scan-gram.l"
return PERCENT_NO_LINES; return PERCENT_NO_LINES;
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
#line 133 "scan-gram.l" #line 129 "scan-gram.l"
return PERCENT_NONASSOC; return PERCENT_NONASSOC;
YY_BREAK YY_BREAK
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
#line 134 "scan-gram.l" #line 130 "scan-gram.l"
return PERCENT_NTERM; return PERCENT_NTERM;
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
#line 135 "scan-gram.l" #line 131 "scan-gram.l"
return PERCENT_OUTPUT; return PERCENT_OUTPUT;
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 136 "scan-gram.l" #line 132 "scan-gram.l"
return PERCENT_PREC; return PERCENT_PREC;
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
#line 137 "scan-gram.l" #line 133 "scan-gram.l"
return PERCENT_PURE_PARSER; return PERCENT_PURE_PARSER;
YY_BREAK YY_BREAK
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
#line 138 "scan-gram.l" #line 134 "scan-gram.l"
return PERCENT_RIGHT; return PERCENT_RIGHT;
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
#line 139 "scan-gram.l" #line 135 "scan-gram.l"
return PERCENT_SKELETON; return PERCENT_SKELETON;
YY_BREAK YY_BREAK
case 20: case 20:
YY_RULE_SETUP YY_RULE_SETUP
#line 140 "scan-gram.l" #line 136 "scan-gram.l"
return PERCENT_START; return PERCENT_START;
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
#line 141 "scan-gram.l" #line 137 "scan-gram.l"
return PERCENT_TOKEN; return PERCENT_TOKEN;
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 142 "scan-gram.l" #line 138 "scan-gram.l"
return PERCENT_TOKEN; return PERCENT_TOKEN;
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 143 "scan-gram.l" #line 139 "scan-gram.l"
return PERCENT_TOKEN_TABLE; return PERCENT_TOKEN_TABLE;
YY_BREAK YY_BREAK
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
#line 144 "scan-gram.l" #line 140 "scan-gram.l"
return PERCENT_TYPE; return PERCENT_TYPE;
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 145 "scan-gram.l" #line 141 "scan-gram.l"
return PERCENT_UNION; return PERCENT_UNION;
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
#line 146 "scan-gram.l" #line 142 "scan-gram.l"
return PERCENT_VERBOSE; return PERCENT_VERBOSE;
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
#line 147 "scan-gram.l" #line 143 "scan-gram.l"
return PERCENT_YACC; return PERCENT_YACC;
YY_BREAK YY_BREAK
case 28: case 28:
YY_RULE_SETUP YY_RULE_SETUP
#line 149 "scan-gram.l" #line 145 "scan-gram.l"
return EQUAL; return EQUAL;
YY_BREAK YY_BREAK
case 29: case 29:
YY_RULE_SETUP YY_RULE_SETUP
#line 150 "scan-gram.l" #line 146 "scan-gram.l"
return COLON; return COLON;
YY_BREAK YY_BREAK
case 30: case 30:
YY_RULE_SETUP YY_RULE_SETUP
#line 151 "scan-gram.l" #line 147 "scan-gram.l"
return PIPE; return PIPE;
YY_BREAK YY_BREAK
case 31: case 31:
YY_RULE_SETUP YY_RULE_SETUP
#line 152 "scan-gram.l" #line 148 "scan-gram.l"
return SEMICOLON; return SEMICOLON;
YY_BREAK YY_BREAK
case 32: case 32:
YY_RULE_SETUP YY_RULE_SETUP
#line 154 "scan-gram.l" #line 150 "scan-gram.l"
YY_LINES; YY_STEP; YY_LINES; YY_STEP;
YY_BREAK YY_BREAK
case 33: case 33:
YY_RULE_SETUP YY_RULE_SETUP
#line 155 "scan-gram.l" #line 151 "scan-gram.l"
YY_STEP; YY_STEP;
YY_BREAK YY_BREAK
case 34: case 34:
YY_RULE_SETUP YY_RULE_SETUP
#line 156 "scan-gram.l" #line 152 "scan-gram.l"
{ {
yylval->symbol = getsym (yytext); yylval->symbol = getsym (yytext);
return ID; return ID;
@@ -1268,50 +1264,49 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 35: case 35:
YY_RULE_SETUP YY_RULE_SETUP
#line 161 "scan-gram.l" #line 157 "scan-gram.l"
yylval->integer = strtol (yytext, 0, 10); return INT; yylval->integer = strtol (yytext, 0, 10); return INT;
YY_BREAK YY_BREAK
/* Characters. We don't check there is only one. */ /* Characters. We don't check there is only one. */
case 36: case 36:
YY_RULE_SETUP YY_RULE_SETUP
#line 164 "scan-gram.l" #line 160 "scan-gram.l"
YY_OBS_INIT; YY_OBS_GROW; yy_push_state (SC_ESCAPED_CHARACTER); YY_OBS_GROW; yy_push_state (SC_ESCAPED_CHARACTER);
YY_BREAK YY_BREAK
/* Strings. */ /* Strings. */
case 37: case 37:
YY_RULE_SETUP YY_RULE_SETUP
#line 167 "scan-gram.l" #line 163 "scan-gram.l"
YY_OBS_INIT; YY_OBS_GROW; yy_push_state (SC_ESCAPED_STRING); YY_OBS_GROW; yy_push_state (SC_ESCAPED_STRING);
YY_BREAK YY_BREAK
/* Comments. */ /* Comments. */
case 38: case 38:
YY_RULE_SETUP YY_RULE_SETUP
#line 170 "scan-gram.l" #line 166 "scan-gram.l"
yy_push_state (SC_COMMENT); yy_push_state (SC_COMMENT);
YY_BREAK YY_BREAK
case 39: case 39:
YY_RULE_SETUP YY_RULE_SETUP
#line 171 "scan-gram.l" #line 167 "scan-gram.l"
YY_STEP; YY_STEP;
YY_BREAK YY_BREAK
/* Prologue. */ /* Prologue. */
case 40: case 40:
YY_RULE_SETUP YY_RULE_SETUP
#line 174 "scan-gram.l" #line 170 "scan-gram.l"
YY_OBS_INIT; yy_push_state (SC_PROLOGUE); yy_push_state (SC_PROLOGUE);
YY_BREAK YY_BREAK
/* Code in between braces. */ /* Code in between braces. */
case 41: case 41:
YY_RULE_SETUP YY_RULE_SETUP
#line 177 "scan-gram.l" #line 173 "scan-gram.l"
YY_OBS_INIT; YY_OBS_GROW; ++braces_level; yy_push_state (SC_BRACED_CODE); YY_OBS_GROW; ++braces_level; yy_push_state (SC_BRACED_CODE);
YY_BREAK YY_BREAK
/* A type. */ /* A type. */
case 42: case 42:
YY_RULE_SETUP YY_RULE_SETUP
#line 180 "scan-gram.l" #line 176 "scan-gram.l"
{ {
YY_OBS_INIT;
obstack_grow (&string_obstack, yytext + 1, yyleng - 2); obstack_grow (&string_obstack, yytext + 1, yyleng - 2);
YY_OBS_FINISH; YY_OBS_FINISH;
yylval->string = last_string; yylval->string = last_string;
@@ -1320,7 +1315,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 43: case 43:
YY_RULE_SETUP YY_RULE_SETUP
#line 189 "scan-gram.l" #line 184 "scan-gram.l"
{ {
if (++percent_percent_count == 2) if (++percent_percent_count == 2)
yy_push_state (SC_EPILOGUE); yy_push_state (SC_EPILOGUE);
@@ -1329,7 +1324,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 44: case 44:
YY_RULE_SETUP YY_RULE_SETUP
#line 195 "scan-gram.l" #line 190 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": invalid character: `%c'\n", *yytext); fprintf (stderr, ": invalid character: `%c'\n", *yytext);
@@ -1346,13 +1341,13 @@ YY_RULE_SETUP
case 45: case 45:
YY_RULE_SETUP YY_RULE_SETUP
#line 211 "scan-gram.l" #line 206 "scan-gram.l"
obstack_sgrow (&string_obstack, "@<:@"); if (YY_START != SC_COMMENT) obstack_sgrow (&string_obstack, "@<:@");
YY_BREAK YY_BREAK
case 46: case 46:
YY_RULE_SETUP YY_RULE_SETUP
#line 212 "scan-gram.l" #line 207 "scan-gram.l"
obstack_sgrow (&string_obstack, "@:>@"); if (YY_START != SC_COMMENT) obstack_sgrow (&string_obstack, "@:>@");
YY_BREAK YY_BREAK
/*-----------------------------------------------------------. /*-----------------------------------------------------------.
@@ -1362,7 +1357,7 @@ obstack_sgrow (&string_obstack, "@:>@");
case 47: case 47:
YY_RULE_SETUP YY_RULE_SETUP
#line 223 "scan-gram.l" #line 218 "scan-gram.l"
{ /* End of the comment. */ { /* End of the comment. */
if (yy_top_state () == INITIAL) if (yy_top_state () == INITIAL)
{ {
@@ -1377,21 +1372,21 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 48: case 48:
YY_RULE_SETUP YY_RULE_SETUP
#line 235 "scan-gram.l" #line 230 "scan-gram.l"
if (yy_top_state () != INITIAL) YY_OBS_GROW; if (yy_top_state () != INITIAL) YY_OBS_GROW;
YY_BREAK YY_BREAK
case 49: case 49:
YY_RULE_SETUP YY_RULE_SETUP
#line 236 "scan-gram.l" #line 231 "scan-gram.l"
if (yy_top_state () != INITIAL) YY_OBS_GROW; YY_LINES; if (yy_top_state () != INITIAL) YY_OBS_GROW; YY_LINES;
YY_BREAK YY_BREAK
case 50: case 50:
YY_RULE_SETUP YY_RULE_SETUP
#line 237 "scan-gram.l" #line 232 "scan-gram.l"
/* Stray `*'. */if (yy_top_state () != INITIAL) YY_OBS_GROW; /* Stray `*'. */if (yy_top_state () != INITIAL) YY_OBS_GROW;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_COMMENT): case YY_STATE_EOF(SC_COMMENT):
#line 239 "scan-gram.l" #line 234 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unexpected end of file in a comment\n"); fprintf (stderr, ": unexpected end of file in a comment\n");
@@ -1407,7 +1402,7 @@ case YY_STATE_EOF(SC_COMMENT):
case 51: case 51:
YY_RULE_SETUP YY_RULE_SETUP
#line 254 "scan-gram.l" #line 249 "scan-gram.l"
{ {
assert (yy_top_state () == INITIAL); assert (yy_top_state () == INITIAL);
YY_OBS_GROW; YY_OBS_GROW;
@@ -1419,16 +1414,16 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 52: case 52:
YY_RULE_SETUP YY_RULE_SETUP
#line 263 "scan-gram.l" #line 258 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 53: case 53:
YY_RULE_SETUP YY_RULE_SETUP
#line 265 "scan-gram.l" #line 260 "scan-gram.l"
obstack_1grow (&string_obstack, '\n'); YY_LINES; obstack_1grow (&string_obstack, '\n'); YY_LINES;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_ESCAPED_STRING): case YY_STATE_EOF(SC_ESCAPED_STRING):
#line 267 "scan-gram.l" #line 262 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unexpected end of file in a string\n"); fprintf (stderr, ": unexpected end of file in a string\n");
@@ -1448,7 +1443,7 @@ case YY_STATE_EOF(SC_ESCAPED_STRING):
case 54: case 54:
YY_RULE_SETUP YY_RULE_SETUP
#line 285 "scan-gram.l" #line 280 "scan-gram.l"
{ {
YY_OBS_GROW; YY_OBS_GROW;
assert (yy_top_state () == INITIAL); assert (yy_top_state () == INITIAL);
@@ -1465,16 +1460,16 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 55: case 55:
YY_RULE_SETUP YY_RULE_SETUP
#line 299 "scan-gram.l" #line 294 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 56: case 56:
YY_RULE_SETUP YY_RULE_SETUP
#line 301 "scan-gram.l" #line 296 "scan-gram.l"
obstack_1grow (&string_obstack, '\n'); YY_LINES; obstack_1grow (&string_obstack, '\n'); YY_LINES;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_ESCAPED_CHARACTER): case YY_STATE_EOF(SC_ESCAPED_CHARACTER):
#line 303 "scan-gram.l" #line 298 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unexpected end of file in a character\n"); fprintf (stderr, ": unexpected end of file in a character\n");
@@ -1493,7 +1488,7 @@ case YY_STATE_EOF(SC_ESCAPED_CHARACTER):
case 57: case 57:
YY_RULE_SETUP YY_RULE_SETUP
#line 321 "scan-gram.l" #line 316 "scan-gram.l"
{ {
long c = strtol (yytext + 1, 0, 8); long c = strtol (yytext + 1, 0, 8);
if (c > 255) if (c > 255)
@@ -1508,54 +1503,54 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 58: case 58:
YY_RULE_SETUP YY_RULE_SETUP
#line 333 "scan-gram.l" #line 328 "scan-gram.l"
{ {
obstack_1grow (&string_obstack, strtol (yytext + 2, 0, 16)); obstack_1grow (&string_obstack, strtol (yytext + 2, 0, 16));
} }
YY_BREAK YY_BREAK
case 59: case 59:
YY_RULE_SETUP YY_RULE_SETUP
#line 337 "scan-gram.l" #line 332 "scan-gram.l"
obstack_1grow (&string_obstack, '\a'); obstack_1grow (&string_obstack, '\a');
YY_BREAK YY_BREAK
case 60: case 60:
YY_RULE_SETUP YY_RULE_SETUP
#line 338 "scan-gram.l" #line 333 "scan-gram.l"
obstack_1grow (&string_obstack, '\b'); obstack_1grow (&string_obstack, '\b');
YY_BREAK YY_BREAK
case 61: case 61:
YY_RULE_SETUP YY_RULE_SETUP
#line 339 "scan-gram.l" #line 334 "scan-gram.l"
obstack_1grow (&string_obstack, '\f'); obstack_1grow (&string_obstack, '\f');
YY_BREAK YY_BREAK
case 62: case 62:
YY_RULE_SETUP YY_RULE_SETUP
#line 340 "scan-gram.l" #line 335 "scan-gram.l"
obstack_1grow (&string_obstack, '\n'); obstack_1grow (&string_obstack, '\n');
YY_BREAK YY_BREAK
case 63: case 63:
YY_RULE_SETUP YY_RULE_SETUP
#line 341 "scan-gram.l" #line 336 "scan-gram.l"
obstack_1grow (&string_obstack, '\r'); obstack_1grow (&string_obstack, '\r');
YY_BREAK YY_BREAK
case 64: case 64:
YY_RULE_SETUP YY_RULE_SETUP
#line 342 "scan-gram.l" #line 337 "scan-gram.l"
obstack_1grow (&string_obstack, '\t'); obstack_1grow (&string_obstack, '\t');
YY_BREAK YY_BREAK
case 65: case 65:
YY_RULE_SETUP YY_RULE_SETUP
#line 343 "scan-gram.l" #line 338 "scan-gram.l"
obstack_1grow (&string_obstack, '\v'); obstack_1grow (&string_obstack, '\v');
YY_BREAK YY_BREAK
case 66: case 66:
YY_RULE_SETUP YY_RULE_SETUP
#line 344 "scan-gram.l" #line 339 "scan-gram.l"
obstack_1grow (&string_obstack, yytext[1]); obstack_1grow (&string_obstack, yytext[1]);
YY_BREAK YY_BREAK
case 67: case 67:
YY_RULE_SETUP YY_RULE_SETUP
#line 345 "scan-gram.l" #line 340 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unrecognized escape: %s\n", yytext); fprintf (stderr, ": unrecognized escape: %s\n", yytext);
@@ -1571,7 +1566,7 @@ YY_RULE_SETUP
case 68: case 68:
YY_RULE_SETUP YY_RULE_SETUP
#line 360 "scan-gram.l" #line 355 "scan-gram.l"
{ {
YY_OBS_GROW; YY_OBS_GROW;
assert (yy_top_state () != INITIAL); assert (yy_top_state () != INITIAL);
@@ -1580,21 +1575,21 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 69: case 69:
YY_RULE_SETUP YY_RULE_SETUP
#line 366 "scan-gram.l" #line 361 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 70: case 70:
YY_RULE_SETUP YY_RULE_SETUP
#line 367 "scan-gram.l" #line 362 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 71: case 71:
YY_RULE_SETUP YY_RULE_SETUP
#line 369 "scan-gram.l" #line 364 "scan-gram.l"
YY_OBS_GROW; YY_LINES; YY_OBS_GROW; YY_LINES;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_CHARACTER): case YY_STATE_EOF(SC_CHARACTER):
#line 371 "scan-gram.l" #line 366 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unexpected end of file in a character\n"); fprintf (stderr, ": unexpected end of file in a character\n");
@@ -1611,7 +1606,7 @@ case YY_STATE_EOF(SC_CHARACTER):
case 72: case 72:
YY_RULE_SETUP YY_RULE_SETUP
#line 387 "scan-gram.l" #line 382 "scan-gram.l"
{ {
assert (yy_top_state () != INITIAL); assert (yy_top_state () != INITIAL);
YY_OBS_GROW; YY_OBS_GROW;
@@ -1620,21 +1615,21 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 73: case 73:
YY_RULE_SETUP YY_RULE_SETUP
#line 393 "scan-gram.l" #line 388 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 74: case 74:
YY_RULE_SETUP YY_RULE_SETUP
#line 394 "scan-gram.l" #line 389 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 75: case 75:
YY_RULE_SETUP YY_RULE_SETUP
#line 396 "scan-gram.l" #line 391 "scan-gram.l"
YY_OBS_GROW; YY_LINES; YY_OBS_GROW; YY_LINES;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_STRING): case YY_STATE_EOF(SC_STRING):
#line 398 "scan-gram.l" #line 393 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unexpected end of file in a string\n"); fprintf (stderr, ": unexpected end of file in a string\n");
@@ -1651,24 +1646,24 @@ case YY_STATE_EOF(SC_STRING):
/* Characters. We don't check there is only one. */ /* Characters. We don't check there is only one. */
case 76: case 76:
YY_RULE_SETUP YY_RULE_SETUP
#line 414 "scan-gram.l" #line 409 "scan-gram.l"
YY_OBS_GROW; yy_push_state (SC_CHARACTER); YY_OBS_GROW; yy_push_state (SC_CHARACTER);
YY_BREAK YY_BREAK
/* Strings. */ /* Strings. */
case 77: case 77:
YY_RULE_SETUP YY_RULE_SETUP
#line 417 "scan-gram.l" #line 412 "scan-gram.l"
YY_OBS_GROW; yy_push_state (SC_STRING); YY_OBS_GROW; yy_push_state (SC_STRING);
YY_BREAK YY_BREAK
/* Comments. */ /* Comments. */
case 78: case 78:
YY_RULE_SETUP YY_RULE_SETUP
#line 420 "scan-gram.l" #line 415 "scan-gram.l"
YY_OBS_GROW; yy_push_state (SC_COMMENT); YY_OBS_GROW; yy_push_state (SC_COMMENT);
YY_BREAK YY_BREAK
case 79: case 79:
YY_RULE_SETUP YY_RULE_SETUP
#line 421 "scan-gram.l" #line 416 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
@@ -1680,7 +1675,7 @@ YY_OBS_GROW;
case 80: case 80:
YY_RULE_SETUP YY_RULE_SETUP
#line 432 "scan-gram.l" #line 427 "scan-gram.l"
{ {
YY_OBS_GROW; YY_OBS_GROW;
if (--braces_level == 0) if (--braces_level == 0)
@@ -1694,37 +1689,37 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 81: case 81:
YY_RULE_SETUP YY_RULE_SETUP
#line 443 "scan-gram.l" #line 438 "scan-gram.l"
YY_OBS_GROW; braces_level++; YY_OBS_GROW; braces_level++;
YY_BREAK YY_BREAK
case 82: case 82:
YY_RULE_SETUP YY_RULE_SETUP
#line 445 "scan-gram.l" #line 440 "scan-gram.l"
{ handle_dollar (yytext); } { handle_dollar (yytext); }
YY_BREAK YY_BREAK
case 83: case 83:
YY_RULE_SETUP YY_RULE_SETUP
#line 446 "scan-gram.l" #line 441 "scan-gram.l"
{ handle_at (yytext); } { handle_at (yytext); }
YY_BREAK YY_BREAK
case 84: case 84:
YY_RULE_SETUP YY_RULE_SETUP
#line 448 "scan-gram.l" #line 443 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 85: case 85:
YY_RULE_SETUP YY_RULE_SETUP
#line 449 "scan-gram.l" #line 444 "scan-gram.l"
YY_OBS_GROW; YY_LINES; YY_OBS_GROW; YY_LINES;
YY_BREAK YY_BREAK
/* A lose $, or /, or etc. */ /* A lose $, or /, or etc. */
case 86: case 86:
YY_RULE_SETUP YY_RULE_SETUP
#line 452 "scan-gram.l" #line 447 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_BRACED_CODE): case YY_STATE_EOF(SC_BRACED_CODE):
#line 454 "scan-gram.l" #line 449 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unexpected end of file in a braced code\n"); fprintf (stderr, ": unexpected end of file in a braced code\n");
@@ -1742,7 +1737,7 @@ case YY_STATE_EOF(SC_BRACED_CODE):
case 87: case 87:
YY_RULE_SETUP YY_RULE_SETUP
#line 472 "scan-gram.l" #line 467 "scan-gram.l"
{ {
yy_pop_state (); yy_pop_state ();
YY_OBS_FINISH; YY_OBS_FINISH;
@@ -1752,21 +1747,21 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 88: case 88:
YY_RULE_SETUP YY_RULE_SETUP
#line 479 "scan-gram.l" #line 474 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 89: case 89:
YY_RULE_SETUP YY_RULE_SETUP
#line 480 "scan-gram.l" #line 475 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case 90: case 90:
YY_RULE_SETUP YY_RULE_SETUP
#line 481 "scan-gram.l" #line 476 "scan-gram.l"
YY_OBS_GROW; YY_LINES; YY_OBS_GROW; YY_LINES;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_PROLOGUE): case YY_STATE_EOF(SC_PROLOGUE):
#line 483 "scan-gram.l" #line 478 "scan-gram.l"
{ {
LOCATION_PRINT (stderr, *yylloc); LOCATION_PRINT (stderr, *yylloc);
fprintf (stderr, ": unexpected end of file in a prologue\n"); fprintf (stderr, ": unexpected end of file in a prologue\n");
@@ -1785,11 +1780,11 @@ case YY_STATE_EOF(SC_PROLOGUE):
case 91: case 91:
YY_RULE_SETUP YY_RULE_SETUP
#line 502 "scan-gram.l" #line 497 "scan-gram.l"
YY_OBS_GROW; YY_OBS_GROW;
YY_BREAK YY_BREAK
case YY_STATE_EOF(SC_EPILOGUE): case YY_STATE_EOF(SC_EPILOGUE):
#line 504 "scan-gram.l" #line 499 "scan-gram.l"
{ {
yy_pop_state (); yy_pop_state ();
YY_OBS_FINISH; YY_OBS_FINISH;
@@ -1800,10 +1795,10 @@ case YY_STATE_EOF(SC_EPILOGUE):
case 92: case 92:
YY_RULE_SETUP YY_RULE_SETUP
#line 513 "scan-gram.l" #line 508 "scan-gram.l"
YY_FATAL_ERROR( "flex scanner jammed" ); YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK YY_BREAK
#line 1807 "scan-gram.c" #line 1802 "scan-gram.c"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
yyterminate(); yyterminate();
@@ -2693,7 +2688,7 @@ int main()
return 0; return 0;
} }
#endif #endif
#line 513 "scan-gram.l" #line 508 "scan-gram.l"
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
@@ -2811,6 +2806,13 @@ handle_at (char *cp)
} }
} }
void
scanner_initialize (void)
{
obstack_init (&string_obstack);
}
void void
scanner_free (void) scanner_free (void)
{ {

View File

@@ -40,18 +40,14 @@
keep (to construct ID, STRINGS etc.). Use the following macros to keep (to construct ID, STRINGS etc.). Use the following macros to
use it. use it.
Use YY_OBS_INIT to initialize a new growing string, YY_OBS_GROW to Use YY_OBS_GROW to append what has just been matched, and
append what has just been matched, and YY_OBS_FINISH to end the YY_OBS_FINISH to end the string (it puts the ending 0).
string (it puts the ending 0). YY_OBS_FINISH also stores this YY_OBS_FINISH also stores this string in LAST_STRING, which can be
string in LAST_STRING, which can be used, and which is used by used, and which is used by YY_OBS_FREE to free the last string. */
YY_OBS_FREE to free the last string. */
static struct obstack string_obstack; static struct obstack string_obstack;
char *last_string; char *last_string;
#define YY_OBS_INIT \
obstack_init (&string_obstack)
#define YY_OBS_GROW \ #define YY_OBS_GROW \
obstack_grow (&string_obstack, yytext, yyleng) obstack_grow (&string_obstack, yytext, yyleng)
@@ -161,24 +157,23 @@ blanks [ \t\f]+
{int} yylval->integer = strtol (yytext, 0, 10); return INT; {int} yylval->integer = strtol (yytext, 0, 10); return INT;
/* Characters. We don't check there is only one. */ /* Characters. We don't check there is only one. */
\' YY_OBS_INIT; YY_OBS_GROW; yy_push_state (SC_ESCAPED_CHARACTER); \' YY_OBS_GROW; yy_push_state (SC_ESCAPED_CHARACTER);
/* Strings. */ /* Strings. */
\" YY_OBS_INIT; YY_OBS_GROW; yy_push_state (SC_ESCAPED_STRING); \" YY_OBS_GROW; yy_push_state (SC_ESCAPED_STRING);
/* Comments. */ /* Comments. */
"/*" yy_push_state (SC_COMMENT); "/*" yy_push_state (SC_COMMENT);
"//".* YY_STEP; "//".* YY_STEP;
/* Prologue. */ /* Prologue. */
"%{" YY_OBS_INIT; yy_push_state (SC_PROLOGUE); "%{" yy_push_state (SC_PROLOGUE);
/* Code in between braces. */ /* Code in between braces. */
"{" YY_OBS_INIT; YY_OBS_GROW; ++braces_level; yy_push_state (SC_BRACED_CODE); "{" YY_OBS_GROW; ++braces_level; yy_push_state (SC_BRACED_CODE);
/* A type. */ /* A type. */
"<"[^>]+">" { "<"[^>]+">" {
YY_OBS_INIT;
obstack_grow (&string_obstack, yytext + 1, yyleng - 2); obstack_grow (&string_obstack, yytext + 1, yyleng - 2);
YY_OBS_FINISH; YY_OBS_FINISH;
yylval->string = last_string; yylval->string = last_string;
@@ -208,8 +203,8 @@ blanks [ \t\f]+
<SC_COMMENT,SC_STRING,SC_CHARACTER,SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE> <SC_COMMENT,SC_STRING,SC_CHARACTER,SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE>
{ {
\[ obstack_sgrow (&string_obstack, "@<:@"); \[ if (YY_START != SC_COMMENT) obstack_sgrow (&string_obstack, "@<:@");
\] obstack_sgrow (&string_obstack, "@:>@"); \] if (YY_START != SC_COMMENT) obstack_sgrow (&string_obstack, "@:>@");
} }
@@ -627,6 +622,13 @@ handle_at (char *cp)
} }
} }
void
scanner_initialize (void)
{
obstack_init (&string_obstack);
}
void void
scanner_free (void) scanner_free (void)
{ {