]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Bison Regressions. -*- Autotest -*- |
d42cf844 PE |
2 | |
3 | # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software | |
4 | # Foundation, Inc. | |
c95f2d78 | 5 | |
342b8b6e AD |
6 | # This program is free software; you can redistribute it and/or modify |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2, or (at your option) | |
9 | # any later version. | |
c95f2d78 | 10 | |
342b8b6e AD |
11 | # This program is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
c95f2d78 | 15 | |
342b8b6e AD |
16 | # You should have received a copy of the GNU General Public License |
17 | # along with this program; if not, write to the Free Software | |
0fb669f9 PE |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | # 02110-1301, USA. | |
c95f2d78 | 20 | |
342b8b6e | 21 | AT_BANNER([[Regression tests.]]) |
c95f2d78 | 22 | |
2b25d624 | 23 | |
276f48df PE |
24 | ## ------------------ ## |
25 | ## Trivial grammars. ## | |
26 | ## ------------------ ## | |
27 | ||
28 | AT_SETUP([Trivial grammars]) | |
29 | ||
30 | AT_DATA_GRAMMAR([input.y], | |
31 | [[%{ | |
32 | void yyerror (char const *); | |
33 | int yylex (void); | |
50cce58e | 34 | #define YYSTYPE int * |
276f48df PE |
35 | %} |
36 | ||
37 | %error-verbose | |
38 | ||
39 | %% | |
40 | ||
41 | program: 'x'; | |
42 | ]]) | |
43 | ||
44 | AT_CHECK([bison -o input.c input.y]) | |
45 | AT_COMPILE([input.o], [-c input.c]) | |
50cce58e | 46 | AT_COMPILE([input.o], [-DYYDEBUG -c input.c]) |
276f48df PE |
47 | |
48 | AT_CLEANUP | |
49 | ||
50 | ||
51 | ||
ddc8ede1 PE |
52 | ## ----------------- ## |
53 | ## YYSTYPE typedef. ## | |
54 | ## ----------------- ## | |
55 | ||
56 | AT_SETUP([YYSTYPE typedef]) | |
57 | ||
58 | AT_DATA_GRAMMAR([input.y], | |
59 | [[%{ | |
60 | void yyerror (char const *); | |
61 | int yylex (void); | |
62 | typedef union { char const *val; } YYSTYPE; | |
63 | %} | |
64 | ||
65 | %type <val> program | |
66 | ||
67 | %% | |
68 | ||
69 | program: { $$ = ""; }; | |
70 | ]]) | |
71 | ||
72 | AT_CHECK([bison -o input.c input.y]) | |
73 | AT_COMPILE([input.o], [-c input.c]) | |
74 | ||
75 | AT_CLEANUP | |
76 | ||
77 | ||
78 | ||
b931235e JD |
79 | ## ------------------------------------- ## |
80 | ## Early token definitions with --yacc. ## | |
81 | ## ------------------------------------- ## | |
69078d4b AD |
82 | |
83 | ||
b931235e | 84 | AT_SETUP([Early token definitions with --yacc]) |
69078d4b AD |
85 | |
86 | # Found in GCJ: they expect the tokens to be defined before the user | |
87 | # prologue, so that they can use the token definitions in it. | |
88 | ||
9501dc6e | 89 | AT_DATA_GRAMMAR([input.y], |
69078d4b AD |
90 | [[%{ |
91 | void yyerror (const char *s); | |
92 | int yylex (void); | |
93 | %} | |
94 | ||
95 | %union | |
96 | { | |
97 | int val; | |
98 | }; | |
9bc0dd67 JD |
99 | %{ |
100 | #ifndef MY_TOKEN | |
101 | # error "MY_TOKEN not defined." | |
102 | #endif | |
103 | %} | |
b931235e JD |
104 | %token MY_TOKEN |
105 | %% | |
106 | exp: MY_TOKEN; | |
107 | %% | |
108 | ]]) | |
109 | ||
110 | AT_CHECK([bison -y -o input.c input.y]) | |
111 | AT_COMPILE([input.o], [-c input.c]) | |
112 | ||
113 | AT_CLEANUP | |
114 | ||
115 | ||
116 | ||
117 | ## ---------------------------------------- ## | |
118 | ## Early token definitions without --yacc. ## | |
119 | ## ---------------------------------------- ## | |
120 | ||
121 | ||
122 | AT_SETUP([Early token definitions without --yacc]) | |
123 | ||
124 | # Found in GCJ: they expect the tokens to be defined before the user | |
125 | # prologue, so that they can use the token definitions in it. | |
126 | ||
127 | AT_DATA_GRAMMAR([input.y], | |
128 | [[%{ | |
129 | #include <stdio.h> | |
130 | void yyerror (const char *s); | |
131 | int yylex (void); | |
132 | void print_my_token (void); | |
9bc0dd67 JD |
133 | %} |
134 | ||
135 | %union | |
136 | { | |
137 | int val; | |
138 | }; | |
139 | %{ | |
b931235e JD |
140 | void |
141 | print_my_token (void) | |
142 | { | |
143 | enum yytokentype my_token = MY_TOKEN; | |
144 | printf ("%d\n", my_token); | |
145 | } | |
69078d4b AD |
146 | %} |
147 | %token MY_TOKEN | |
148 | %% | |
149 | exp: MY_TOKEN; | |
150 | %% | |
151 | ]]) | |
152 | ||
b56471a6 | 153 | AT_CHECK([bison -o input.c input.y]) |
002b9b7d | 154 | AT_COMPILE([input.o], [-c input.c]) |
69078d4b AD |
155 | |
156 | AT_CLEANUP | |
157 | ||
158 | ||
159 | ||
2b25d624 AD |
160 | ## ---------------- ## |
161 | ## Braces parsing. ## | |
162 | ## ---------------- ## | |
163 | ||
164 | ||
69078d4b | 165 | AT_SETUP([Braces parsing]) |
2b25d624 AD |
166 | |
167 | AT_DATA([input.y], | |
168 | [[/* Bison used to swallow the character after `}'. */ | |
169 | ||
170 | %% | |
bfcf1f3a | 171 | exp: { tests = {{{{{{{{{{}}}}}}}}}}; }; |
2b25d624 AD |
172 | %% |
173 | ]]) | |
174 | ||
b56471a6 | 175 | AT_CHECK([bison -v -o input.c input.y]) |
2b25d624 | 176 | |
a4bf0390 | 177 | AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore]) |
2b25d624 AD |
178 | |
179 | AT_CLEANUP | |
180 | ||
181 | ||
c95f2d78 AD |
182 | ## ------------------ ## |
183 | ## Duplicate string. ## | |
184 | ## ------------------ ## | |
185 | ||
186 | ||
187 | AT_SETUP([Duplicate string]) | |
188 | ||
f499b062 | 189 | AT_DATA([input.y], |
c95f2d78 AD |
190 | [[/* `Bison -v' used to dump core when two tokens are defined with the same |
191 | string, as LE and GE below. */ | |
192 | ||
193 | %token NUM | |
194 | %token LE "<=" | |
195 | %token GE "<=" | |
196 | ||
197 | %% | |
198 | exp: '(' exp ')' | NUM ; | |
199 | %% | |
200 | ]]) | |
201 | ||
b56471a6 | 202 | AT_CHECK([bison -v -o input.c input.y], 0, [], |
a5d50994 | 203 | [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string |
69078d4b | 204 | ]]) |
c95f2d78 | 205 | |
d803322e | 206 | AT_CLEANUP |
c95f2d78 AD |
207 | |
208 | ||
2ca209c1 AD |
209 | ## ------------------- ## |
210 | ## Rule Line Numbers. ## | |
211 | ## ------------------- ## | |
212 | ||
213 | AT_SETUP([Rule Line Numbers]) | |
214 | ||
6b98e4b5 AD |
215 | AT_KEYWORDS([report]) |
216 | ||
2ca209c1 AD |
217 | AT_DATA([input.y], |
218 | [[%% | |
219 | expr: | |
220 | 'a' | |
221 | ||
222 | { | |
223 | ||
224 | } | |
225 | ||
226 | 'b' | |
227 | ||
228 | { | |
229 | ||
230 | } | |
231 | ||
232 | | | |
233 | ||
234 | ||
235 | { | |
236 | ||
237 | ||
238 | } | |
239 | ||
240 | 'c' | |
241 | ||
242 | { | |
243 | ||
bfcf1f3a | 244 | }; |
2ca209c1 AD |
245 | ]]) |
246 | ||
b56471a6 | 247 | AT_CHECK([bison -o input.c -v input.y]) |
2ca209c1 AD |
248 | |
249 | # Check the contents of the report. | |
250 | AT_CHECK([cat input.output], [], | |
d2d1b42b | 251 | [[Grammar |
2ca209c1 | 252 | |
88bce5a2 | 253 | 0 $accept: expr $end |
6b98e4b5 AD |
254 | |
255 | 1 @1: /* empty */ | |
256 | ||
257 | 2 expr: 'a' @1 'b' | |
258 | ||
259 | 3 @2: /* empty */ | |
260 | ||
261 | 4 expr: @2 'c' | |
2ca209c1 | 262 | |
d2d1b42b | 263 | |
2ca209c1 AD |
264 | Terminals, with rules where they appear |
265 | ||
88bce5a2 | 266 | $end (0) 0 |
2ca209c1 AD |
267 | 'a' (97) 2 |
268 | 'b' (98) 2 | |
269 | 'c' (99) 4 | |
270 | error (256) | |
271 | ||
d2d1b42b | 272 | |
2ca209c1 AD |
273 | Nonterminals, with rules where they appear |
274 | ||
88bce5a2 | 275 | $accept (6) |
b365aa05 AD |
276 | on left: 0 |
277 | expr (7) | |
278 | on left: 2 4, on right: 0 | |
279 | @1 (8) | |
2ca209c1 | 280 | on left: 1, on right: 2 |
b365aa05 | 281 | @2 (9) |
2ca209c1 AD |
282 | on left: 3, on right: 4 |
283 | ||
284 | ||
285 | state 0 | |
286 | ||
88bce5a2 | 287 | 0 $accept: . expr $end |
643a5994 | 288 | |
87675353 | 289 | 'a' shift, and go to state 1 |
2ca209c1 | 290 | |
87675353 | 291 | $default reduce using rule 3 (@2) |
2ca209c1 | 292 | |
87675353 AD |
293 | expr go to state 2 |
294 | @2 go to state 3 | |
2ca209c1 AD |
295 | |
296 | ||
297 | state 1 | |
298 | ||
ce4ccb4b | 299 | 2 expr: 'a' . @1 'b' |
2ca209c1 | 300 | |
87675353 | 301 | $default reduce using rule 1 (@1) |
2ca209c1 | 302 | |
87675353 | 303 | @1 go to state 4 |
2ca209c1 AD |
304 | |
305 | ||
306 | state 2 | |
307 | ||
88bce5a2 | 308 | 0 $accept: expr . $end |
2ca209c1 | 309 | |
88bce5a2 | 310 | $end shift, and go to state 5 |
2ca209c1 AD |
311 | |
312 | ||
313 | state 3 | |
314 | ||
ce4ccb4b | 315 | 4 expr: @2 . 'c' |
2ca209c1 | 316 | |
87675353 | 317 | 'c' shift, and go to state 6 |
2ca209c1 AD |
318 | |
319 | ||
320 | state 4 | |
321 | ||
ce4ccb4b | 322 | 2 expr: 'a' @1 . 'b' |
2ca209c1 | 323 | |
87675353 | 324 | 'b' shift, and go to state 7 |
2ca209c1 AD |
325 | |
326 | ||
327 | state 5 | |
328 | ||
88bce5a2 | 329 | 0 $accept: expr $end . |
2ca209c1 | 330 | |
e8832397 | 331 | $default accept |
2ca209c1 AD |
332 | |
333 | ||
334 | state 6 | |
335 | ||
ce4ccb4b | 336 | 4 expr: @2 'c' . |
b365aa05 | 337 | |
87675353 | 338 | $default reduce using rule 4 (expr) |
2ca209c1 AD |
339 | |
340 | ||
341 | state 7 | |
342 | ||
ce4ccb4b | 343 | 2 expr: 'a' @1 'b' . |
b365aa05 | 344 | |
87675353 | 345 | $default reduce using rule 2 (expr) |
2ca209c1 AD |
346 | ]]) |
347 | ||
348 | AT_CLEANUP | |
349 | ||
350 | ||
351 | ||
cd5aafcf AD |
352 | ## ---------------------- ## |
353 | ## Mixing %token styles. ## | |
354 | ## ---------------------- ## | |
355 | ||
356 | ||
357 | AT_SETUP([Mixing %token styles]) | |
358 | ||
359 | # Taken from the documentation. | |
360 | AT_DATA([input.y], | |
361 | [[%token <operator> OR "||" | |
362 | %token <operator> LE 134 "<=" | |
363 | %left OR "<=" | |
364 | %% | |
365 | exp: ; | |
366 | %% | |
367 | ]]) | |
368 | ||
b56471a6 | 369 | AT_CHECK([bison -v -o input.c input.y]) |
cd5aafcf | 370 | |
d803322e | 371 | AT_CLEANUP |
cd5aafcf AD |
372 | |
373 | ||
374 | ||
29ae55f1 AD |
375 | ## ---------------- ## |
376 | ## Invalid inputs. ## | |
377 | ## ---------------- ## | |
561f9a30 AD |
378 | |
379 | ||
29ae55f1 | 380 | AT_SETUP([Invalid inputs]) |
561f9a30 AD |
381 | |
382 | AT_DATA([input.y], | |
383 | [[%% | |
384 | ? | |
561f9a30 | 385 | default: 'a' } |
29ae55f1 | 386 | %& |
2dfbfc12 | 387 | %a-does-not-exist |
29ae55f1 | 388 | %- |
e9955c83 | 389 | %{ |
561f9a30 AD |
390 | ]]) |
391 | ||
392 | AT_CHECK([bison input.y], [1], [], | |
e9955c83 AD |
393 | [[input.y:2.1: invalid character: `?' |
394 | input.y:3.14: invalid character: `}' | |
395 | input.y:4.1: invalid character: `%' | |
396 | input.y:4.2: invalid character: `&' | |
2dfbfc12 | 397 | input.y:5.1-17: invalid directive: `%a-does-not-exist' |
e9955c83 AD |
398 | input.y:6.1: invalid character: `%' |
399 | input.y:6.2: invalid character: `-' | |
2115939b | 400 | input.y:7.1-8.0: missing `%}' at end of file |
e0c40012 | 401 | ]]) |
561f9a30 AD |
402 | |
403 | AT_CLEANUP | |
404 | ||
405 | ||
fc01665e PE |
406 | AT_SETUP([Invalid inputs with {}]) |
407 | ||
408 | AT_DATA([input.y], | |
409 | [[ | |
410 | %destructor | |
411 | %initial-action | |
412 | %lex-param | |
413 | %parse-param | |
414 | %printer | |
415 | %union | |
416 | ]]) | |
417 | ||
418 | AT_CHECK([bison input.y], [1], [], | |
e9071366 | 419 | [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...} |
fc01665e PE |
420 | ]]) |
421 | ||
422 | AT_CLEANUP | |
423 | ||
424 | ||
270a173c | 425 | |
b87f8b21 AD |
426 | ## ------------------- ## |
427 | ## Token definitions. ## | |
428 | ## ------------------- ## | |
429 | ||
430 | ||
431 | AT_SETUP([Token definitions]) | |
432 | ||
433 | # Bison managed, when fed with `%token 'f' "f"' to #define 'f'! | |
9501dc6e | 434 | AT_DATA_GRAMMAR([input.y], |
db7c8e9a | 435 | [%{ |
ca407bdf | 436 | #include <stdio.h> |
db7c8e9a AD |
437 | void yyerror (const char *s); |
438 | int yylex (void); | |
439 | %} | |
ca407bdf PE |
440 | [%error-verbose |
441 | %token MYEOF 0 "end of file" | |
b87f8b21 | 442 | %token 'a' "a" |
4f136612 PE |
443 | %token B_TOKEN "b" |
444 | %token C_TOKEN 'c' | |
445 | %token 'd' D_TOKEN | |
3d54b576 | 446 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" |
b87f8b21 | 447 | %% |
3d54b576 | 448 | exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"; |
ca407bdf PE |
449 | %% |
450 | void | |
451 | yyerror (char const *s) | |
452 | { | |
453 | fprintf (stderr, "%s\n", s); | |
454 | } | |
455 | ||
456 | int | |
457 | yylex (void) | |
458 | { | |
459 | return SPECIAL; | |
460 | } | |
461 | ||
462 | int | |
463 | main (void) | |
464 | { | |
465 | return yyparse (); | |
466 | } | |
b87f8b21 AD |
467 | ]]) |
468 | ||
b56471a6 | 469 | AT_CHECK([bison -o input.c input.y]) |
ca407bdf | 470 | AT_COMPILE([input]) |
3d54b576 PE |
471 | AT_DATA([experr], |
472 | [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201?\?!", expecting a | |
473 | ]]) | |
474 | AT_PARSER_CHECK([./input], 1, [], [experr]) | |
b87f8b21 AD |
475 | AT_CLEANUP |
476 | ||
477 | ||
478 | ||
eb714592 AD |
479 | ## -------------------- ## |
480 | ## Characters Escapes. ## | |
481 | ## -------------------- ## | |
482 | ||
483 | ||
484 | AT_SETUP([Characters Escapes]) | |
485 | ||
9501dc6e | 486 | AT_DATA_GRAMMAR([input.y], |
eb714592 AD |
487 | [%{ |
488 | void yyerror (const char *s); | |
489 | int yylex (void); | |
490 | %} | |
491 | [%% | |
492 | exp: | |
493 | '\'' "\'" | |
494 | | '\"' "\"" | |
495 | | '"' "'" | |
496 | ; | |
497 | ]]) | |
9501dc6e | 498 | # Pacify font-lock-mode: " |
eb714592 | 499 | |
b56471a6 | 500 | AT_CHECK([bison -o input.c input.y]) |
eb714592 AD |
501 | AT_COMPILE([input.o], [-c input.c]) |
502 | AT_CLEANUP | |
503 | ||
504 | ||
505 | ||
b9752825 AD |
506 | ## -------------- ## |
507 | ## Web2c Report. ## | |
508 | ## -------------- ## | |
776209d6 AD |
509 | |
510 | # The generation of the reduction was once wrong in Bison, and made it | |
511 | # miss some reductions. In the following test case, the reduction on | |
512 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
513 | # the actual web2c.y. | |
514 | ||
b9752825 | 515 | AT_SETUP([Web2c Report]) |
776209d6 | 516 | |
6b98e4b5 AD |
517 | AT_KEYWORDS([report]) |
518 | ||
776209d6 AD |
519 | AT_DATA([input.y], |
520 | [[%token undef_id_tok const_id_tok | |
521 | ||
522 | %start CONST_DEC_PART | |
523 | \f | |
524 | %% | |
525 | CONST_DEC_PART: | |
526 | CONST_DEC_LIST | |
527 | ; | |
528 | ||
529 | CONST_DEC_LIST: | |
530 | CONST_DEC | |
531 | | CONST_DEC_LIST CONST_DEC | |
532 | ; | |
533 | ||
534 | CONST_DEC: | |
535 | { } undef_id_tok '=' const_id_tok ';' | |
536 | ; | |
537 | %% | |
776209d6 AD |
538 | ]]) |
539 | ||
540 | AT_CHECK([bison -v input.y]) | |
87675353 | 541 | AT_CHECK([cat input.output], 0, |
776209d6 | 542 | [[Grammar |
87675353 | 543 | |
88bce5a2 | 544 | 0 $accept: CONST_DEC_PART $end |
87675353 | 545 | |
6b98e4b5 | 546 | 1 CONST_DEC_PART: CONST_DEC_LIST |
87675353 | 547 | |
6b98e4b5 AD |
548 | 2 CONST_DEC_LIST: CONST_DEC |
549 | 3 | CONST_DEC_LIST CONST_DEC | |
87675353 | 550 | |
6b98e4b5 | 551 | 4 @1: /* empty */ |
87675353 | 552 | |
6b98e4b5 | 553 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' |
87675353 AD |
554 | |
555 | ||
776209d6 | 556 | Terminals, with rules where they appear |
87675353 | 557 | |
88bce5a2 | 558 | $end (0) 0 |
776209d6 AD |
559 | ';' (59) 5 |
560 | '=' (61) 5 | |
561 | error (256) | |
007a50a4 AD |
562 | undef_id_tok (258) 5 |
563 | const_id_tok (259) 5 | |
87675353 AD |
564 | |
565 | ||
776209d6 | 566 | Nonterminals, with rules where they appear |
87675353 | 567 | |
88bce5a2 | 568 | $accept (7) |
78d5bae9 AD |
569 | on left: 0 |
570 | CONST_DEC_PART (8) | |
571 | on left: 1, on right: 0 | |
572 | CONST_DEC_LIST (9) | |
776209d6 | 573 | on left: 2 3, on right: 1 3 |
78d5bae9 | 574 | CONST_DEC (10) |
776209d6 | 575 | on left: 5, on right: 2 3 |
78d5bae9 | 576 | @1 (11) |
776209d6 | 577 | on left: 4, on right: 5 |
87675353 AD |
578 | |
579 | ||
776209d6 | 580 | state 0 |
87675353 | 581 | |
88bce5a2 | 582 | 0 $accept: . CONST_DEC_PART $end |
87675353 AD |
583 | |
584 | $default reduce using rule 4 (@1) | |
585 | ||
586 | CONST_DEC_PART go to state 1 | |
587 | CONST_DEC_LIST go to state 2 | |
588 | CONST_DEC go to state 3 | |
589 | @1 go to state 4 | |
590 | ||
591 | ||
776209d6 | 592 | state 1 |
87675353 | 593 | |
88bce5a2 | 594 | 0 $accept: CONST_DEC_PART . $end |
87675353 | 595 | |
88bce5a2 | 596 | $end shift, and go to state 5 |
87675353 AD |
597 | |
598 | ||
78d5bae9 | 599 | state 2 |
87675353 | 600 | |
ce4ccb4b AD |
601 | 1 CONST_DEC_PART: CONST_DEC_LIST . |
602 | 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC | |
87675353 AD |
603 | |
604 | undef_id_tok reduce using rule 4 (@1) | |
605 | $default reduce using rule 1 (CONST_DEC_PART) | |
606 | ||
607 | CONST_DEC go to state 6 | |
608 | @1 go to state 4 | |
609 | ||
610 | ||
78d5bae9 | 611 | state 3 |
87675353 | 612 | |
ce4ccb4b | 613 | 2 CONST_DEC_LIST: CONST_DEC . |
87675353 AD |
614 | |
615 | $default reduce using rule 2 (CONST_DEC_LIST) | |
616 | ||
617 | ||
776209d6 | 618 | state 4 |
87675353 | 619 | |
ce4ccb4b | 620 | 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';' |
87675353 AD |
621 | |
622 | undef_id_tok shift, and go to state 7 | |
623 | ||
624 | ||
78d5bae9 | 625 | state 5 |
87675353 | 626 | |
88bce5a2 | 627 | 0 $accept: CONST_DEC_PART $end . |
87675353 | 628 | |
e8832397 | 629 | $default accept |
87675353 AD |
630 | |
631 | ||
78d5bae9 | 632 | state 6 |
87675353 | 633 | |
ce4ccb4b | 634 | 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC . |
87675353 AD |
635 | |
636 | $default reduce using rule 3 (CONST_DEC_LIST) | |
637 | ||
638 | ||
78d5bae9 | 639 | state 7 |
87675353 | 640 | |
ce4ccb4b | 641 | 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';' |
87675353 AD |
642 | |
643 | '=' shift, and go to state 8 | |
644 | ||
645 | ||
78d5bae9 | 646 | state 8 |
87675353 | 647 | |
ce4ccb4b | 648 | 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';' |
87675353 AD |
649 | |
650 | const_id_tok shift, and go to state 9 | |
651 | ||
652 | ||
78d5bae9 | 653 | state 9 |
87675353 | 654 | |
ce4ccb4b | 655 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';' |
87675353 AD |
656 | |
657 | ';' shift, and go to state 10 | |
658 | ||
659 | ||
78d5bae9 | 660 | state 10 |
87675353 | 661 | |
ce4ccb4b | 662 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' . |
87675353 AD |
663 | |
664 | $default reduce using rule 5 (CONST_DEC) | |
776209d6 AD |
665 | ]]) |
666 | ||
667 | AT_CLEANUP | |
b9752825 AD |
668 | |
669 | ||
670 | ## --------------- ## | |
671 | ## Web2c Actions. ## | |
672 | ## --------------- ## | |
673 | ||
674 | # The generation of the mapping `state -> action' was once wrong in | |
675 | # extremely specific situations. web2c.y exhibits this situation. | |
676 | # Below is a stripped version of the grammar. It looks like one can | |
677 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
678 | # which disapears when applying sane grammar transformations. | |
679 | # | |
680 | # It used to be wrong on yydefact only: | |
681 | # | |
d42cf844 | 682 | # static const yytype_uint8 yydefact[] = |
b9752825 AD |
683 | # { |
684 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
685 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
686 | # 0, 0 | |
687 | # }; | |
688 | # | |
689 | # but let's check all the tables. | |
690 | ||
691 | ||
692 | AT_SETUP([Web2c Actions]) | |
693 | ||
6b98e4b5 AD |
694 | AT_KEYWORDS([report]) |
695 | ||
b9752825 AD |
696 | AT_DATA([input.y], |
697 | [[%% | |
698 | statement: struct_stat; | |
699 | struct_stat: /* empty. */ | if else; | |
700 | if: "if" "const" "then" statement; | |
701 | else: "else" statement; | |
702 | %% | |
703 | ]]) | |
704 | ||
b56471a6 | 705 | AT_CHECK([bison -v -o input.c input.y]) |
b9752825 AD |
706 | |
707 | # Check only the tables. We don't use --no-parser, because it is | |
708 | # still to be implemented in the experimental branch of Bison. | |
ce4ccb4b AD |
709 | [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] |
710 | ||
711 | AT_CHECK([[cat tables.c]], 0, | |
d42cf844 | 712 | [[static const yytype_uint8 yytranslate[] = |
b9752825 AD |
713 | { |
714 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
715 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
716 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
717 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
718 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
719 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
720 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
721 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
722 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
723 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
724 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
725 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
726 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
727 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
728 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
729 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
730 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
731 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
732 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
733 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
734 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
735 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
736 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
737 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
738 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
007a50a4 AD |
739 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
740 | 5, 6 | |
b9752825 | 741 | }; |
d42cf844 | 742 | static const yytype_uint8 yyprhs[] = |
b9752825 | 743 | { |
e7b8bef1 | 744 | 0, 0, 3, 5, 6, 9, 14 |
b9752825 | 745 | }; |
d42cf844 | 746 | static const yytype_int8 yyrhs[] = |
b9752825 | 747 | { |
e7b8bef1 AD |
748 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, |
749 | 4, 5, 8, -1, 6, 8, -1 | |
b9752825 | 750 | }; |
d42cf844 | 751 | static const yytype_uint8 yyrline[] = |
b9752825 | 752 | { |
e7b8bef1 | 753 | 0, 2, 2, 3, 3, 4, 5 |
b9752825 AD |
754 | }; |
755 | static const char *const yytname[] = | |
756 | { | |
9e0876fb PE |
757 | "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"", |
758 | "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0 | |
b9752825 | 759 | }; |
d42cf844 | 760 | static const yytype_uint16 yytoknum[] = |
b9752825 | 761 | { |
3650b4b8 | 762 | 0, 256, 257, 258, 259, 260, 261 |
b9752825 | 763 | }; |
d42cf844 | 764 | static const yytype_uint8 yyr1[] = |
b9752825 | 765 | { |
e7b8bef1 | 766 | 0, 7, 8, 9, 9, 10, 11 |
b9752825 | 767 | }; |
d42cf844 | 768 | static const yytype_uint8 yyr2[] = |
b9752825 | 769 | { |
e7b8bef1 | 770 | 0, 2, 1, 0, 2, 4, 2 |
b9752825 | 771 | }; |
d42cf844 | 772 | static const yytype_uint8 yydefact[] = |
b9752825 | 773 | { |
e8832397 | 774 | 3, 0, 0, 2, 0, 0, 1, 3, 4, 3, |
e7b8bef1 | 775 | 6, 5 |
b9752825 | 776 | }; |
d42cf844 | 777 | static const yytype_int8 yydefgoto[] = |
b9752825 | 778 | { |
e7b8bef1 | 779 | -1, 2, 3, 4, 8 |
b9752825 | 780 | }; |
d42cf844 | 781 | static const yytype_int8 yypact[] = |
b9752825 | 782 | { |
12b0043a AD |
783 | -2, -1, 4, -8, 0, 2, -8, -2, -8, -2, |
784 | -8, -8 | |
b9752825 | 785 | }; |
d42cf844 | 786 | static const yytype_int8 yypgoto[] = |
b9752825 | 787 | { |
12b0043a | 788 | -8, -7, -8, -8, -8 |
b9752825 | 789 | }; |
d42cf844 | 790 | static const yytype_uint8 yytable[] = |
b9752825 | 791 | { |
e7b8bef1 | 792 | 10, 1, 11, 5, 6, 0, 7, 9 |
b9752825 | 793 | }; |
d42cf844 | 794 | static const yytype_int8 yycheck[] = |
b9752825 | 795 | { |
e7b8bef1 | 796 | 7, 3, 9, 4, 0, -1, 6, 5 |
b9752825 | 797 | }; |
d42cf844 | 798 | static const yytype_uint8 yystos[] = |
5504898e AD |
799 | { |
800 | 0, 3, 8, 9, 10, 4, 0, 6, 11, 5, | |
801 | 8, 8 | |
802 | }; | |
b9752825 AD |
803 | ]]) |
804 | ||
805 | AT_CLEANUP | |
22e304a6 AD |
806 | |
807 | ||
808 | ## ------------------------- ## | |
809 | ## yycheck Bound Violation. ## | |
810 | ## ------------------------- ## | |
811 | ||
812 | ||
813 | # _AT_DATA_DANCER_Y(BISON-OPTIONS) | |
814 | # -------------------------------- | |
815 | # The following grammar, taken from Andrew Suffield's GPL'd implementation | |
816 | # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate | |
817 | # yycheck's bounds where issuing a verbose error message. Keep this test | |
818 | # so that possible bound checking compilers could check all the skeletons. | |
819 | m4_define([_AT_DATA_DANCER_Y], | |
820 | [AT_DATA_GRAMMAR([dancer.y], | |
821 | [%{ | |
848dc439 PE |
822 | static int yylex (AT_LALR1_CC_IF([int *], [void])); |
823 | AT_LALR1_CC_IF([], | |
22e304a6 | 824 | [#include <stdio.h> |
848dc439 | 825 | static void yyerror (const char *);]) |
22e304a6 AD |
826 | %} |
827 | $1 | |
828 | %token ARROW INVALID NUMBER STRING DATA | |
829 | %defines | |
830 | %verbose | |
831 | %error-verbose | |
832 | /* Grammar follows */ | |
833 | %% | |
834 | line: header body | |
835 | ; | |
836 | ||
837 | header: '<' from ARROW to '>' type ':' | |
838 | | '<' ARROW to '>' type ':' | |
839 | | ARROW to type ':' | |
840 | | type ':' | |
841 | | '<' '>' | |
842 | ; | |
843 | ||
844 | from: DATA | |
845 | | STRING | |
846 | | INVALID | |
847 | ; | |
848 | ||
849 | to: DATA | |
850 | | STRING | |
851 | | INVALID | |
852 | ; | |
853 | ||
854 | type: DATA | |
855 | | STRING | |
856 | | INVALID | |
857 | ; | |
858 | ||
859 | body: /* empty */ | |
860 | | body member | |
861 | ; | |
862 | ||
863 | member: STRING | |
864 | | DATA | |
865 | | '+' NUMBER | |
866 | | '-' NUMBER | |
867 | | NUMBER | |
868 | | INVALID | |
869 | ; | |
870 | %% | |
871 | AT_LALR1_CC_IF( | |
68e11668 | 872 | [/* A C++ error reporting function. */ |
22e304a6 | 873 | void |
99880de5 | 874 | yy::parser::error (const location&, const std::string& m) |
22e304a6 | 875 | { |
efeed023 | 876 | std::cerr << m << std::endl; |
22e304a6 AD |
877 | } |
878 | ||
879 | int | |
99880de5 | 880 | yyparse () |
22e304a6 | 881 | { |
99880de5 | 882 | yy::parser parser; |
a3cb6248 | 883 | parser.set_debug_level (!!YYDEBUG); |
22e304a6 AD |
884 | return parser.parse (); |
885 | } | |
886 | ], | |
887 | [static void | |
888 | yyerror (const char *s) | |
889 | { | |
890 | fprintf (stderr, "%s\n", s); | |
891 | }]) | |
892 | ||
893 | static int | |
848dc439 | 894 | yylex (AT_LALR1_CC_IF([int *lval], [void])) |
22e304a6 AD |
895 | [{ |
896 | static int toknum = 0; | |
d6645148 | 897 | static int tokens[] = |
22e304a6 AD |
898 | { |
899 | ':', -1 | |
900 | }; | |
848dc439 | 901 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
22e304a6 AD |
902 | return tokens[toknum++]; |
903 | }] | |
904 | ||
905 | int | |
906 | main (void) | |
907 | { | |
908 | return yyparse (); | |
909 | } | |
910 | ]) | |
911 | ])# _AT_DATA_DANCER_Y | |
912 | ||
913 | ||
914 | # AT_CHECK_DANCER(BISON-OPTIONS) | |
915 | # ------------------------------ | |
916 | # Generate the grammar, compile it, run it. | |
917 | m4_define([AT_CHECK_DANCER], | |
918 | [AT_SETUP([Dancer $1]) | |
919 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
920 | _AT_DATA_DANCER_Y([$1]) | |
921 | AT_CHECK([bison -o dancer.c dancer.y]) | |
07971983 PE |
922 | AT_LALR1_CC_IF( |
923 | [AT_CHECK([bison -o dancer.cc dancer.y]) | |
924 | AT_COMPILE_CXX([dancer])], | |
925 | [AT_CHECK([bison -o dancer.c dancer.y]) | |
926 | AT_COMPILE([dancer])]) | |
22e304a6 | 927 | AT_PARSER_CHECK([./dancer], 1, [], |
d5286af1 | 928 | [syntax error, unexpected ':' |
22e304a6 AD |
929 | ]) |
930 | AT_BISON_OPTION_POPDEFS | |
931 | AT_CLEANUP | |
932 | ]) | |
933 | ||
934 | AT_CHECK_DANCER() | |
935 | AT_CHECK_DANCER([%glr-parser]) | |
936 | AT_CHECK_DANCER([%skeleton "lalr1.cc"]) | |
d6645148 PE |
937 | |
938 | ||
939 | ## ------------------------------------------ ## | |
940 | ## Diagnostic that expects two alternatives. ## | |
941 | ## ------------------------------------------ ## | |
942 | ||
943 | ||
944 | # _AT_DATA_EXPECT2_Y(BISON-OPTIONS) | |
945 | # -------------------------------- | |
946 | m4_define([_AT_DATA_EXPECT2_Y], | |
947 | [AT_DATA_GRAMMAR([expect2.y], | |
948 | [%{ | |
949 | static int yylex (AT_LALR1_CC_IF([int *], [void])); | |
950 | AT_LALR1_CC_IF([], | |
951 | [#include <stdio.h> | |
952 | static void yyerror (const char *);]) | |
953 | %} | |
954 | $1 | |
955 | %defines | |
956 | %error-verbose | |
957 | %token A 1000 | |
958 | %token B | |
959 | ||
960 | %% | |
961 | program: /* empty */ | |
962 | | program e ';' | |
963 | | program error ';'; | |
964 | ||
965 | e: e '+' t | t; | |
966 | t: A | B; | |
967 | ||
968 | %% | |
969 | AT_LALR1_CC_IF( | |
970 | [/* A C++ error reporting function. */ | |
971 | void | |
972 | yy::parser::error (const location&, const std::string& m) | |
973 | { | |
974 | std::cerr << m << std::endl; | |
975 | } | |
976 | ||
977 | int | |
978 | yyparse () | |
979 | { | |
980 | yy::parser parser; | |
981 | return parser.parse (); | |
982 | } | |
983 | ], | |
984 | [static void | |
985 | yyerror (const char *s) | |
986 | { | |
987 | fprintf (stderr, "%s\n", s); | |
988 | }]) | |
989 | ||
990 | static int | |
991 | yylex (AT_LALR1_CC_IF([int *lval], [void])) | |
992 | [{ | |
993 | static int toknum = 0; | |
994 | static int tokens[] = | |
995 | { | |
996 | 1000, '+', '+', -1 | |
997 | }; | |
998 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ | |
999 | return tokens[toknum++]; | |
1000 | }] | |
1001 | ||
1002 | int | |
1003 | main (void) | |
1004 | { | |
1005 | return yyparse (); | |
1006 | } | |
1007 | ]) | |
1008 | ])# _AT_DATA_EXPECT2_Y | |
1009 | ||
1010 | ||
1011 | # AT_CHECK_EXPECT2(BISON-OPTIONS) | |
1012 | # ------------------------------ | |
1013 | # Generate the grammar, compile it, run it. | |
1014 | m4_define([AT_CHECK_EXPECT2], | |
1015 | [AT_SETUP([Expecting two tokens $1]) | |
1016 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
1017 | _AT_DATA_EXPECT2_Y([$1]) | |
1018 | AT_CHECK([bison -o expect2.c expect2.y]) | |
1019 | AT_LALR1_CC_IF( | |
1020 | [AT_CHECK([bison -o expect2.cc expect2.y]) | |
1021 | AT_COMPILE_CXX([expect2])], | |
1022 | [AT_CHECK([bison -o expect2.c expect2.y]) | |
1023 | AT_COMPILE([expect2])]) | |
1024 | AT_PARSER_CHECK([./expect2], 1, [], | |
1025 | [syntax error, unexpected '+', expecting A or B | |
1026 | ]) | |
1027 | AT_BISON_OPTION_POPDEFS | |
1028 | AT_CLEANUP | |
1029 | ]) | |
1030 | ||
1031 | AT_CHECK_EXPECT2() | |
1032 | AT_CHECK_EXPECT2([%glr-parser]) | |
1033 | AT_CHECK_EXPECT2([%skeleton "lalr1.cc"]) | |
4210cd0b JD |
1034 | |
1035 | ||
1036 | ||
1037 | ## --------------------------------------------- ## | |
1038 | ## Braced code in declaration in rules section. ## | |
1039 | ## --------------------------------------------- ## | |
1040 | ||
1041 | AT_SETUP([Braced code in declaration in rules section]) | |
1042 | ||
1043 | # Bison once mistook braced code in a declaration in the rules section to be a | |
1044 | # rule action. | |
1045 | ||
1046 | AT_DATA_GRAMMAR([input.y], | |
1047 | [[%{ | |
1048 | #include <stdio.h> | |
381ecb06 JD |
1049 | static void yyerror (char const *msg); |
1050 | static int yylex (void); | |
4210cd0b JD |
1051 | %} |
1052 | ||
1053 | %error-verbose | |
1054 | ||
1055 | %% | |
1056 | ||
1057 | start: | |
1058 | { | |
1059 | printf ("Bison would once convert this action to a midrule because of the" | |
1060 | " subsequent braced code.\n"); | |
1061 | } | |
1062 | ; | |
1063 | ||
1064 | %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a'; | |
1065 | %printer { fprintf (yyoutput, "PRINTER"); } 'a'; | |
1066 | ||
1067 | %% | |
1068 | ||
381ecb06 | 1069 | static void |
4210cd0b JD |
1070 | yyerror (char const *msg) |
1071 | { | |
1072 | fprintf (stderr, "%s\n", msg); | |
1073 | } | |
1074 | ||
381ecb06 | 1075 | static int |
4210cd0b JD |
1076 | yylex (void) |
1077 | { | |
1078 | return 'a'; | |
1079 | } | |
1080 | ||
1081 | int | |
1082 | main (void) | |
1083 | { | |
1084 | yydebug = 1; | |
1085 | return !yyparse (); | |
1086 | } | |
1087 | ]]) | |
1088 | ||
1089 | AT_CHECK([bison -t -o input.c input.y]) | |
1090 | AT_COMPILE([input]) | |
1091 | AT_PARSER_CHECK([./input], 0, | |
1092 | [[Bison would once convert this action to a midrule because of the subsequent braced code. | |
1093 | ]], | |
1094 | [[Starting parse | |
1095 | Entering state 0 | |
1096 | Reducing stack by rule 1 (line 22): | |
1097 | -> $$ = nterm start () | |
1098 | Stack now 0 | |
1099 | Entering state 1 | |
1100 | Reading a token: Next token is token 'a' (PRINTER) | |
1101 | syntax error, unexpected 'a', expecting $end | |
1102 | Error: popping nterm start () | |
1103 | Stack now 0 | |
1104 | Cleanup: discarding lookahead token 'a' (PRINTER) | |
1105 | DESTRUCTOR | |
1106 | Stack now 0 | |
1107 | ]]) | |
1108 | ||
1109 | AT_CLEANUP |