]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Bison Regressions. -*- Autotest -*- |
d42cf844 | 2 | |
1462fcee | 3 | # Copyright (C) 2001-2010 Free Software Foundation, Inc. |
c95f2d78 | 4 | |
f16b0819 | 5 | # This program is free software: you can redistribute it and/or modify |
342b8b6e | 6 | # it under the terms of the GNU General Public License as published by |
f16b0819 PE |
7 | # the Free Software Foundation, either version 3 of the License, or |
8 | # (at your option) any later version. | |
9 | # | |
342b8b6e AD |
10 | # This program is distributed in the hope that it will be useful, |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. | |
f16b0819 | 14 | # |
342b8b6e | 15 | # You should have received a copy of the GNU General Public License |
f16b0819 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c95f2d78 | 17 | |
342b8b6e | 18 | AT_BANNER([[Regression tests.]]) |
c95f2d78 | 19 | |
2b25d624 | 20 | |
276f48df PE |
21 | ## ------------------ ## |
22 | ## Trivial grammars. ## | |
23 | ## ------------------ ## | |
24 | ||
25 | AT_SETUP([Trivial grammars]) | |
26 | ||
27 | AT_DATA_GRAMMAR([input.y], | |
28 | [[%{ | |
29 | void yyerror (char const *); | |
30 | int yylex (void); | |
50cce58e | 31 | #define YYSTYPE int * |
276f48df PE |
32 | %} |
33 | ||
34 | %error-verbose | |
35 | ||
36 | %% | |
37 | ||
38 | program: 'x'; | |
39 | ]]) | |
40 | ||
da730230 | 41 | AT_BISON_CHECK([-o input.c input.y]) |
276f48df | 42 | AT_COMPILE([input.o], [-c input.c]) |
50cce58e | 43 | AT_COMPILE([input.o], [-DYYDEBUG -c input.c]) |
276f48df PE |
44 | |
45 | AT_CLEANUP | |
46 | ||
47 | ||
48 | ||
ddc8ede1 PE |
49 | ## ----------------- ## |
50 | ## YYSTYPE typedef. ## | |
51 | ## ----------------- ## | |
52 | ||
53 | AT_SETUP([YYSTYPE typedef]) | |
54 | ||
55 | AT_DATA_GRAMMAR([input.y], | |
56 | [[%{ | |
57 | void yyerror (char const *); | |
58 | int yylex (void); | |
59 | typedef union { char const *val; } YYSTYPE; | |
60 | %} | |
61 | ||
62 | %type <val> program | |
63 | ||
64 | %% | |
65 | ||
66 | program: { $$ = ""; }; | |
67 | ]]) | |
68 | ||
da730230 | 69 | AT_BISON_CHECK([-o input.c input.y]) |
ddc8ede1 PE |
70 | AT_COMPILE([input.o], [-c input.c]) |
71 | ||
72 | AT_CLEANUP | |
73 | ||
74 | ||
75 | ||
b931235e JD |
76 | ## ------------------------------------- ## |
77 | ## Early token definitions with --yacc. ## | |
78 | ## ------------------------------------- ## | |
69078d4b AD |
79 | |
80 | ||
b931235e | 81 | AT_SETUP([Early token definitions with --yacc]) |
69078d4b AD |
82 | |
83 | # Found in GCJ: they expect the tokens to be defined before the user | |
84 | # prologue, so that they can use the token definitions in it. | |
85 | ||
9501dc6e | 86 | AT_DATA_GRAMMAR([input.y], |
69078d4b AD |
87 | [[%{ |
88 | void yyerror (const char *s); | |
89 | int yylex (void); | |
90 | %} | |
91 | ||
92 | %union | |
93 | { | |
94 | int val; | |
95 | }; | |
9bc0dd67 JD |
96 | %{ |
97 | #ifndef MY_TOKEN | |
98 | # error "MY_TOKEN not defined." | |
99 | #endif | |
100 | %} | |
b931235e JD |
101 | %token MY_TOKEN |
102 | %% | |
103 | exp: MY_TOKEN; | |
104 | %% | |
105 | ]]) | |
106 | ||
da730230 | 107 | AT_BISON_CHECK([-y -o input.c input.y]) |
b931235e JD |
108 | AT_COMPILE([input.o], [-c input.c]) |
109 | ||
110 | AT_CLEANUP | |
111 | ||
112 | ||
113 | ||
114 | ## ---------------------------------------- ## | |
115 | ## Early token definitions without --yacc. ## | |
116 | ## ---------------------------------------- ## | |
117 | ||
118 | ||
119 | AT_SETUP([Early token definitions without --yacc]) | |
120 | ||
121 | # Found in GCJ: they expect the tokens to be defined before the user | |
122 | # prologue, so that they can use the token definitions in it. | |
123 | ||
124 | AT_DATA_GRAMMAR([input.y], | |
125 | [[%{ | |
126 | #include <stdio.h> | |
127 | void yyerror (const char *s); | |
128 | int yylex (void); | |
129 | void print_my_token (void); | |
9bc0dd67 JD |
130 | %} |
131 | ||
132 | %union | |
133 | { | |
134 | int val; | |
135 | }; | |
136 | %{ | |
b931235e JD |
137 | void |
138 | print_my_token (void) | |
139 | { | |
140 | enum yytokentype my_token = MY_TOKEN; | |
141 | printf ("%d\n", my_token); | |
142 | } | |
69078d4b AD |
143 | %} |
144 | %token MY_TOKEN | |
145 | %% | |
146 | exp: MY_TOKEN; | |
147 | %% | |
148 | ]]) | |
149 | ||
da730230 | 150 | AT_BISON_CHECK([-o input.c input.y]) |
002b9b7d | 151 | AT_COMPILE([input.o], [-c input.c]) |
69078d4b AD |
152 | |
153 | AT_CLEANUP | |
154 | ||
155 | ||
156 | ||
2b25d624 AD |
157 | ## ---------------- ## |
158 | ## Braces parsing. ## | |
159 | ## ---------------- ## | |
160 | ||
161 | ||
69078d4b | 162 | AT_SETUP([Braces parsing]) |
2b25d624 AD |
163 | |
164 | AT_DATA([input.y], | |
165 | [[/* Bison used to swallow the character after `}'. */ | |
166 | ||
167 | %% | |
bfcf1f3a | 168 | exp: { tests = {{{{{{{{{{}}}}}}}}}}; }; |
2b25d624 AD |
169 | %% |
170 | ]]) | |
171 | ||
da730230 | 172 | AT_BISON_CHECK([-v -o input.c input.y]) |
2b25d624 | 173 | |
a4bf0390 | 174 | AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore]) |
2b25d624 AD |
175 | |
176 | AT_CLEANUP | |
177 | ||
178 | ||
c95f2d78 AD |
179 | ## ------------------ ## |
180 | ## Duplicate string. ## | |
181 | ## ------------------ ## | |
182 | ||
183 | ||
184 | AT_SETUP([Duplicate string]) | |
185 | ||
f499b062 | 186 | AT_DATA([input.y], |
c95f2d78 AD |
187 | [[/* `Bison -v' used to dump core when two tokens are defined with the same |
188 | string, as LE and GE below. */ | |
189 | ||
190 | %token NUM | |
191 | %token LE "<=" | |
192 | %token GE "<=" | |
193 | ||
194 | %% | |
195 | exp: '(' exp ')' | NUM ; | |
196 | %% | |
197 | ]]) | |
198 | ||
da730230 | 199 | AT_BISON_CHECK([-v -o input.c input.y], 0, [], |
a5d50994 | 200 | [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string |
69078d4b | 201 | ]]) |
c95f2d78 | 202 | |
d803322e | 203 | AT_CLEANUP |
c95f2d78 AD |
204 | |
205 | ||
2ca209c1 AD |
206 | ## ------------------- ## |
207 | ## Rule Line Numbers. ## | |
208 | ## ------------------- ## | |
209 | ||
210 | AT_SETUP([Rule Line Numbers]) | |
211 | ||
6b98e4b5 AD |
212 | AT_KEYWORDS([report]) |
213 | ||
2ca209c1 AD |
214 | AT_DATA([input.y], |
215 | [[%% | |
216 | expr: | |
217 | 'a' | |
218 | ||
219 | { | |
220 | ||
221 | } | |
222 | ||
223 | 'b' | |
224 | ||
225 | { | |
226 | ||
227 | } | |
228 | ||
229 | | | |
230 | ||
231 | ||
232 | { | |
233 | ||
234 | ||
235 | } | |
236 | ||
237 | 'c' | |
238 | ||
239 | { | |
240 | ||
bfcf1f3a | 241 | }; |
2ca209c1 AD |
242 | ]]) |
243 | ||
da730230 | 244 | AT_BISON_CHECK([-o input.c -v input.y]) |
2ca209c1 AD |
245 | |
246 | # Check the contents of the report. | |
247 | AT_CHECK([cat input.output], [], | |
d2d1b42b | 248 | [[Grammar |
2ca209c1 | 249 | |
88bce5a2 | 250 | 0 $accept: expr $end |
6b98e4b5 | 251 | |
f91b1629 | 252 | 1 $@1: /* empty */ |
6b98e4b5 | 253 | |
f91b1629 | 254 | 2 expr: 'a' $@1 'b' |
6b98e4b5 | 255 | |
f91b1629 | 256 | 3 $@2: /* empty */ |
6b98e4b5 | 257 | |
f91b1629 | 258 | 4 expr: $@2 'c' |
2ca209c1 | 259 | |
d2d1b42b | 260 | |
2ca209c1 AD |
261 | Terminals, with rules where they appear |
262 | ||
88bce5a2 | 263 | $end (0) 0 |
2ca209c1 AD |
264 | 'a' (97) 2 |
265 | 'b' (98) 2 | |
266 | 'c' (99) 4 | |
267 | error (256) | |
268 | ||
d2d1b42b | 269 | |
2ca209c1 AD |
270 | Nonterminals, with rules where they appear |
271 | ||
88bce5a2 | 272 | $accept (6) |
b365aa05 AD |
273 | on left: 0 |
274 | expr (7) | |
275 | on left: 2 4, on right: 0 | |
f91b1629 | 276 | $@1 (8) |
2ca209c1 | 277 | on left: 1, on right: 2 |
f91b1629 | 278 | $@2 (9) |
2ca209c1 AD |
279 | on left: 3, on right: 4 |
280 | ||
281 | ||
282 | state 0 | |
283 | ||
88bce5a2 | 284 | 0 $accept: . expr $end |
643a5994 | 285 | |
87675353 | 286 | 'a' shift, and go to state 1 |
2ca209c1 | 287 | |
f91b1629 | 288 | $default reduce using rule 3 ($@2) |
2ca209c1 | 289 | |
87675353 | 290 | expr go to state 2 |
f91b1629 | 291 | $@2 go to state 3 |
2ca209c1 AD |
292 | |
293 | ||
294 | state 1 | |
295 | ||
f91b1629 | 296 | 2 expr: 'a' . $@1 'b' |
2ca209c1 | 297 | |
f91b1629 | 298 | $default reduce using rule 1 ($@1) |
2ca209c1 | 299 | |
f91b1629 | 300 | $@1 go to state 4 |
2ca209c1 AD |
301 | |
302 | ||
303 | state 2 | |
304 | ||
88bce5a2 | 305 | 0 $accept: expr . $end |
2ca209c1 | 306 | |
88bce5a2 | 307 | $end shift, and go to state 5 |
2ca209c1 AD |
308 | |
309 | ||
310 | state 3 | |
311 | ||
f91b1629 | 312 | 4 expr: $@2 . 'c' |
2ca209c1 | 313 | |
87675353 | 314 | 'c' shift, and go to state 6 |
2ca209c1 AD |
315 | |
316 | ||
317 | state 4 | |
318 | ||
f91b1629 | 319 | 2 expr: 'a' $@1 . 'b' |
2ca209c1 | 320 | |
87675353 | 321 | 'b' shift, and go to state 7 |
2ca209c1 AD |
322 | |
323 | ||
324 | state 5 | |
325 | ||
88bce5a2 | 326 | 0 $accept: expr $end . |
2ca209c1 | 327 | |
e8832397 | 328 | $default accept |
2ca209c1 AD |
329 | |
330 | ||
331 | state 6 | |
332 | ||
f91b1629 | 333 | 4 expr: $@2 'c' . |
b365aa05 | 334 | |
87675353 | 335 | $default reduce using rule 4 (expr) |
2ca209c1 AD |
336 | |
337 | ||
338 | state 7 | |
339 | ||
f91b1629 | 340 | 2 expr: 'a' $@1 'b' . |
b365aa05 | 341 | |
87675353 | 342 | $default reduce using rule 2 (expr) |
2ca209c1 AD |
343 | ]]) |
344 | ||
345 | AT_CLEANUP | |
346 | ||
347 | ||
348 | ||
cd5aafcf AD |
349 | ## ---------------------- ## |
350 | ## Mixing %token styles. ## | |
351 | ## ---------------------- ## | |
352 | ||
353 | ||
354 | AT_SETUP([Mixing %token styles]) | |
355 | ||
356 | # Taken from the documentation. | |
357 | AT_DATA([input.y], | |
358 | [[%token <operator> OR "||" | |
359 | %token <operator> LE 134 "<=" | |
360 | %left OR "<=" | |
361 | %% | |
362 | exp: ; | |
363 | %% | |
364 | ]]) | |
365 | ||
da730230 | 366 | AT_BISON_CHECK([-v -o input.c input.y]) |
cd5aafcf | 367 | |
d803322e | 368 | AT_CLEANUP |
cd5aafcf AD |
369 | |
370 | ||
371 | ||
29ae55f1 AD |
372 | ## ---------------- ## |
373 | ## Invalid inputs. ## | |
374 | ## ---------------- ## | |
561f9a30 AD |
375 | |
376 | ||
29ae55f1 | 377 | AT_SETUP([Invalid inputs]) |
561f9a30 AD |
378 | |
379 | AT_DATA([input.y], | |
380 | [[%% | |
381 | ? | |
561f9a30 | 382 | default: 'a' } |
29ae55f1 | 383 | %& |
2dfbfc12 | 384 | %a-does-not-exist |
29ae55f1 | 385 | %- |
e9955c83 | 386 | %{ |
561f9a30 AD |
387 | ]]) |
388 | ||
da730230 | 389 | AT_BISON_CHECK([input.y], [1], [], |
e9955c83 AD |
390 | [[input.y:2.1: invalid character: `?' |
391 | input.y:3.14: invalid character: `}' | |
392 | input.y:4.1: invalid character: `%' | |
393 | input.y:4.2: invalid character: `&' | |
2dfbfc12 | 394 | input.y:5.1-17: invalid directive: `%a-does-not-exist' |
c046698e | 395 | input.y:6.1-2: invalid directive: `%-' |
2115939b | 396 | input.y:7.1-8.0: missing `%}' at end of file |
47aee066 | 397 | input.y:7.1-8.0: syntax error, unexpected %{...%} |
e0c40012 | 398 | ]]) |
561f9a30 AD |
399 | |
400 | AT_CLEANUP | |
401 | ||
402 | ||
fc01665e PE |
403 | AT_SETUP([Invalid inputs with {}]) |
404 | ||
405 | AT_DATA([input.y], | |
406 | [[ | |
407 | %destructor | |
408 | %initial-action | |
409 | %lex-param | |
410 | %parse-param | |
411 | %printer | |
412 | %union | |
413 | ]]) | |
414 | ||
da730230 | 415 | AT_BISON_CHECK([input.y], [1], [], |
e9071366 | 416 | [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...} |
fc01665e PE |
417 | ]]) |
418 | ||
419 | AT_CLEANUP | |
420 | ||
421 | ||
270a173c | 422 | |
b87f8b21 AD |
423 | ## ------------------- ## |
424 | ## Token definitions. ## | |
425 | ## ------------------- ## | |
426 | ||
427 | ||
428 | AT_SETUP([Token definitions]) | |
429 | ||
430 | # Bison managed, when fed with `%token 'f' "f"' to #define 'f'! | |
9501dc6e | 431 | AT_DATA_GRAMMAR([input.y], |
db7c8e9a | 432 | [%{ |
cf806753 | 433 | #include <stdlib.h> |
ca407bdf | 434 | #include <stdio.h> |
db7c8e9a AD |
435 | void yyerror (const char *s); |
436 | int yylex (void); | |
437 | %} | |
ca407bdf PE |
438 | [%error-verbose |
439 | %token MYEOF 0 "end of file" | |
b87f8b21 | 440 | %token 'a' "a" |
4f136612 PE |
441 | %token B_TOKEN "b" |
442 | %token C_TOKEN 'c' | |
443 | %token 'd' D_TOKEN | |
3d54b576 | 444 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" |
1cfe6375 | 445 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" |
b87f8b21 | 446 | %% |
3d54b576 | 447 | exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"; |
ca407bdf PE |
448 | %% |
449 | void | |
450 | yyerror (char const *s) | |
451 | { | |
452 | fprintf (stderr, "%s\n", s); | |
453 | } | |
454 | ||
455 | int | |
456 | yylex (void) | |
457 | { | |
cf806753 PE |
458 | static int called; |
459 | if (called++) | |
460 | abort (); | |
ca407bdf PE |
461 | return SPECIAL; |
462 | } | |
463 | ||
464 | int | |
465 | main (void) | |
466 | { | |
467 | return yyparse (); | |
468 | } | |
b87f8b21 AD |
469 | ]]) |
470 | ||
1cfe6375 JD |
471 | # Checking the warning message guarantees that the trigraph "??!" isn't |
472 | # unnecessarily escaped here even though it would need to be if encoded in a | |
473 | # C-string literal. Also notice that unnecessary escaping, such as "\?", from | |
474 | # the user specification is eliminated. | |
475 | AT_BISON_CHECK([-o input.c input.y], [[0]], [[]], | |
476 | [[input.y:22.8-14: warning: symbol SPECIAL redeclared | |
477 | input.y:22.8-63: warning: symbol `"\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!"' used more than once as a literal string | |
478 | ]]) | |
ca407bdf | 479 | AT_COMPILE([input]) |
1cfe6375 JD |
480 | |
481 | # Checking the error message here guarantees that yytname, which does contain | |
482 | # C-string literals, does have the trigraph escaped correctly. Thus, the | |
483 | # symbol name reported by the parser is exactly the same as that reported by | |
484 | # Bison itself. | |
3d54b576 | 485 | AT_DATA([experr], |
1cfe6375 | 486 | [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a |
3d54b576 PE |
487 | ]]) |
488 | AT_PARSER_CHECK([./input], 1, [], [experr]) | |
b87f8b21 AD |
489 | AT_CLEANUP |
490 | ||
491 | ||
492 | ||
eb714592 AD |
493 | ## -------------------- ## |
494 | ## Characters Escapes. ## | |
495 | ## -------------------- ## | |
496 | ||
497 | ||
498 | AT_SETUP([Characters Escapes]) | |
499 | ||
9501dc6e | 500 | AT_DATA_GRAMMAR([input.y], |
eb714592 AD |
501 | [%{ |
502 | void yyerror (const char *s); | |
503 | int yylex (void); | |
504 | %} | |
6d0ef4ec | 505 | [%% |
eb714592 AD |
506 | exp: |
507 | '\'' "\'" | |
508 | | '\"' "\"" | |
509 | | '"' "'" | |
510 | ; | |
511 | ]]) | |
9501dc6e | 512 | # Pacify font-lock-mode: " |
eb714592 | 513 | |
da730230 | 514 | AT_BISON_CHECK([-o input.c input.y]) |
eb714592 AD |
515 | AT_COMPILE([input.o], [-c input.c]) |
516 | AT_CLEANUP | |
517 | ||
518 | ||
519 | ||
b9752825 AD |
520 | ## -------------- ## |
521 | ## Web2c Report. ## | |
522 | ## -------------- ## | |
776209d6 AD |
523 | |
524 | # The generation of the reduction was once wrong in Bison, and made it | |
525 | # miss some reductions. In the following test case, the reduction on | |
526 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
527 | # the actual web2c.y. | |
528 | ||
b9752825 | 529 | AT_SETUP([Web2c Report]) |
776209d6 | 530 | |
6b98e4b5 AD |
531 | AT_KEYWORDS([report]) |
532 | ||
776209d6 AD |
533 | AT_DATA([input.y], |
534 | [[%token undef_id_tok const_id_tok | |
535 | ||
536 | %start CONST_DEC_PART | |
537 | \f | |
538 | %% | |
539 | CONST_DEC_PART: | |
540 | CONST_DEC_LIST | |
541 | ; | |
542 | ||
543 | CONST_DEC_LIST: | |
544 | CONST_DEC | |
545 | | CONST_DEC_LIST CONST_DEC | |
546 | ; | |
547 | ||
548 | CONST_DEC: | |
549 | { } undef_id_tok '=' const_id_tok ';' | |
550 | ; | |
551 | %% | |
776209d6 AD |
552 | ]]) |
553 | ||
da730230 | 554 | AT_BISON_CHECK([-v input.y]) |
87675353 | 555 | AT_CHECK([cat input.output], 0, |
776209d6 | 556 | [[Grammar |
87675353 | 557 | |
88bce5a2 | 558 | 0 $accept: CONST_DEC_PART $end |
87675353 | 559 | |
6b98e4b5 | 560 | 1 CONST_DEC_PART: CONST_DEC_LIST |
87675353 | 561 | |
6b98e4b5 AD |
562 | 2 CONST_DEC_LIST: CONST_DEC |
563 | 3 | CONST_DEC_LIST CONST_DEC | |
87675353 | 564 | |
f91b1629 | 565 | 4 $@1: /* empty */ |
87675353 | 566 | |
f91b1629 | 567 | 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' |
87675353 AD |
568 | |
569 | ||
776209d6 | 570 | Terminals, with rules where they appear |
87675353 | 571 | |
88bce5a2 | 572 | $end (0) 0 |
776209d6 AD |
573 | ';' (59) 5 |
574 | '=' (61) 5 | |
575 | error (256) | |
007a50a4 AD |
576 | undef_id_tok (258) 5 |
577 | const_id_tok (259) 5 | |
87675353 AD |
578 | |
579 | ||
776209d6 | 580 | Nonterminals, with rules where they appear |
87675353 | 581 | |
88bce5a2 | 582 | $accept (7) |
78d5bae9 AD |
583 | on left: 0 |
584 | CONST_DEC_PART (8) | |
585 | on left: 1, on right: 0 | |
586 | CONST_DEC_LIST (9) | |
776209d6 | 587 | on left: 2 3, on right: 1 3 |
78d5bae9 | 588 | CONST_DEC (10) |
776209d6 | 589 | on left: 5, on right: 2 3 |
f91b1629 | 590 | $@1 (11) |
776209d6 | 591 | on left: 4, on right: 5 |
87675353 AD |
592 | |
593 | ||
776209d6 | 594 | state 0 |
87675353 | 595 | |
88bce5a2 | 596 | 0 $accept: . CONST_DEC_PART $end |
87675353 | 597 | |
f91b1629 | 598 | $default reduce using rule 4 ($@1) |
87675353 AD |
599 | |
600 | CONST_DEC_PART go to state 1 | |
601 | CONST_DEC_LIST go to state 2 | |
602 | CONST_DEC go to state 3 | |
f91b1629 | 603 | $@1 go to state 4 |
87675353 AD |
604 | |
605 | ||
776209d6 | 606 | state 1 |
87675353 | 607 | |
88bce5a2 | 608 | 0 $accept: CONST_DEC_PART . $end |
87675353 | 609 | |
88bce5a2 | 610 | $end shift, and go to state 5 |
87675353 AD |
611 | |
612 | ||
78d5bae9 | 613 | state 2 |
87675353 | 614 | |
ce4ccb4b AD |
615 | 1 CONST_DEC_PART: CONST_DEC_LIST . |
616 | 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC | |
87675353 | 617 | |
f91b1629 | 618 | undef_id_tok reduce using rule 4 ($@1) |
87675353 AD |
619 | $default reduce using rule 1 (CONST_DEC_PART) |
620 | ||
621 | CONST_DEC go to state 6 | |
f91b1629 | 622 | $@1 go to state 4 |
87675353 AD |
623 | |
624 | ||
78d5bae9 | 625 | state 3 |
87675353 | 626 | |
ce4ccb4b | 627 | 2 CONST_DEC_LIST: CONST_DEC . |
87675353 AD |
628 | |
629 | $default reduce using rule 2 (CONST_DEC_LIST) | |
630 | ||
631 | ||
776209d6 | 632 | state 4 |
87675353 | 633 | |
f91b1629 | 634 | 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';' |
87675353 AD |
635 | |
636 | undef_id_tok shift, and go to state 7 | |
637 | ||
638 | ||
78d5bae9 | 639 | state 5 |
87675353 | 640 | |
88bce5a2 | 641 | 0 $accept: CONST_DEC_PART $end . |
87675353 | 642 | |
e8832397 | 643 | $default accept |
87675353 AD |
644 | |
645 | ||
78d5bae9 | 646 | state 6 |
87675353 | 647 | |
ce4ccb4b | 648 | 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC . |
87675353 AD |
649 | |
650 | $default reduce using rule 3 (CONST_DEC_LIST) | |
651 | ||
652 | ||
78d5bae9 | 653 | state 7 |
87675353 | 654 | |
f91b1629 | 655 | 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';' |
87675353 AD |
656 | |
657 | '=' shift, and go to state 8 | |
658 | ||
659 | ||
78d5bae9 | 660 | state 8 |
87675353 | 661 | |
f91b1629 | 662 | 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';' |
87675353 AD |
663 | |
664 | const_id_tok shift, and go to state 9 | |
665 | ||
666 | ||
78d5bae9 | 667 | state 9 |
87675353 | 668 | |
f91b1629 | 669 | 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';' |
87675353 AD |
670 | |
671 | ';' shift, and go to state 10 | |
672 | ||
673 | ||
78d5bae9 | 674 | state 10 |
87675353 | 675 | |
f91b1629 | 676 | 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' . |
87675353 AD |
677 | |
678 | $default reduce using rule 5 (CONST_DEC) | |
776209d6 AD |
679 | ]]) |
680 | ||
681 | AT_CLEANUP | |
b9752825 AD |
682 | |
683 | ||
684 | ## --------------- ## | |
685 | ## Web2c Actions. ## | |
686 | ## --------------- ## | |
687 | ||
688 | # The generation of the mapping `state -> action' was once wrong in | |
689 | # extremely specific situations. web2c.y exhibits this situation. | |
690 | # Below is a stripped version of the grammar. It looks like one can | |
691 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
692 | # which disapears when applying sane grammar transformations. | |
693 | # | |
694 | # It used to be wrong on yydefact only: | |
695 | # | |
d42cf844 | 696 | # static const yytype_uint8 yydefact[] = |
b9752825 AD |
697 | # { |
698 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
699 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
700 | # 0, 0 | |
701 | # }; | |
702 | # | |
703 | # but let's check all the tables. | |
704 | ||
705 | ||
706 | AT_SETUP([Web2c Actions]) | |
707 | ||
6b98e4b5 AD |
708 | AT_KEYWORDS([report]) |
709 | ||
b9752825 AD |
710 | AT_DATA([input.y], |
711 | [[%% | |
712 | statement: struct_stat; | |
713 | struct_stat: /* empty. */ | if else; | |
714 | if: "if" "const" "then" statement; | |
715 | else: "else" statement; | |
716 | %% | |
717 | ]]) | |
718 | ||
da730230 | 719 | AT_BISON_CHECK([-v -o input.c input.y]) |
b9752825 | 720 | |
728c4be2 | 721 | # Check only the tables. |
ce4ccb4b AD |
722 | [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] |
723 | ||
724 | AT_CHECK([[cat tables.c]], 0, | |
d42cf844 | 725 | [[static const yytype_uint8 yytranslate[] = |
b9752825 AD |
726 | { |
727 | 0, 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, | |
740 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
741 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
742 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
743 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
744 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
745 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
746 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
747 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
748 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
749 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
750 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
751 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
007a50a4 AD |
752 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
753 | 5, 6 | |
b9752825 | 754 | }; |
d42cf844 | 755 | static const yytype_uint8 yyprhs[] = |
b9752825 | 756 | { |
e7b8bef1 | 757 | 0, 0, 3, 5, 6, 9, 14 |
b9752825 | 758 | }; |
d42cf844 | 759 | static const yytype_int8 yyrhs[] = |
b9752825 | 760 | { |
e7b8bef1 AD |
761 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, |
762 | 4, 5, 8, -1, 6, 8, -1 | |
b9752825 | 763 | }; |
d42cf844 | 764 | static const yytype_uint8 yyrline[] = |
b9752825 | 765 | { |
e7b8bef1 | 766 | 0, 2, 2, 3, 3, 4, 5 |
b9752825 AD |
767 | }; |
768 | static const char *const yytname[] = | |
769 | { | |
9e0876fb PE |
770 | "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"", |
771 | "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0 | |
b9752825 | 772 | }; |
d42cf844 | 773 | static const yytype_uint16 yytoknum[] = |
b9752825 | 774 | { |
3650b4b8 | 775 | 0, 256, 257, 258, 259, 260, 261 |
b9752825 | 776 | }; |
d42cf844 | 777 | static const yytype_uint8 yyr1[] = |
b9752825 | 778 | { |
e7b8bef1 | 779 | 0, 7, 8, 9, 9, 10, 11 |
b9752825 | 780 | }; |
d42cf844 | 781 | static const yytype_uint8 yyr2[] = |
b9752825 | 782 | { |
e7b8bef1 | 783 | 0, 2, 1, 0, 2, 4, 2 |
b9752825 | 784 | }; |
d42cf844 | 785 | static const yytype_uint8 yydefact[] = |
b9752825 | 786 | { |
e8832397 | 787 | 3, 0, 0, 2, 0, 0, 1, 3, 4, 3, |
e7b8bef1 | 788 | 6, 5 |
b9752825 | 789 | }; |
d42cf844 | 790 | static const yytype_int8 yydefgoto[] = |
b9752825 | 791 | { |
e7b8bef1 | 792 | -1, 2, 3, 4, 8 |
b9752825 | 793 | }; |
d42cf844 | 794 | static const yytype_int8 yypact[] = |
b9752825 | 795 | { |
12b0043a AD |
796 | -2, -1, 4, -8, 0, 2, -8, -2, -8, -2, |
797 | -8, -8 | |
b9752825 | 798 | }; |
d42cf844 | 799 | static const yytype_int8 yypgoto[] = |
b9752825 | 800 | { |
12b0043a | 801 | -8, -7, -8, -8, -8 |
b9752825 | 802 | }; |
d42cf844 | 803 | static const yytype_uint8 yytable[] = |
b9752825 | 804 | { |
e7b8bef1 | 805 | 10, 1, 11, 5, 6, 0, 7, 9 |
b9752825 | 806 | }; |
d42cf844 | 807 | static const yytype_int8 yycheck[] = |
b9752825 | 808 | { |
e7b8bef1 | 809 | 7, 3, 9, 4, 0, -1, 6, 5 |
b9752825 | 810 | }; |
d42cf844 | 811 | static const yytype_uint8 yystos[] = |
5504898e AD |
812 | { |
813 | 0, 3, 8, 9, 10, 4, 0, 6, 11, 5, | |
814 | 8, 8 | |
815 | }; | |
b9752825 AD |
816 | ]]) |
817 | ||
818 | AT_CLEANUP | |
22e304a6 AD |
819 | |
820 | ||
821 | ## ------------------------- ## | |
822 | ## yycheck Bound Violation. ## | |
823 | ## ------------------------- ## | |
824 | ||
825 | ||
826 | # _AT_DATA_DANCER_Y(BISON-OPTIONS) | |
827 | # -------------------------------- | |
828 | # The following grammar, taken from Andrew Suffield's GPL'd implementation | |
829 | # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate | |
830 | # yycheck's bounds where issuing a verbose error message. Keep this test | |
831 | # so that possible bound checking compilers could check all the skeletons. | |
832 | m4_define([_AT_DATA_DANCER_Y], | |
833 | [AT_DATA_GRAMMAR([dancer.y], | |
834 | [%{ | |
848dc439 PE |
835 | static int yylex (AT_LALR1_CC_IF([int *], [void])); |
836 | AT_LALR1_CC_IF([], | |
cf806753 PE |
837 | [#include <stdlib.h> |
838 | #include <stdio.h> | |
848dc439 | 839 | static void yyerror (const char *);]) |
22e304a6 AD |
840 | %} |
841 | $1 | |
842 | %token ARROW INVALID NUMBER STRING DATA | |
843 | %defines | |
844 | %verbose | |
845 | %error-verbose | |
846 | /* Grammar follows */ | |
847 | %% | |
848 | line: header body | |
849 | ; | |
850 | ||
851 | header: '<' from ARROW to '>' type ':' | |
852 | | '<' ARROW to '>' type ':' | |
853 | | ARROW to type ':' | |
854 | | type ':' | |
855 | | '<' '>' | |
856 | ; | |
857 | ||
858 | from: DATA | |
859 | | STRING | |
860 | | INVALID | |
861 | ; | |
862 | ||
863 | to: DATA | |
864 | | STRING | |
865 | | INVALID | |
866 | ; | |
867 | ||
868 | type: DATA | |
869 | | STRING | |
870 | | INVALID | |
871 | ; | |
872 | ||
873 | body: /* empty */ | |
874 | | body member | |
875 | ; | |
876 | ||
877 | member: STRING | |
878 | | DATA | |
879 | | '+' NUMBER | |
880 | | '-' NUMBER | |
881 | | NUMBER | |
882 | | INVALID | |
883 | ; | |
884 | %% | |
885 | AT_LALR1_CC_IF( | |
68e11668 | 886 | [/* A C++ error reporting function. */ |
22e304a6 | 887 | void |
99880de5 | 888 | yy::parser::error (const location&, const std::string& m) |
22e304a6 | 889 | { |
efeed023 | 890 | std::cerr << m << std::endl; |
22e304a6 AD |
891 | } |
892 | ||
893 | int | |
99880de5 | 894 | yyparse () |
22e304a6 | 895 | { |
99880de5 | 896 | yy::parser parser; |
fa7b79c0 PE |
897 | #if YYDEBUG |
898 | parser.set_debug_level (YYDEBUG); | |
899 | #endif | |
22e304a6 AD |
900 | return parser.parse (); |
901 | } | |
902 | ], | |
903 | [static void | |
904 | yyerror (const char *s) | |
905 | { | |
906 | fprintf (stderr, "%s\n", s); | |
907 | }]) | |
908 | ||
909 | static int | |
848dc439 | 910 | yylex (AT_LALR1_CC_IF([int *lval], [void])) |
22e304a6 | 911 | [{ |
cf806753 | 912 | static int const tokens[] = |
22e304a6 AD |
913 | { |
914 | ':', -1 | |
915 | }; | |
cf806753 | 916 | static size_t toknum; |
848dc439 | 917 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
cf806753 PE |
918 | if (! (toknum < sizeof tokens / sizeof *tokens)) |
919 | abort (); | |
22e304a6 AD |
920 | return tokens[toknum++]; |
921 | }] | |
922 | ||
923 | int | |
924 | main (void) | |
925 | { | |
926 | return yyparse (); | |
927 | } | |
928 | ]) | |
929 | ])# _AT_DATA_DANCER_Y | |
930 | ||
931 | ||
932 | # AT_CHECK_DANCER(BISON-OPTIONS) | |
933 | # ------------------------------ | |
934 | # Generate the grammar, compile it, run it. | |
935 | m4_define([AT_CHECK_DANCER], | |
936 | [AT_SETUP([Dancer $1]) | |
937 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
938 | _AT_DATA_DANCER_Y([$1]) | |
da730230 | 939 | AT_BISON_CHECK([-o dancer.c dancer.y]) |
11c4e57d | 940 | AT_FULL_COMPILE([dancer]) |
22e304a6 | 941 | AT_PARSER_CHECK([./dancer], 1, [], |
d5286af1 | 942 | [syntax error, unexpected ':' |
22e304a6 AD |
943 | ]) |
944 | AT_BISON_OPTION_POPDEFS | |
945 | AT_CLEANUP | |
946 | ]) | |
947 | ||
948 | AT_CHECK_DANCER() | |
949 | AT_CHECK_DANCER([%glr-parser]) | |
950 | AT_CHECK_DANCER([%skeleton "lalr1.cc"]) | |
d6645148 PE |
951 | |
952 | ||
953 | ## ------------------------------------------ ## | |
954 | ## Diagnostic that expects two alternatives. ## | |
955 | ## ------------------------------------------ ## | |
956 | ||
957 | ||
958 | # _AT_DATA_EXPECT2_Y(BISON-OPTIONS) | |
959 | # -------------------------------- | |
960 | m4_define([_AT_DATA_EXPECT2_Y], | |
961 | [AT_DATA_GRAMMAR([expect2.y], | |
962 | [%{ | |
963 | static int yylex (AT_LALR1_CC_IF([int *], [void])); | |
964 | AT_LALR1_CC_IF([], | |
965 | [#include <stdio.h> | |
c4bd5bf7 | 966 | #include <stdlib.h> |
d6645148 PE |
967 | static void yyerror (const char *);]) |
968 | %} | |
969 | $1 | |
970 | %defines | |
971 | %error-verbose | |
972 | %token A 1000 | |
973 | %token B | |
974 | ||
975 | %% | |
976 | program: /* empty */ | |
977 | | program e ';' | |
978 | | program error ';'; | |
979 | ||
980 | e: e '+' t | t; | |
981 | t: A | B; | |
982 | ||
983 | %% | |
984 | AT_LALR1_CC_IF( | |
985 | [/* A C++ error reporting function. */ | |
986 | void | |
987 | yy::parser::error (const location&, const std::string& m) | |
988 | { | |
989 | std::cerr << m << std::endl; | |
990 | } | |
991 | ||
992 | int | |
993 | yyparse () | |
994 | { | |
995 | yy::parser parser; | |
996 | return parser.parse (); | |
997 | } | |
998 | ], | |
999 | [static void | |
1000 | yyerror (const char *s) | |
1001 | { | |
1002 | fprintf (stderr, "%s\n", s); | |
1003 | }]) | |
1004 | ||
1005 | static int | |
1006 | yylex (AT_LALR1_CC_IF([int *lval], [void])) | |
1007 | [{ | |
cf806753 | 1008 | static int const tokens[] = |
d6645148 PE |
1009 | { |
1010 | 1000, '+', '+', -1 | |
1011 | }; | |
cf806753 | 1012 | static size_t toknum; |
d6645148 | 1013 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
cf806753 PE |
1014 | if (! (toknum < sizeof tokens / sizeof *tokens)) |
1015 | abort (); | |
d6645148 PE |
1016 | return tokens[toknum++]; |
1017 | }] | |
1018 | ||
1019 | int | |
1020 | main (void) | |
1021 | { | |
1022 | return yyparse (); | |
1023 | } | |
1024 | ]) | |
1025 | ])# _AT_DATA_EXPECT2_Y | |
1026 | ||
1027 | ||
1028 | # AT_CHECK_EXPECT2(BISON-OPTIONS) | |
1029 | # ------------------------------ | |
1030 | # Generate the grammar, compile it, run it. | |
1031 | m4_define([AT_CHECK_EXPECT2], | |
1032 | [AT_SETUP([Expecting two tokens $1]) | |
1033 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
1034 | _AT_DATA_EXPECT2_Y([$1]) | |
da730230 | 1035 | AT_BISON_CHECK([-o expect2.c expect2.y]) |
11c4e57d | 1036 | AT_FULL_COMPILE([expect2]) |
d6645148 PE |
1037 | AT_PARSER_CHECK([./expect2], 1, [], |
1038 | [syntax error, unexpected '+', expecting A or B | |
1039 | ]) | |
1040 | AT_BISON_OPTION_POPDEFS | |
1041 | AT_CLEANUP | |
1042 | ]) | |
1043 | ||
1044 | AT_CHECK_EXPECT2() | |
1045 | AT_CHECK_EXPECT2([%glr-parser]) | |
1046 | AT_CHECK_EXPECT2([%skeleton "lalr1.cc"]) | |
4210cd0b JD |
1047 | |
1048 | ||
1049 | ||
1050 | ## --------------------------------------------- ## | |
1051 | ## Braced code in declaration in rules section. ## | |
1052 | ## --------------------------------------------- ## | |
1053 | ||
1054 | AT_SETUP([Braced code in declaration in rules section]) | |
1055 | ||
1056 | # Bison once mistook braced code in a declaration in the rules section to be a | |
1057 | # rule action. | |
1058 | ||
1059 | AT_DATA_GRAMMAR([input.y], | |
1060 | [[%{ | |
1061 | #include <stdio.h> | |
381ecb06 JD |
1062 | static void yyerror (char const *msg); |
1063 | static int yylex (void); | |
4210cd0b JD |
1064 | %} |
1065 | ||
1066 | %error-verbose | |
1067 | ||
1068 | %% | |
1069 | ||
1070 | start: | |
1071 | { | |
1072 | printf ("Bison would once convert this action to a midrule because of the" | |
1073 | " subsequent braced code.\n"); | |
1074 | } | |
1075 | ; | |
1076 | ||
1077 | %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a'; | |
1078 | %printer { fprintf (yyoutput, "PRINTER"); } 'a'; | |
1079 | ||
1080 | %% | |
1081 | ||
381ecb06 | 1082 | static void |
4210cd0b JD |
1083 | yyerror (char const *msg) |
1084 | { | |
1085 | fprintf (stderr, "%s\n", msg); | |
1086 | } | |
1087 | ||
381ecb06 | 1088 | static int |
4210cd0b JD |
1089 | yylex (void) |
1090 | { | |
1091 | return 'a'; | |
1092 | } | |
1093 | ||
1094 | int | |
1095 | main (void) | |
1096 | { | |
1097 | yydebug = 1; | |
1098 | return !yyparse (); | |
1099 | } | |
1100 | ]]) | |
1101 | ||
da730230 | 1102 | AT_BISON_CHECK([-t -o input.c input.y]) |
4210cd0b JD |
1103 | AT_COMPILE([input]) |
1104 | AT_PARSER_CHECK([./input], 0, | |
1105 | [[Bison would once convert this action to a midrule because of the subsequent braced code. | |
1106 | ]], | |
1107 | [[Starting parse | |
1108 | Entering state 0 | |
231ed89a | 1109 | Reducing stack by rule 1 (line 20): |
4210cd0b JD |
1110 | -> $$ = nterm start () |
1111 | Stack now 0 | |
1112 | Entering state 1 | |
1113 | Reading a token: Next token is token 'a' (PRINTER) | |
1114 | syntax error, unexpected 'a', expecting $end | |
1115 | Error: popping nterm start () | |
1116 | Stack now 0 | |
1117 | Cleanup: discarding lookahead token 'a' (PRINTER) | |
1118 | DESTRUCTOR | |
1119 | Stack now 0 | |
1120 | ]]) | |
1121 | ||
1122 | AT_CLEANUP | |
965537bc JD |
1123 | |
1124 | ||
1125 | ||
1126 | ## --------------------------------- ## | |
1127 | ## String alias declared after use. ## | |
1128 | ## --------------------------------- ## | |
1129 | ||
1130 | AT_SETUP([String alias declared after use]) | |
1131 | ||
1132 | # Bison once incorrectly asserted that the symbol number for either a token or | |
1133 | # its alias was the highest symbol number so far at the point of the alias | |
1134 | # declaration. That was true unless the declaration appeared after their first | |
6d0ef4ec | 1135 | # uses and other tokens appeared in between. |
965537bc JD |
1136 | |
1137 | AT_DATA([input.y], | |
1138 | [[%% | |
1139 | start: 'a' "A" 'b'; | |
1140 | %token 'a' "A"; | |
1141 | ]]) | |
1142 | ||
da730230 | 1143 | AT_BISON_CHECK([-t -o input.c input.y]) |
965537bc JD |
1144 | |
1145 | AT_CLEANUP | |
a0de5091 JD |
1146 | |
1147 | ||
1148 | ||
1149 | ## -------------------------------- ## | |
1150 | ## Extra lookahead sets in report. ## | |
1151 | ## -------------------------------- ## | |
1152 | ||
1153 | AT_SETUP([[Extra lookahead sets in report]]) | |
1154 | ||
88c78747 JD |
1155 | # Bison prints each reduction's lookahead set only next to the associated |
1156 | # state's one item that (1) is associated with the same rule as the reduction | |
1157 | # and (2) has its dot at the end of its RHS. Previously, Bison also | |
1158 | # erroneously printed the lookahead set next to all of the state's other items | |
1159 | # associated with the same rule. This bug affected only the `.output' file and | |
1160 | # not the generated parser source code. | |
a0de5091 JD |
1161 | |
1162 | AT_DATA([[input.y]], | |
1163 | [[%% | |
1164 | start: a | 'a' a 'a' ; | |
1165 | a: 'a' ; | |
1166 | ]]) | |
1167 | ||
da730230 | 1168 | AT_BISON_CHECK([[--report=all input.y]]) |
a0de5091 JD |
1169 | AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]], |
1170 | [[state 1 | |
1171 | ||
1172 | 2 start: 'a' . a 'a' | |
1173 | 3 a: . 'a' | |
1174 | 3 | 'a' . [$end] | |
1175 | ||
1176 | 'a' shift, and go to state 4 | |
1177 | ||
1178 | $default reduce using rule 3 (a) | |
1179 | ||
1180 | a go to state 5 | |
1181 | ||
1182 | ||
1183 | state 2 | |
1184 | ]]) | |
1185 | ||
1186 | AT_CLEANUP | |
ab7f29f8 JD |
1187 | |
1188 | ||
1189 | ||
1190 | ## ---------------------------------------- ## | |
1191 | ## Token number in precedence declaration. ## | |
1192 | ## ---------------------------------------- ## | |
1193 | ||
14da0cdd | 1194 | AT_SETUP([[Token number in precedence declaration]]) |
ab7f29f8 JD |
1195 | |
1196 | # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but | |
1197 | # we lost this in Bison 1.50. | |
1198 | ||
1199 | AT_DATA_GRAMMAR([input.y], | |
1200 | [[%{ | |
1201 | #include <stdio.h> | |
1202 | void yyerror (char const *); | |
1203 | int yylex (void); | |
1204 | %} | |
1205 | ||
1206 | %error-verbose | |
1207 | %left TK1 1 TK2 2 "tok alias" 3 | |
1208 | ||
1209 | %% | |
1210 | ||
1211 | start: TK1 sr_conflict "tok alias" ; | |
1212 | ||
1213 | sr_conflict: | |
1214 | TK2 | |
1215 | | TK2 "tok alias" | |
1216 | ; | |
1217 | ||
1218 | %% | |
1219 | ||
1220 | void | |
1221 | yyerror (char const *msg) | |
1222 | { | |
1223 | fprintf (stderr, "%s\n", msg); | |
1224 | } | |
1225 | ||
1226 | int | |
1227 | yylex (void) | |
1228 | { | |
1229 | static int const input[] = { 1, 2, 3, 0 }; | |
1230 | static int const *inputp = input; | |
1231 | return *inputp++; | |
1232 | } | |
1233 | ||
1234 | int | |
1235 | main (void) | |
1236 | { | |
1237 | return yyparse (); | |
1238 | } | |
1239 | ]]) | |
1240 | ||
1241 | AT_BISON_CHECK([[-o input.c input.y]], [[0]],, | |
1242 | [[input.y:24.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias" | |
1243 | ]]) | |
1244 | AT_COMPILE([[input]]) | |
1245 | AT_PARSER_CHECK([[./input]]) | |
1246 | ||
1247 | AT_CLEANUP | |
873ac263 JD |
1248 | |
1249 | ||
1250 | ||
1251 | ## --------------------------- ## | |
1252 | ## parse-gram.y: LALR = IELR. ## | |
1253 | ## --------------------------- ## | |
1254 | ||
1255 | # If parse-gram.y's LALR and IELR parser tables ever begin to differ, we | |
1256 | # need to fix parse-gram.y or start using IELR. | |
1257 | ||
1258 | AT_SETUP([[parse-gram.y: LALR = IELR]]) | |
1259 | ||
1260 | # Avoid differences in synclines by telling bison that the output files | |
1261 | # have the same name. | |
4b7a4c1b JD |
1262 | [cp $abs_top_srcdir/src/parse-gram.y input.y] |
1263 | AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]]) | |
1264 | [mv input.c lalr.c] | |
1265 | AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]]) | |
1266 | [mv input.c ielr.c] | |
873ac263 JD |
1267 | AT_CHECK([[diff -u lalr.c ielr.c]]) |
1268 | ||
1269 | AT_CLEANUP | |
d88cf117 JD |
1270 | |
1271 | ||
1272 | ||
1273 | ## --------------------------------------- ## | |
1274 | ## %error-verbose and YYSTACK_USE_ALLOCA. ## | |
1275 | ## --------------------------------------- ## | |
1276 | ||
1277 | AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]]) | |
1278 | ||
1279 | AT_DATA_GRAMMAR([input.y], | |
1280 | [[%code { | |
1281 | #include <stdio.h> | |
1282 | void yyerror (char const *); | |
1283 | int yylex (void); | |
1284 | #define YYSTACK_USE_ALLOCA 1 | |
1285 | } | |
1286 | ||
1287 | %error-verbose | |
1288 | ||
1289 | %% | |
1290 | ||
1291 | start: check syntax_error syntax_error ; | |
1292 | ||
1293 | check: | |
1294 | { | |
1295 | if (128 < sizeof yymsgbuf) | |
1296 | { | |
1297 | fprintf (stderr, | |
1298 | "The initial size of yymsgbuf in yyparse has increased\n" | |
1299 | "since this test group was last updated. As a result,\n" | |
1300 | "this test group may no longer manage to induce a\n" | |
1301 | "reallocation of the syntax error message buffer.\n" | |
1302 | "This test group must be adjusted to produce a longer\n" | |
1303 | "error message.\n"); | |
1304 | YYABORT; | |
1305 | } | |
1306 | } | |
1307 | ; | |
1308 | ||
1309 | // Induce a syntax error message whose total length is more than | |
1310 | // sizeof yymsgbuf in yyparse. Each token here is 64 bytes. | |
1311 | syntax_error: | |
1312 | "123456789112345678921234567893123456789412345678951234567896123A" | |
1313 | | "123456789112345678921234567893123456789412345678951234567896123B" | |
1314 | | error 'a' 'b' 'c' | |
1315 | ; | |
1316 | ||
1317 | %% | |
1318 | ||
1319 | void | |
1320 | yyerror (char const *msg) | |
1321 | { | |
1322 | fprintf (stderr, "%s\n", msg); | |
1323 | } | |
1324 | ||
1325 | int | |
1326 | yylex (void) | |
1327 | { | |
1328 | /* Induce two syntax error messages (which requires full error | |
1329 | recovery by shifting 3 tokens) in order to detect any loss of the | |
1330 | reallocated buffer. */ | |
1331 | static char const *input = "abc"; | |
1332 | return *input++; | |
1333 | } | |
1334 | ||
1335 | int | |
1336 | main (void) | |
1337 | { | |
1338 | return yyparse (); | |
1339 | } | |
1340 | ]]) | |
1341 | ||
1342 | AT_BISON_CHECK([[-o input.c input.y]]) | |
1343 | AT_COMPILE([[input]]) | |
1344 | AT_PARSER_CHECK([[./input]], [[1]], [], | |
1345 | [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B | |
1346 | syntax error, unexpected $end, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B | |
1347 | ]]) | |
1348 | ||
1349 | AT_CLEANUP | |
1350 | ||
1351 | ||
1352 | ||
1353 | ## ------------------------- ## | |
1354 | ## %error-verbose overflow. ## | |
1355 | ## ------------------------- ## | |
1356 | ||
1357 | # Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an | |
1358 | # invocation of yysyntax_error has caused yymsg_alloc to grow to exactly | |
1359 | # YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had | |
69a2ab11 JD |
1360 | # to be clipped to YYSTACK_ALLOC_MAXIMUM). In an old version of yacc.c, |
1361 | # a subsequent invocation of yysyntax_error that overflows during its | |
1362 | # size calculation would return YYSIZE_MAXIMUM to yyparse. Then, | |
1363 | # yyparse would invoke yyerror using the old contents of yymsg. | |
d88cf117 JD |
1364 | |
1365 | AT_SETUP([[%error-verbose overflow]]) | |
1366 | ||
d88cf117 JD |
1367 | AT_DATA_GRAMMAR([input.y], |
1368 | [[%code { | |
1369 | #include <stdio.h> | |
1370 | void yyerror (char const *); | |
1371 | int yylex (void); | |
1372 | ||
1373 | /* This prevents this test case from having to induce error messages | |
1374 | large enough to overflow size_t. */ | |
1375 | #define YYSIZE_T unsigned char | |
1376 | ||
1377 | /* Bring in malloc so yacc.c doesn't try to provide a malloc prototype | |
1378 | using our YYSIZE_T. */ | |
1379 | #include <stdlib.h> | |
1380 | ||
1381 | /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and | |
1382 | we don't want gcc to warn everywhere this constant would be too big | |
1383 | to make sense for our YYSIZE_T. */ | |
1384 | #define YYMAXDEPTH 100 | |
1385 | } | |
1386 | ||
1387 | %error-verbose | |
1388 | ||
1389 | %% | |
1390 | ||
1391 | start: syntax_error1 check syntax_error2 ; | |
1392 | ||
1393 | // Induce a syntax error message whose total length causes yymsg in | |
1394 | // yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which | |
1395 | // should be 255. Each token here is 64 bytes. | |
1396 | syntax_error1: | |
1397 | "123456789112345678921234567893123456789412345678951234567896123A" | |
1398 | | "123456789112345678921234567893123456789412345678951234567896123B" | |
1399 | | "123456789112345678921234567893123456789412345678951234567896123C" | |
1400 | | error 'a' 'b' 'c' | |
1401 | ; | |
1402 | ||
1403 | check: | |
1404 | { | |
1405 | if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM | |
1406 | || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM | |
1407 | || YYSIZE_MAXIMUM != 255) | |
1408 | { | |
1409 | fprintf (stderr, | |
1410 | "The assumptions of this test group are no longer\n" | |
1411 | "valid, so it may no longer catch the error it was\n" | |
1412 | "designed to catch. Specifically, the following\n" | |
1413 | "values should all be 255:\n\n"); | |
1414 | fprintf (stderr, " yymsg_alloc = %d\n", yymsg_alloc); | |
1415 | fprintf (stderr, " YYSTACK_ALLOC_MAXIMUM = %d\n", | |
1416 | YYSTACK_ALLOC_MAXIMUM); | |
1417 | fprintf (stderr, " YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM); | |
1418 | YYABORT; | |
1419 | } | |
1420 | } | |
1421 | ; | |
1422 | ||
1423 | // Now overflow. | |
1424 | syntax_error2: | |
1425 | "123456789112345678921234567893123456789412345678951234567896123A" | |
1426 | | "123456789112345678921234567893123456789412345678951234567896123B" | |
1427 | | "123456789112345678921234567893123456789412345678951234567896123C" | |
1428 | | "123456789112345678921234567893123456789412345678951234567896123D" | |
1429 | | "123456789112345678921234567893123456789412345678951234567896123E" | |
1430 | ; | |
1431 | ||
1432 | %% | |
1433 | ||
1434 | void | |
1435 | yyerror (char const *msg) | |
1436 | { | |
1437 | fprintf (stderr, "%s\n", msg); | |
1438 | } | |
1439 | ||
1440 | int | |
1441 | yylex (void) | |
1442 | { | |
1443 | /* Induce two syntax error messages (which requires full error | |
1444 | recovery by shifting 3 tokens). */ | |
1445 | static char const *input = "abc"; | |
1446 | return *input++; | |
1447 | } | |
1448 | ||
1449 | int | |
1450 | main (void) | |
1451 | { | |
1452 | /* Push parsers throw away the message buffer between tokens, so skip | |
1453 | this test under maintainer-push-check. */ | |
1454 | if (YYPUSH) | |
1455 | return 77; | |
1456 | return yyparse (); | |
1457 | } | |
1458 | ]]) | |
1459 | ||
1460 | AT_BISON_CHECK([[-o input.c input.y]]) | |
1461 | ||
1462 | # gcc warns about tautologies and fallacies involving comparisons for | |
1463 | # unsigned char. However, it doesn't produce these same warnings for | |
1464 | # size_t and many other types when the warnings would seem to make just | |
1465 | # as much sense. We ignore the warnings. | |
1466 | [CFLAGS="$NO_WERROR_CFLAGS"] | |
1467 | AT_COMPILE([[input]]) | |
1468 | ||
1469 | AT_PARSER_CHECK([[./input]], [[2]], [], | |
1470 | [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C | |
1471 | syntax error | |
1472 | memory exhausted | |
1473 | ]]) | |
1474 | ||
1475 | AT_CLEANUP |