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