169 |
|
|
170 |
#define YYERROR_VERBOSE 1 |
#define YYERROR_VERBOSE 1 |
171 |
#define YYDEBUG 1 |
#define YYDEBUG 1 |
|
#define YYPRINT yyprint |
|
172 |
%} |
%} |
173 |
%verbose |
%verbose |
174 |
%union |
%union |
176 |
int ival; |
int ival; |
177 |
} |
} |
178 |
%type <ival> 'x' thing line input |
%type <ival> 'x' thing line input |
179 |
%destructor { printf ("Freeing input %d from %d\n", $$, @$.first_line); } input |
|
180 |
%destructor { printf ("Freeing line %d from %d\n", $$, @$.first_line); } line |
%printer { fprintf (yyout, "%d from %d", $$, @$.first_line); } |
181 |
%destructor { printf ("Freeing thing %d from %d\n", $$, @$.first_line); } thing |
input line thing 'x' |
182 |
%destructor { printf ("Freeing 'x' %d from %d\n", $$, @$.first_line); } 'x' |
|
183 |
|
%destructor |
184 |
|
{ |
185 |
|
fprintf (stdout, "Freeing "); |
186 |
|
/* FIXME: Ouch: INTERNAL DETAILS EXPOSED HERE. */ |
187 |
|
/* Cannot use $$ which is the union member, not the union itself. */ |
188 |
|
yysymprint (stdout, yytype, yyvalue, @$); |
189 |
|
fprintf (stdout, "\n"); |
190 |
|
} |
191 |
|
input line thing 'x' |
192 |
|
|
193 |
%{ |
%{ |
194 |
static int yylex (void); |
static int yylex (void); |
263 |
if (counter < (sizeof(input) / sizeof (input[0]))) |
if (counter < (sizeof(input) / sizeof (input[0]))) |
264 |
{ |
{ |
265 |
yylval.ival = counter; |
yylval.ival = counter; |
266 |
printf ("sending: '%c'(%d)\n", input[counter], counter); |
printf ("sending: '%c' (line %d)\n", input[counter], counter); |
267 |
/* As in BASIC, line numbers go from 10 to 10. */ |
/* As in BASIC, line numbers go from 10 to 10. */ |
268 |
yylloc.first_line = 10 * counter; |
yylloc.first_line = 10 * counter; |
269 |
return input[counter++]; |
return input[counter++]; |
281 |
fprintf (stdout, "%d: %s\n", yylloc.first_line, msg); |
fprintf (stdout, "%d: %s\n", yylloc.first_line, msg); |
282 |
} |
} |
283 |
|
|
|
static void |
|
|
yyprint (FILE *out, int num, YYSTYPE val) |
|
|
{ |
|
|
fprintf (out, " = %d", val.ival); |
|
|
} |
|
|
|
|
284 |
int |
int |
285 |
main (void) |
main (void) |
286 |
{ |
{ |
298 |
AT_CHECK([bison input.y --location -d -v -o input.c]) |
AT_CHECK([bison input.y --location -d -v -o input.c]) |
299 |
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) |
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) |
300 |
AT_CHECK([./input], 1, |
AT_CHECK([./input], 1, |
301 |
[[sending: 'x'(0) |
[[sending: 'x' (line 0) |
302 |
thing(0): 'x'(0) |
thing(0): 'x'(0) |
303 |
sending: 'x'(1) |
sending: 'x' (line 1) |
304 |
thing(1): 'x'(1) |
thing(1): 'x'(1) |
305 |
sending: 'x'(2) |
sending: 'x' (line 2) |
306 |
thing(2): 'x'(2) |
thing(2): 'x'(2) |
307 |
sending: 'x'(3) |
sending: 'x' (line 3) |
308 |
30: parse error, unexpected 'x', expecting ';' |
30: parse error, unexpected 'x', expecting ';' |
309 |
Freeing thing 2 from 20 |
Freeing nterm thing (2 from 20) |
310 |
Freeing thing 1 from 10 |
Freeing nterm thing (1 from 10) |
311 |
Freeing thing 0 from 0 |
Freeing nterm thing (0 from 0) |
312 |
Freeing 'x' 3 from 30 |
Freeing token 'x' (3 from 30) |
313 |
sending: 'x'(4) |
sending: 'x' (line 4) |
314 |
Freeing 'x' 4 from 40 |
Freeing token 'x' (4 from 40) |
315 |
sending: 'x'(5) |
sending: 'x' (line 5) |
316 |
Freeing 'x' 5 from 50 |
Freeing token 'x' (5 from 50) |
317 |
sending: ';'(6) |
sending: ';' (line 6) |
318 |
line(-1): error ';' |
line(-1): error ';' |
319 |
sending: 'x'(7) |
sending: 'x' (line 7) |
320 |
thing(7): 'x'(7) |
thing(7): 'x'(7) |
321 |
sending: 'x'(8) |
sending: 'x' (line 8) |
322 |
thing(8): 'x'(8) |
thing(8): 'x'(8) |
323 |
sending: ';'(9) |
sending: ';' (line 9) |
324 |
line(7): thing(7) thing(8) ';' |
line(7): thing(7) thing(8) ';' |
325 |
sending: 'x'(10) |
sending: 'x' (line 10) |
326 |
thing(10): 'x'(10) |
thing(10): 'x'(10) |
327 |
sending: ';'(11) |
sending: ';' (line 11) |
328 |
line(10): thing(10) ';' |
line(10): thing(10) ';' |
329 |
sending: 'y'(12) |
sending: 'y' (line 12) |
330 |
120: parse error, unexpected $undefined., expecting $ or error or 'x' |
120: parse error, unexpected $undefined., expecting $ or error or 'x' |
331 |
sending: EOF |
sending: EOF |
332 |
Freeing line 10 from 100 |
Freeing nterm line (10 from 100) |
333 |
Freeing line 7 from 70 |
Freeing nterm line (7 from 70) |
334 |
Freeing line -1 from 50 |
Freeing nterm line (-1 from 50) |
335 |
Parsing FAILED. |
Parsing FAILED. |
336 |
]]) |
]]) |
337 |
|
|