]>
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 |
47aee066 | 401 | input.y:7.1-8.0: syntax error, unexpected %{...%} |
e0c40012 | 402 | ]]) |
561f9a30 AD |
403 | |
404 | AT_CLEANUP | |
405 | ||
406 | ||
fc01665e PE |
407 | AT_SETUP([Invalid inputs with {}]) |
408 | ||
409 | AT_DATA([input.y], | |
410 | [[ | |
411 | %destructor | |
412 | %initial-action | |
413 | %lex-param | |
414 | %parse-param | |
415 | %printer | |
416 | %union | |
417 | ]]) | |
418 | ||
419 | AT_CHECK([bison input.y], [1], [], | |
e9071366 | 420 | [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...} |
fc01665e PE |
421 | ]]) |
422 | ||
423 | AT_CLEANUP | |
424 | ||
425 | ||
270a173c | 426 | |
b87f8b21 AD |
427 | ## ------------------- ## |
428 | ## Token definitions. ## | |
429 | ## ------------------- ## | |
430 | ||
431 | ||
432 | AT_SETUP([Token definitions]) | |
433 | ||
434 | # Bison managed, when fed with `%token 'f' "f"' to #define 'f'! | |
9501dc6e | 435 | AT_DATA_GRAMMAR([input.y], |
db7c8e9a | 436 | [%{ |
ca407bdf | 437 | #include <stdio.h> |
db7c8e9a AD |
438 | void yyerror (const char *s); |
439 | int yylex (void); | |
440 | %} | |
ca407bdf PE |
441 | [%error-verbose |
442 | %token MYEOF 0 "end of file" | |
b87f8b21 | 443 | %token 'a' "a" |
4f136612 PE |
444 | %token B_TOKEN "b" |
445 | %token C_TOKEN 'c' | |
446 | %token 'd' D_TOKEN | |
3d54b576 | 447 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" |
b87f8b21 | 448 | %% |
3d54b576 | 449 | exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"; |
ca407bdf PE |
450 | %% |
451 | void | |
452 | yyerror (char const *s) | |
453 | { | |
454 | fprintf (stderr, "%s\n", s); | |
455 | } | |
456 | ||
457 | int | |
458 | yylex (void) | |
459 | { | |
460 | return SPECIAL; | |
461 | } | |
462 | ||
463 | int | |
464 | main (void) | |
465 | { | |
466 | return yyparse (); | |
467 | } | |
b87f8b21 AD |
468 | ]]) |
469 | ||
b56471a6 | 470 | AT_CHECK([bison -o input.c input.y]) |
ca407bdf | 471 | AT_COMPILE([input]) |
3d54b576 PE |
472 | AT_DATA([experr], |
473 | [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201?\?!", expecting a | |
474 | ]]) | |
475 | AT_PARSER_CHECK([./input], 1, [], [experr]) | |
b87f8b21 AD |
476 | AT_CLEANUP |
477 | ||
478 | ||
479 | ||
eb714592 AD |
480 | ## -------------------- ## |
481 | ## Characters Escapes. ## | |
482 | ## -------------------- ## | |
483 | ||
484 | ||
485 | AT_SETUP([Characters Escapes]) | |
486 | ||
9501dc6e | 487 | AT_DATA_GRAMMAR([input.y], |
eb714592 AD |
488 | [%{ |
489 | void yyerror (const char *s); | |
490 | int yylex (void); | |
491 | %} | |
492 | [%% | |
493 | exp: | |
494 | '\'' "\'" | |
495 | | '\"' "\"" | |
496 | | '"' "'" | |
497 | ; | |
498 | ]]) | |
9501dc6e | 499 | # Pacify font-lock-mode: " |
eb714592 | 500 | |
b56471a6 | 501 | AT_CHECK([bison -o input.c input.y]) |
eb714592 AD |
502 | AT_COMPILE([input.o], [-c input.c]) |
503 | AT_CLEANUP | |
504 | ||
505 | ||
506 | ||
b9752825 AD |
507 | ## -------------- ## |
508 | ## Web2c Report. ## | |
509 | ## -------------- ## | |
776209d6 AD |
510 | |
511 | # The generation of the reduction was once wrong in Bison, and made it | |
512 | # miss some reductions. In the following test case, the reduction on | |
513 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
514 | # the actual web2c.y. | |
515 | ||
b9752825 | 516 | AT_SETUP([Web2c Report]) |
776209d6 | 517 | |
6b98e4b5 AD |
518 | AT_KEYWORDS([report]) |
519 | ||
776209d6 AD |
520 | AT_DATA([input.y], |
521 | [[%token undef_id_tok const_id_tok | |
522 | ||
523 | %start CONST_DEC_PART | |
524 | \f | |
525 | %% | |
526 | CONST_DEC_PART: | |
527 | CONST_DEC_LIST | |
528 | ; | |
529 | ||
530 | CONST_DEC_LIST: | |
531 | CONST_DEC | |
532 | | CONST_DEC_LIST CONST_DEC | |
533 | ; | |
534 | ||
535 | CONST_DEC: | |
536 | { } undef_id_tok '=' const_id_tok ';' | |
537 | ; | |
538 | %% | |
776209d6 AD |
539 | ]]) |
540 | ||
541 | AT_CHECK([bison -v input.y]) | |
87675353 | 542 | AT_CHECK([cat input.output], 0, |
776209d6 | 543 | [[Grammar |
87675353 | 544 | |
88bce5a2 | 545 | 0 $accept: CONST_DEC_PART $end |
87675353 | 546 | |
6b98e4b5 | 547 | 1 CONST_DEC_PART: CONST_DEC_LIST |
87675353 | 548 | |
6b98e4b5 AD |
549 | 2 CONST_DEC_LIST: CONST_DEC |
550 | 3 | CONST_DEC_LIST CONST_DEC | |
87675353 | 551 | |
6b98e4b5 | 552 | 4 @1: /* empty */ |
87675353 | 553 | |
6b98e4b5 | 554 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' |
87675353 AD |
555 | |
556 | ||
776209d6 | 557 | Terminals, with rules where they appear |
87675353 | 558 | |
88bce5a2 | 559 | $end (0) 0 |
776209d6 AD |
560 | ';' (59) 5 |
561 | '=' (61) 5 | |
562 | error (256) | |
007a50a4 AD |
563 | undef_id_tok (258) 5 |
564 | const_id_tok (259) 5 | |
87675353 AD |
565 | |
566 | ||
776209d6 | 567 | Nonterminals, with rules where they appear |
87675353 | 568 | |
88bce5a2 | 569 | $accept (7) |
78d5bae9 AD |
570 | on left: 0 |
571 | CONST_DEC_PART (8) | |
572 | on left: 1, on right: 0 | |
573 | CONST_DEC_LIST (9) | |
776209d6 | 574 | on left: 2 3, on right: 1 3 |
78d5bae9 | 575 | CONST_DEC (10) |
776209d6 | 576 | on left: 5, on right: 2 3 |
78d5bae9 | 577 | @1 (11) |
776209d6 | 578 | on left: 4, on right: 5 |
87675353 AD |
579 | |
580 | ||
776209d6 | 581 | state 0 |
87675353 | 582 | |
88bce5a2 | 583 | 0 $accept: . CONST_DEC_PART $end |
87675353 AD |
584 | |
585 | $default reduce using rule 4 (@1) | |
586 | ||
587 | CONST_DEC_PART go to state 1 | |
588 | CONST_DEC_LIST go to state 2 | |
589 | CONST_DEC go to state 3 | |
590 | @1 go to state 4 | |
591 | ||
592 | ||
776209d6 | 593 | state 1 |
87675353 | 594 | |
88bce5a2 | 595 | 0 $accept: CONST_DEC_PART . $end |
87675353 | 596 | |
88bce5a2 | 597 | $end shift, and go to state 5 |
87675353 AD |
598 | |
599 | ||
78d5bae9 | 600 | state 2 |
87675353 | 601 | |
ce4ccb4b AD |
602 | 1 CONST_DEC_PART: CONST_DEC_LIST . |
603 | 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC | |
87675353 AD |
604 | |
605 | undef_id_tok reduce using rule 4 (@1) | |
606 | $default reduce using rule 1 (CONST_DEC_PART) | |
607 | ||
608 | CONST_DEC go to state 6 | |
609 | @1 go to state 4 | |
610 | ||
611 | ||
78d5bae9 | 612 | state 3 |
87675353 | 613 | |
ce4ccb4b | 614 | 2 CONST_DEC_LIST: CONST_DEC . |
87675353 AD |
615 | |
616 | $default reduce using rule 2 (CONST_DEC_LIST) | |
617 | ||
618 | ||
776209d6 | 619 | state 4 |
87675353 | 620 | |
ce4ccb4b | 621 | 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';' |
87675353 AD |
622 | |
623 | undef_id_tok shift, and go to state 7 | |
624 | ||
625 | ||
78d5bae9 | 626 | state 5 |
87675353 | 627 | |
88bce5a2 | 628 | 0 $accept: CONST_DEC_PART $end . |
87675353 | 629 | |
e8832397 | 630 | $default accept |
87675353 AD |
631 | |
632 | ||
78d5bae9 | 633 | state 6 |
87675353 | 634 | |
ce4ccb4b | 635 | 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC . |
87675353 AD |
636 | |
637 | $default reduce using rule 3 (CONST_DEC_LIST) | |
638 | ||
639 | ||
78d5bae9 | 640 | state 7 |
87675353 | 641 | |
ce4ccb4b | 642 | 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';' |
87675353 AD |
643 | |
644 | '=' shift, and go to state 8 | |
645 | ||
646 | ||
78d5bae9 | 647 | state 8 |
87675353 | 648 | |
ce4ccb4b | 649 | 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';' |
87675353 AD |
650 | |
651 | const_id_tok shift, and go to state 9 | |
652 | ||
653 | ||
78d5bae9 | 654 | state 9 |
87675353 | 655 | |
ce4ccb4b | 656 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';' |
87675353 AD |
657 | |
658 | ';' shift, and go to state 10 | |
659 | ||
660 | ||
78d5bae9 | 661 | state 10 |
87675353 | 662 | |
ce4ccb4b | 663 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' . |
87675353 AD |
664 | |
665 | $default reduce using rule 5 (CONST_DEC) | |
776209d6 AD |
666 | ]]) |
667 | ||
668 | AT_CLEANUP | |
b9752825 AD |
669 | |
670 | ||
671 | ## --------------- ## | |
672 | ## Web2c Actions. ## | |
673 | ## --------------- ## | |
674 | ||
675 | # The generation of the mapping `state -> action' was once wrong in | |
676 | # extremely specific situations. web2c.y exhibits this situation. | |
677 | # Below is a stripped version of the grammar. It looks like one can | |
678 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
679 | # which disapears when applying sane grammar transformations. | |
680 | # | |
681 | # It used to be wrong on yydefact only: | |
682 | # | |
d42cf844 | 683 | # static const yytype_uint8 yydefact[] = |
b9752825 AD |
684 | # { |
685 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
686 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
687 | # 0, 0 | |
688 | # }; | |
689 | # | |
690 | # but let's check all the tables. | |
691 | ||
692 | ||
693 | AT_SETUP([Web2c Actions]) | |
694 | ||
6b98e4b5 AD |
695 | AT_KEYWORDS([report]) |
696 | ||
b9752825 AD |
697 | AT_DATA([input.y], |
698 | [[%% | |
699 | statement: struct_stat; | |
700 | struct_stat: /* empty. */ | if else; | |
701 | if: "if" "const" "then" statement; | |
702 | else: "else" statement; | |
703 | %% | |
704 | ]]) | |
705 | ||
b56471a6 | 706 | AT_CHECK([bison -v -o input.c input.y]) |
b9752825 AD |
707 | |
708 | # Check only the tables. We don't use --no-parser, because it is | |
709 | # still to be implemented in the experimental branch of Bison. | |
ce4ccb4b AD |
710 | [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] |
711 | ||
712 | AT_CHECK([[cat tables.c]], 0, | |
d42cf844 | 713 | [[static const yytype_uint8 yytranslate[] = |
b9752825 AD |
714 | { |
715 | 0, 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, | |
739 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
007a50a4 AD |
740 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
741 | 5, 6 | |
b9752825 | 742 | }; |
d42cf844 | 743 | static const yytype_uint8 yyprhs[] = |
b9752825 | 744 | { |
e7b8bef1 | 745 | 0, 0, 3, 5, 6, 9, 14 |
b9752825 | 746 | }; |
d42cf844 | 747 | static const yytype_int8 yyrhs[] = |
b9752825 | 748 | { |
e7b8bef1 AD |
749 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, |
750 | 4, 5, 8, -1, 6, 8, -1 | |
b9752825 | 751 | }; |
d42cf844 | 752 | static const yytype_uint8 yyrline[] = |
b9752825 | 753 | { |
e7b8bef1 | 754 | 0, 2, 2, 3, 3, 4, 5 |
b9752825 AD |
755 | }; |
756 | static const char *const yytname[] = | |
757 | { | |
9e0876fb PE |
758 | "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"", |
759 | "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0 | |
b9752825 | 760 | }; |
d42cf844 | 761 | static const yytype_uint16 yytoknum[] = |
b9752825 | 762 | { |
3650b4b8 | 763 | 0, 256, 257, 258, 259, 260, 261 |
b9752825 | 764 | }; |
d42cf844 | 765 | static const yytype_uint8 yyr1[] = |
b9752825 | 766 | { |
e7b8bef1 | 767 | 0, 7, 8, 9, 9, 10, 11 |
b9752825 | 768 | }; |
d42cf844 | 769 | static const yytype_uint8 yyr2[] = |
b9752825 | 770 | { |
e7b8bef1 | 771 | 0, 2, 1, 0, 2, 4, 2 |
b9752825 | 772 | }; |
d42cf844 | 773 | static const yytype_uint8 yydefact[] = |
b9752825 | 774 | { |
e8832397 | 775 | 3, 0, 0, 2, 0, 0, 1, 3, 4, 3, |
e7b8bef1 | 776 | 6, 5 |
b9752825 | 777 | }; |
d42cf844 | 778 | static const yytype_int8 yydefgoto[] = |
b9752825 | 779 | { |
e7b8bef1 | 780 | -1, 2, 3, 4, 8 |
b9752825 | 781 | }; |
d42cf844 | 782 | static const yytype_int8 yypact[] = |
b9752825 | 783 | { |
12b0043a AD |
784 | -2, -1, 4, -8, 0, 2, -8, -2, -8, -2, |
785 | -8, -8 | |
b9752825 | 786 | }; |
d42cf844 | 787 | static const yytype_int8 yypgoto[] = |
b9752825 | 788 | { |
12b0043a | 789 | -8, -7, -8, -8, -8 |
b9752825 | 790 | }; |
d42cf844 | 791 | static const yytype_uint8 yytable[] = |
b9752825 | 792 | { |
e7b8bef1 | 793 | 10, 1, 11, 5, 6, 0, 7, 9 |
b9752825 | 794 | }; |
d42cf844 | 795 | static const yytype_int8 yycheck[] = |
b9752825 | 796 | { |
e7b8bef1 | 797 | 7, 3, 9, 4, 0, -1, 6, 5 |
b9752825 | 798 | }; |
d42cf844 | 799 | static const yytype_uint8 yystos[] = |
5504898e AD |
800 | { |
801 | 0, 3, 8, 9, 10, 4, 0, 6, 11, 5, | |
802 | 8, 8 | |
803 | }; | |
b9752825 AD |
804 | ]]) |
805 | ||
806 | AT_CLEANUP | |
22e304a6 AD |
807 | |
808 | ||
809 | ## ------------------------- ## | |
810 | ## yycheck Bound Violation. ## | |
811 | ## ------------------------- ## | |
812 | ||
813 | ||
814 | # _AT_DATA_DANCER_Y(BISON-OPTIONS) | |
815 | # -------------------------------- | |
816 | # The following grammar, taken from Andrew Suffield's GPL'd implementation | |
817 | # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate | |
818 | # yycheck's bounds where issuing a verbose error message. Keep this test | |
819 | # so that possible bound checking compilers could check all the skeletons. | |
820 | m4_define([_AT_DATA_DANCER_Y], | |
821 | [AT_DATA_GRAMMAR([dancer.y], | |
822 | [%{ | |
848dc439 PE |
823 | static int yylex (AT_LALR1_CC_IF([int *], [void])); |
824 | AT_LALR1_CC_IF([], | |
22e304a6 | 825 | [#include <stdio.h> |
848dc439 | 826 | static void yyerror (const char *);]) |
22e304a6 AD |
827 | %} |
828 | $1 | |
829 | %token ARROW INVALID NUMBER STRING DATA | |
830 | %defines | |
831 | %verbose | |
832 | %error-verbose | |
833 | /* Grammar follows */ | |
834 | %% | |
835 | line: header body | |
836 | ; | |
837 | ||
838 | header: '<' from ARROW to '>' type ':' | |
839 | | '<' ARROW to '>' type ':' | |
840 | | ARROW to type ':' | |
841 | | type ':' | |
842 | | '<' '>' | |
843 | ; | |
844 | ||
845 | from: DATA | |
846 | | STRING | |
847 | | INVALID | |
848 | ; | |
849 | ||
850 | to: DATA | |
851 | | STRING | |
852 | | INVALID | |
853 | ; | |
854 | ||
855 | type: DATA | |
856 | | STRING | |
857 | | INVALID | |
858 | ; | |
859 | ||
860 | body: /* empty */ | |
861 | | body member | |
862 | ; | |
863 | ||
864 | member: STRING | |
865 | | DATA | |
866 | | '+' NUMBER | |
867 | | '-' NUMBER | |
868 | | NUMBER | |
869 | | INVALID | |
870 | ; | |
871 | %% | |
872 | AT_LALR1_CC_IF( | |
68e11668 | 873 | [/* A C++ error reporting function. */ |
22e304a6 | 874 | void |
99880de5 | 875 | yy::parser::error (const location&, const std::string& m) |
22e304a6 | 876 | { |
efeed023 | 877 | std::cerr << m << std::endl; |
22e304a6 AD |
878 | } |
879 | ||
880 | int | |
99880de5 | 881 | yyparse () |
22e304a6 | 882 | { |
99880de5 | 883 | yy::parser parser; |
a3cb6248 | 884 | parser.set_debug_level (!!YYDEBUG); |
22e304a6 AD |
885 | return parser.parse (); |
886 | } | |
887 | ], | |
888 | [static void | |
889 | yyerror (const char *s) | |
890 | { | |
891 | fprintf (stderr, "%s\n", s); | |
892 | }]) | |
893 | ||
894 | static int | |
848dc439 | 895 | yylex (AT_LALR1_CC_IF([int *lval], [void])) |
22e304a6 AD |
896 | [{ |
897 | static int toknum = 0; | |
d6645148 | 898 | static int tokens[] = |
22e304a6 AD |
899 | { |
900 | ':', -1 | |
901 | }; | |
848dc439 | 902 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
22e304a6 AD |
903 | return tokens[toknum++]; |
904 | }] | |
905 | ||
906 | int | |
907 | main (void) | |
908 | { | |
909 | return yyparse (); | |
910 | } | |
911 | ]) | |
912 | ])# _AT_DATA_DANCER_Y | |
913 | ||
914 | ||
915 | # AT_CHECK_DANCER(BISON-OPTIONS) | |
916 | # ------------------------------ | |
917 | # Generate the grammar, compile it, run it. | |
918 | m4_define([AT_CHECK_DANCER], | |
919 | [AT_SETUP([Dancer $1]) | |
920 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
921 | _AT_DATA_DANCER_Y([$1]) | |
922 | AT_CHECK([bison -o dancer.c dancer.y]) | |
07971983 PE |
923 | AT_LALR1_CC_IF( |
924 | [AT_CHECK([bison -o dancer.cc dancer.y]) | |
925 | AT_COMPILE_CXX([dancer])], | |
926 | [AT_CHECK([bison -o dancer.c dancer.y]) | |
927 | AT_COMPILE([dancer])]) | |
22e304a6 | 928 | AT_PARSER_CHECK([./dancer], 1, [], |
d5286af1 | 929 | [syntax error, unexpected ':' |
22e304a6 AD |
930 | ]) |
931 | AT_BISON_OPTION_POPDEFS | |
932 | AT_CLEANUP | |
933 | ]) | |
934 | ||
935 | AT_CHECK_DANCER() | |
936 | AT_CHECK_DANCER([%glr-parser]) | |
937 | AT_CHECK_DANCER([%skeleton "lalr1.cc"]) | |
d6645148 PE |
938 | |
939 | ||
940 | ## ------------------------------------------ ## | |
941 | ## Diagnostic that expects two alternatives. ## | |
942 | ## ------------------------------------------ ## | |
943 | ||
944 | ||
945 | # _AT_DATA_EXPECT2_Y(BISON-OPTIONS) | |
946 | # -------------------------------- | |
947 | m4_define([_AT_DATA_EXPECT2_Y], | |
948 | [AT_DATA_GRAMMAR([expect2.y], | |
949 | [%{ | |
950 | static int yylex (AT_LALR1_CC_IF([int *], [void])); | |
951 | AT_LALR1_CC_IF([], | |
952 | [#include <stdio.h> | |
953 | static void yyerror (const char *);]) | |
954 | %} | |
955 | $1 | |
956 | %defines | |
957 | %error-verbose | |
958 | %token A 1000 | |
959 | %token B | |
960 | ||
961 | %% | |
962 | program: /* empty */ | |
963 | | program e ';' | |
964 | | program error ';'; | |
965 | ||
966 | e: e '+' t | t; | |
967 | t: A | B; | |
968 | ||
969 | %% | |
970 | AT_LALR1_CC_IF( | |
971 | [/* A C++ error reporting function. */ | |
972 | void | |
973 | yy::parser::error (const location&, const std::string& m) | |
974 | { | |
975 | std::cerr << m << std::endl; | |
976 | } | |
977 | ||
978 | int | |
979 | yyparse () | |
980 | { | |
981 | yy::parser parser; | |
982 | return parser.parse (); | |
983 | } | |
984 | ], | |
985 | [static void | |
986 | yyerror (const char *s) | |
987 | { | |
988 | fprintf (stderr, "%s\n", s); | |
989 | }]) | |
990 | ||
991 | static int | |
992 | yylex (AT_LALR1_CC_IF([int *lval], [void])) | |
993 | [{ | |
994 | static int toknum = 0; | |
995 | static int tokens[] = | |
996 | { | |
997 | 1000, '+', '+', -1 | |
998 | }; | |
999 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ | |
1000 | return tokens[toknum++]; | |
1001 | }] | |
1002 | ||
1003 | int | |
1004 | main (void) | |
1005 | { | |
1006 | return yyparse (); | |
1007 | } | |
1008 | ]) | |
1009 | ])# _AT_DATA_EXPECT2_Y | |
1010 | ||
1011 | ||
1012 | # AT_CHECK_EXPECT2(BISON-OPTIONS) | |
1013 | # ------------------------------ | |
1014 | # Generate the grammar, compile it, run it. | |
1015 | m4_define([AT_CHECK_EXPECT2], | |
1016 | [AT_SETUP([Expecting two tokens $1]) | |
1017 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
1018 | _AT_DATA_EXPECT2_Y([$1]) | |
1019 | AT_CHECK([bison -o expect2.c expect2.y]) | |
1020 | AT_LALR1_CC_IF( | |
1021 | [AT_CHECK([bison -o expect2.cc expect2.y]) | |
1022 | AT_COMPILE_CXX([expect2])], | |
1023 | [AT_CHECK([bison -o expect2.c expect2.y]) | |
1024 | AT_COMPILE([expect2])]) | |
1025 | AT_PARSER_CHECK([./expect2], 1, [], | |
1026 | [syntax error, unexpected '+', expecting A or B | |
1027 | ]) | |
1028 | AT_BISON_OPTION_POPDEFS | |
1029 | AT_CLEANUP | |
1030 | ]) | |
1031 | ||
1032 | AT_CHECK_EXPECT2() | |
1033 | AT_CHECK_EXPECT2([%glr-parser]) | |
1034 | AT_CHECK_EXPECT2([%skeleton "lalr1.cc"]) | |
4210cd0b JD |
1035 | |
1036 | ||
1037 | ||
1038 | ## --------------------------------------------- ## | |
1039 | ## Braced code in declaration in rules section. ## | |
1040 | ## --------------------------------------------- ## | |
1041 | ||
1042 | AT_SETUP([Braced code in declaration in rules section]) | |
1043 | ||
1044 | # Bison once mistook braced code in a declaration in the rules section to be a | |
1045 | # rule action. | |
1046 | ||
1047 | AT_DATA_GRAMMAR([input.y], | |
1048 | [[%{ | |
1049 | #include <stdio.h> | |
381ecb06 JD |
1050 | static void yyerror (char const *msg); |
1051 | static int yylex (void); | |
4210cd0b JD |
1052 | %} |
1053 | ||
1054 | %error-verbose | |
1055 | ||
1056 | %% | |
1057 | ||
1058 | start: | |
1059 | { | |
1060 | printf ("Bison would once convert this action to a midrule because of the" | |
1061 | " subsequent braced code.\n"); | |
1062 | } | |
1063 | ; | |
1064 | ||
1065 | %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a'; | |
1066 | %printer { fprintf (yyoutput, "PRINTER"); } 'a'; | |
1067 | ||
1068 | %% | |
1069 | ||
381ecb06 | 1070 | static void |
4210cd0b JD |
1071 | yyerror (char const *msg) |
1072 | { | |
1073 | fprintf (stderr, "%s\n", msg); | |
1074 | } | |
1075 | ||
381ecb06 | 1076 | static int |
4210cd0b JD |
1077 | yylex (void) |
1078 | { | |
1079 | return 'a'; | |
1080 | } | |
1081 | ||
1082 | int | |
1083 | main (void) | |
1084 | { | |
1085 | yydebug = 1; | |
1086 | return !yyparse (); | |
1087 | } | |
1088 | ]]) | |
1089 | ||
1090 | AT_CHECK([bison -t -o input.c input.y]) | |
1091 | AT_COMPILE([input]) | |
1092 | AT_PARSER_CHECK([./input], 0, | |
1093 | [[Bison would once convert this action to a midrule because of the subsequent braced code. | |
1094 | ]], | |
1095 | [[Starting parse | |
1096 | Entering state 0 | |
1097 | Reducing stack by rule 1 (line 22): | |
1098 | -> $$ = nterm start () | |
1099 | Stack now 0 | |
1100 | Entering state 1 | |
1101 | Reading a token: Next token is token 'a' (PRINTER) | |
1102 | syntax error, unexpected 'a', expecting $end | |
1103 | Error: popping nterm start () | |
1104 | Stack now 0 | |
1105 | Cleanup: discarding lookahead token 'a' (PRINTER) | |
1106 | DESTRUCTOR | |
1107 | Stack now 0 | |
1108 | ]]) | |
1109 | ||
1110 | AT_CLEANUP |