]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Bison Regressions. -*- Autotest -*- |
d42cf844 | 2 | |
c932d613 | 3 | # Copyright (C) 2001-2012 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], | |
9874f80b | 165 | [[/* Bison used to swallow the character after '}'. */ |
2b25d624 AD |
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], |
9874f80b | 187 | [[/* 'Bison -v' used to dump core when two tokens are defined with the same |
c95f2d78 AD |
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, [], |
4c787a31 | 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], [], |
9874f80b JM |
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: '&' | |
394 | input.y:5.1-17: invalid directive: '%a-does-not-exist' | |
395 | input.y:6.1: invalid character: '%' | |
396 | input.y:6.2: invalid character: '-' | |
397 | input.y:7.1-8.0: missing '%}' at end of file | |
47aee066 | 398 | input.y:7.1-8.0: syntax error, unexpected %{...%} |
e0c40012 | 399 | ]]) |
561f9a30 AD |
400 | |
401 | AT_CLEANUP | |
402 | ||
403 | ||
fc01665e PE |
404 | AT_SETUP([Invalid inputs with {}]) |
405 | ||
406 | AT_DATA([input.y], | |
407 | [[ | |
408 | %destructor | |
409 | %initial-action | |
410 | %lex-param | |
411 | %parse-param | |
412 | %printer | |
413 | %union | |
414 | ]]) | |
415 | ||
da730230 | 416 | AT_BISON_CHECK([input.y], [1], [], |
e9071366 | 417 | [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...} |
fc01665e PE |
418 | ]]) |
419 | ||
420 | AT_CLEANUP | |
421 | ||
422 | ||
270a173c | 423 | |
b87f8b21 AD |
424 | ## ------------------- ## |
425 | ## Token definitions. ## | |
426 | ## ------------------- ## | |
427 | ||
428 | ||
429 | AT_SETUP([Token definitions]) | |
430 | ||
9874f80b | 431 | # Bison managed, when fed with '%token 'f' "f"' to #define 'f'! |
9501dc6e | 432 | AT_DATA_GRAMMAR([input.y], |
db7c8e9a | 433 | [%{ |
cf806753 | 434 | #include <stdlib.h> |
ca407bdf | 435 | #include <stdio.h> |
db7c8e9a AD |
436 | void yyerror (const char *s); |
437 | int yylex (void); | |
438 | %} | |
ca407bdf PE |
439 | [%error-verbose |
440 | %token MYEOF 0 "end of file" | |
b87f8b21 | 441 | %token 'a' "a" |
4f136612 PE |
442 | %token B_TOKEN "b" |
443 | %token C_TOKEN 'c' | |
444 | %token 'd' D_TOKEN | |
3d54b576 | 445 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" |
1cfe6375 | 446 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" |
b87f8b21 | 447 | %% |
3d54b576 | 448 | exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"; |
ca407bdf PE |
449 | %% |
450 | void | |
451 | yyerror (char const *s) | |
452 | { | |
453 | fprintf (stderr, "%s\n", s); | |
454 | } | |
455 | ||
456 | int | |
457 | yylex (void) | |
458 | { | |
cf806753 PE |
459 | static int called; |
460 | if (called++) | |
461 | abort (); | |
ca407bdf PE |
462 | return SPECIAL; |
463 | } | |
464 | ||
465 | int | |
466 | main (void) | |
467 | { | |
468 | return yyparse (); | |
469 | } | |
b87f8b21 AD |
470 | ]]) |
471 | ||
1cfe6375 JD |
472 | # Checking the warning message guarantees that the trigraph "??!" isn't |
473 | # unnecessarily escaped here even though it would need to be if encoded in a | |
474 | # C-string literal. Also notice that unnecessary escaping, such as "\?", from | |
475 | # the user specification is eliminated. | |
476 | AT_BISON_CHECK([-o input.c input.y], [[0]], [[]], | |
477 | [[input.y:22.8-14: warning: symbol SPECIAL redeclared | |
4c787a31 | 478 | 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 |
1cfe6375 | 479 | ]]) |
ca407bdf | 480 | AT_COMPILE([input]) |
1cfe6375 JD |
481 | |
482 | # Checking the error message here guarantees that yytname, which does contain | |
483 | # C-string literals, does have the trigraph escaped correctly. Thus, the | |
484 | # symbol name reported by the parser is exactly the same as that reported by | |
485 | # Bison itself. | |
3d54b576 | 486 | AT_DATA([experr], |
1cfe6375 | 487 | [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a |
3d54b576 PE |
488 | ]]) |
489 | AT_PARSER_CHECK([./input], 1, [], [experr]) | |
b87f8b21 AD |
490 | AT_CLEANUP |
491 | ||
492 | ||
493 | ||
eb714592 AD |
494 | ## -------------------- ## |
495 | ## Characters Escapes. ## | |
496 | ## -------------------- ## | |
497 | ||
498 | ||
499 | AT_SETUP([Characters Escapes]) | |
500 | ||
9501dc6e | 501 | AT_DATA_GRAMMAR([input.y], |
eb714592 AD |
502 | [%{ |
503 | void yyerror (const char *s); | |
504 | int yylex (void); | |
505 | %} | |
6d0ef4ec | 506 | [%% |
eb714592 AD |
507 | exp: |
508 | '\'' "\'" | |
509 | | '\"' "\"" | |
510 | | '"' "'" | |
511 | ; | |
512 | ]]) | |
9501dc6e | 513 | # Pacify font-lock-mode: " |
eb714592 | 514 | |
da730230 | 515 | AT_BISON_CHECK([-o input.c input.y]) |
eb714592 AD |
516 | AT_COMPILE([input.o], [-c input.c]) |
517 | AT_CLEANUP | |
518 | ||
519 | ||
520 | ||
b9752825 AD |
521 | ## -------------- ## |
522 | ## Web2c Report. ## | |
523 | ## -------------- ## | |
776209d6 AD |
524 | |
525 | # The generation of the reduction was once wrong in Bison, and made it | |
526 | # miss some reductions. In the following test case, the reduction on | |
9874f80b | 527 | # 'undef_id_tok' in state 1 was missing. This is stripped down from |
776209d6 AD |
528 | # the actual web2c.y. |
529 | ||
b9752825 | 530 | AT_SETUP([Web2c Report]) |
776209d6 | 531 | |
6b98e4b5 AD |
532 | AT_KEYWORDS([report]) |
533 | ||
776209d6 AD |
534 | AT_DATA([input.y], |
535 | [[%token undef_id_tok const_id_tok | |
536 | ||
537 | %start CONST_DEC_PART | |
538 | \f | |
539 | %% | |
540 | CONST_DEC_PART: | |
541 | CONST_DEC_LIST | |
542 | ; | |
543 | ||
544 | CONST_DEC_LIST: | |
545 | CONST_DEC | |
546 | | CONST_DEC_LIST CONST_DEC | |
547 | ; | |
548 | ||
549 | CONST_DEC: | |
550 | { } undef_id_tok '=' const_id_tok ';' | |
551 | ; | |
552 | %% | |
776209d6 AD |
553 | ]]) |
554 | ||
da730230 | 555 | AT_BISON_CHECK([-v input.y]) |
87675353 | 556 | AT_CHECK([cat input.output], 0, |
776209d6 | 557 | [[Grammar |
87675353 | 558 | |
88bce5a2 | 559 | 0 $accept: CONST_DEC_PART $end |
87675353 | 560 | |
6b98e4b5 | 561 | 1 CONST_DEC_PART: CONST_DEC_LIST |
87675353 | 562 | |
6b98e4b5 AD |
563 | 2 CONST_DEC_LIST: CONST_DEC |
564 | 3 | CONST_DEC_LIST CONST_DEC | |
87675353 | 565 | |
f91b1629 | 566 | 4 $@1: /* empty */ |
87675353 | 567 | |
f91b1629 | 568 | 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' |
87675353 AD |
569 | |
570 | ||
776209d6 | 571 | Terminals, with rules where they appear |
87675353 | 572 | |
88bce5a2 | 573 | $end (0) 0 |
776209d6 AD |
574 | ';' (59) 5 |
575 | '=' (61) 5 | |
576 | error (256) | |
007a50a4 AD |
577 | undef_id_tok (258) 5 |
578 | const_id_tok (259) 5 | |
87675353 AD |
579 | |
580 | ||
776209d6 | 581 | Nonterminals, with rules where they appear |
87675353 | 582 | |
88bce5a2 | 583 | $accept (7) |
78d5bae9 AD |
584 | on left: 0 |
585 | CONST_DEC_PART (8) | |
586 | on left: 1, on right: 0 | |
587 | CONST_DEC_LIST (9) | |
776209d6 | 588 | on left: 2 3, on right: 1 3 |
78d5bae9 | 589 | CONST_DEC (10) |
776209d6 | 590 | on left: 5, on right: 2 3 |
f91b1629 | 591 | $@1 (11) |
776209d6 | 592 | on left: 4, on right: 5 |
87675353 AD |
593 | |
594 | ||
776209d6 | 595 | state 0 |
87675353 | 596 | |
88bce5a2 | 597 | 0 $accept: . CONST_DEC_PART $end |
87675353 | 598 | |
f91b1629 | 599 | $default reduce using rule 4 ($@1) |
87675353 AD |
600 | |
601 | CONST_DEC_PART go to state 1 | |
602 | CONST_DEC_LIST go to state 2 | |
603 | CONST_DEC go to state 3 | |
f91b1629 | 604 | $@1 go to state 4 |
87675353 AD |
605 | |
606 | ||
776209d6 | 607 | state 1 |
87675353 | 608 | |
88bce5a2 | 609 | 0 $accept: CONST_DEC_PART . $end |
87675353 | 610 | |
88bce5a2 | 611 | $end shift, and go to state 5 |
87675353 AD |
612 | |
613 | ||
78d5bae9 | 614 | state 2 |
87675353 | 615 | |
ce4ccb4b AD |
616 | 1 CONST_DEC_PART: CONST_DEC_LIST . |
617 | 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC | |
87675353 | 618 | |
f91b1629 | 619 | undef_id_tok reduce using rule 4 ($@1) |
87675353 AD |
620 | $default reduce using rule 1 (CONST_DEC_PART) |
621 | ||
622 | CONST_DEC go to state 6 | |
f91b1629 | 623 | $@1 go to state 4 |
87675353 AD |
624 | |
625 | ||
78d5bae9 | 626 | state 3 |
87675353 | 627 | |
ce4ccb4b | 628 | 2 CONST_DEC_LIST: CONST_DEC . |
87675353 AD |
629 | |
630 | $default reduce using rule 2 (CONST_DEC_LIST) | |
631 | ||
632 | ||
776209d6 | 633 | state 4 |
87675353 | 634 | |
f91b1629 | 635 | 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';' |
87675353 AD |
636 | |
637 | undef_id_tok shift, and go to state 7 | |
638 | ||
639 | ||
78d5bae9 | 640 | state 5 |
87675353 | 641 | |
88bce5a2 | 642 | 0 $accept: CONST_DEC_PART $end . |
87675353 | 643 | |
e8832397 | 644 | $default accept |
87675353 AD |
645 | |
646 | ||
78d5bae9 | 647 | state 6 |
87675353 | 648 | |
ce4ccb4b | 649 | 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC . |
87675353 AD |
650 | |
651 | $default reduce using rule 3 (CONST_DEC_LIST) | |
652 | ||
653 | ||
78d5bae9 | 654 | state 7 |
87675353 | 655 | |
f91b1629 | 656 | 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';' |
87675353 AD |
657 | |
658 | '=' shift, and go to state 8 | |
659 | ||
660 | ||
78d5bae9 | 661 | state 8 |
87675353 | 662 | |
f91b1629 | 663 | 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';' |
87675353 AD |
664 | |
665 | const_id_tok shift, and go to state 9 | |
666 | ||
667 | ||
78d5bae9 | 668 | state 9 |
87675353 | 669 | |
f91b1629 | 670 | 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';' |
87675353 AD |
671 | |
672 | ';' shift, and go to state 10 | |
673 | ||
674 | ||
78d5bae9 | 675 | state 10 |
87675353 | 676 | |
f91b1629 | 677 | 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' . |
87675353 AD |
678 | |
679 | $default reduce using rule 5 (CONST_DEC) | |
776209d6 AD |
680 | ]]) |
681 | ||
682 | AT_CLEANUP | |
b9752825 AD |
683 | |
684 | ||
685 | ## --------------- ## | |
686 | ## Web2c Actions. ## | |
687 | ## --------------- ## | |
688 | ||
9874f80b | 689 | # The generation of the mapping 'state -> action' was once wrong in |
b9752825 AD |
690 | # extremely specific situations. web2c.y exhibits this situation. |
691 | # Below is a stripped version of the grammar. It looks like one can | |
692 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
693 | # which disapears when applying sane grammar transformations. | |
694 | # | |
695 | # It used to be wrong on yydefact only: | |
696 | # | |
d42cf844 | 697 | # static const yytype_uint8 yydefact[] = |
b9752825 AD |
698 | # { |
699 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
700 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
701 | # 0, 0 | |
702 | # }; | |
703 | # | |
704 | # but let's check all the tables. | |
705 | ||
706 | ||
707 | AT_SETUP([Web2c Actions]) | |
708 | ||
6b98e4b5 AD |
709 | AT_KEYWORDS([report]) |
710 | ||
b9752825 AD |
711 | AT_DATA([input.y], |
712 | [[%% | |
713 | statement: struct_stat; | |
714 | struct_stat: /* empty. */ | if else; | |
715 | if: "if" "const" "then" statement; | |
716 | else: "else" statement; | |
717 | %% | |
718 | ]]) | |
719 | ||
da730230 | 720 | AT_BISON_CHECK([-v -o input.c input.y]) |
b9752825 | 721 | |
728c4be2 | 722 | # Check only the tables. |
ce4ccb4b AD |
723 | [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] |
724 | ||
725 | AT_CHECK([[cat tables.c]], 0, | |
d42cf844 | 726 | [[static const yytype_uint8 yytranslate[] = |
b9752825 AD |
727 | { |
728 | 0, 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, | |
752 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
007a50a4 AD |
753 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
754 | 5, 6 | |
b9752825 | 755 | }; |
d42cf844 | 756 | static const yytype_uint8 yyprhs[] = |
b9752825 | 757 | { |
e7b8bef1 | 758 | 0, 0, 3, 5, 6, 9, 14 |
b9752825 | 759 | }; |
d42cf844 | 760 | static const yytype_int8 yyrhs[] = |
b9752825 | 761 | { |
e7b8bef1 AD |
762 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, |
763 | 4, 5, 8, -1, 6, 8, -1 | |
b9752825 | 764 | }; |
d42cf844 | 765 | static const yytype_uint8 yyrline[] = |
b9752825 | 766 | { |
e7b8bef1 | 767 | 0, 2, 2, 3, 3, 4, 5 |
b9752825 AD |
768 | }; |
769 | static const char *const yytname[] = | |
770 | { | |
9e0876fb | 771 | "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"", |
ef51bfa7 | 772 | "\"else\"", "$accept", "statement", "struct_stat", "if", "else", YY_NULL |
b9752825 | 773 | }; |
d42cf844 | 774 | static const yytype_uint16 yytoknum[] = |
b9752825 | 775 | { |
3650b4b8 | 776 | 0, 256, 257, 258, 259, 260, 261 |
b9752825 | 777 | }; |
d42cf844 | 778 | static const yytype_uint8 yyr1[] = |
b9752825 | 779 | { |
e7b8bef1 | 780 | 0, 7, 8, 9, 9, 10, 11 |
b9752825 | 781 | }; |
d42cf844 | 782 | static const yytype_uint8 yyr2[] = |
b9752825 | 783 | { |
e7b8bef1 | 784 | 0, 2, 1, 0, 2, 4, 2 |
b9752825 | 785 | }; |
d42cf844 | 786 | static const yytype_uint8 yydefact[] = |
b9752825 | 787 | { |
e8832397 | 788 | 3, 0, 0, 2, 0, 0, 1, 3, 4, 3, |
e7b8bef1 | 789 | 6, 5 |
b9752825 | 790 | }; |
d42cf844 | 791 | static const yytype_int8 yydefgoto[] = |
b9752825 | 792 | { |
e7b8bef1 | 793 | -1, 2, 3, 4, 8 |
b9752825 | 794 | }; |
d42cf844 | 795 | static const yytype_int8 yypact[] = |
b9752825 | 796 | { |
12b0043a AD |
797 | -2, -1, 4, -8, 0, 2, -8, -2, -8, -2, |
798 | -8, -8 | |
b9752825 | 799 | }; |
d42cf844 | 800 | static const yytype_int8 yypgoto[] = |
b9752825 | 801 | { |
12b0043a | 802 | -8, -7, -8, -8, -8 |
b9752825 | 803 | }; |
d42cf844 | 804 | static const yytype_uint8 yytable[] = |
b9752825 | 805 | { |
e7b8bef1 | 806 | 10, 1, 11, 5, 6, 0, 7, 9 |
b9752825 | 807 | }; |
d42cf844 | 808 | static const yytype_int8 yycheck[] = |
b9752825 | 809 | { |
e7b8bef1 | 810 | 7, 3, 9, 4, 0, -1, 6, 5 |
b9752825 | 811 | }; |
d42cf844 | 812 | static const yytype_uint8 yystos[] = |
5504898e AD |
813 | { |
814 | 0, 3, 8, 9, 10, 4, 0, 6, 11, 5, | |
815 | 8, 8 | |
816 | }; | |
b9752825 AD |
817 | ]]) |
818 | ||
819 | AT_CLEANUP | |
22e304a6 AD |
820 | |
821 | ||
822 | ## ------------------------- ## | |
823 | ## yycheck Bound Violation. ## | |
824 | ## ------------------------- ## | |
825 | ||
826 | ||
827 | # _AT_DATA_DANCER_Y(BISON-OPTIONS) | |
828 | # -------------------------------- | |
829 | # The following grammar, taken from Andrew Suffield's GPL'd implementation | |
830 | # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate | |
831 | # yycheck's bounds where issuing a verbose error message. Keep this test | |
832 | # so that possible bound checking compilers could check all the skeletons. | |
833 | m4_define([_AT_DATA_DANCER_Y], | |
834 | [AT_DATA_GRAMMAR([dancer.y], | |
835 | [%{ | |
848dc439 PE |
836 | static int yylex (AT_LALR1_CC_IF([int *], [void])); |
837 | AT_LALR1_CC_IF([], | |
cf806753 PE |
838 | [#include <stdlib.h> |
839 | #include <stdio.h> | |
848dc439 | 840 | static void yyerror (const char *);]) |
22e304a6 AD |
841 | %} |
842 | $1 | |
843 | %token ARROW INVALID NUMBER STRING DATA | |
844 | %defines | |
845 | %verbose | |
846 | %error-verbose | |
847 | /* Grammar follows */ | |
848 | %% | |
849 | line: header body | |
850 | ; | |
851 | ||
852 | header: '<' from ARROW to '>' type ':' | |
853 | | '<' ARROW to '>' type ':' | |
854 | | ARROW to type ':' | |
855 | | type ':' | |
856 | | '<' '>' | |
857 | ; | |
858 | ||
859 | from: DATA | |
860 | | STRING | |
861 | | INVALID | |
862 | ; | |
863 | ||
864 | to: DATA | |
865 | | STRING | |
866 | | INVALID | |
867 | ; | |
868 | ||
869 | type: DATA | |
870 | | STRING | |
871 | | INVALID | |
872 | ; | |
873 | ||
874 | body: /* empty */ | |
875 | | body member | |
876 | ; | |
877 | ||
878 | member: STRING | |
879 | | DATA | |
880 | | '+' NUMBER | |
881 | | '-' NUMBER | |
882 | | NUMBER | |
883 | | INVALID | |
884 | ; | |
885 | %% | |
886 | AT_LALR1_CC_IF( | |
68e11668 | 887 | [/* A C++ error reporting function. */ |
22e304a6 | 888 | void |
99880de5 | 889 | yy::parser::error (const location&, const std::string& m) |
22e304a6 | 890 | { |
efeed023 | 891 | std::cerr << m << std::endl; |
22e304a6 AD |
892 | } |
893 | ||
894 | int | |
99880de5 | 895 | yyparse () |
22e304a6 | 896 | { |
99880de5 | 897 | yy::parser parser; |
fa7b79c0 PE |
898 | #if YYDEBUG |
899 | parser.set_debug_level (YYDEBUG); | |
900 | #endif | |
22e304a6 AD |
901 | return parser.parse (); |
902 | } | |
903 | ], | |
904 | [static void | |
905 | yyerror (const char *s) | |
906 | { | |
907 | fprintf (stderr, "%s\n", s); | |
908 | }]) | |
909 | ||
910 | static int | |
848dc439 | 911 | yylex (AT_LALR1_CC_IF([int *lval], [void])) |
22e304a6 | 912 | [{ |
cf806753 | 913 | static int const tokens[] = |
22e304a6 AD |
914 | { |
915 | ':', -1 | |
916 | }; | |
cf806753 | 917 | static size_t toknum; |
848dc439 | 918 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
cf806753 PE |
919 | if (! (toknum < sizeof tokens / sizeof *tokens)) |
920 | abort (); | |
22e304a6 AD |
921 | return tokens[toknum++]; |
922 | }] | |
923 | ||
924 | int | |
925 | main (void) | |
926 | { | |
927 | return yyparse (); | |
928 | } | |
929 | ]) | |
930 | ])# _AT_DATA_DANCER_Y | |
931 | ||
932 | ||
933 | # AT_CHECK_DANCER(BISON-OPTIONS) | |
934 | # ------------------------------ | |
935 | # Generate the grammar, compile it, run it. | |
936 | m4_define([AT_CHECK_DANCER], | |
937 | [AT_SETUP([Dancer $1]) | |
938 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
939 | _AT_DATA_DANCER_Y([$1]) | |
da730230 | 940 | AT_BISON_CHECK([-o dancer.c dancer.y]) |
11c4e57d | 941 | AT_FULL_COMPILE([dancer]) |
22e304a6 | 942 | AT_PARSER_CHECK([./dancer], 1, [], |
d5286af1 | 943 | [syntax error, unexpected ':' |
22e304a6 AD |
944 | ]) |
945 | AT_BISON_OPTION_POPDEFS | |
946 | AT_CLEANUP | |
947 | ]) | |
948 | ||
949 | AT_CHECK_DANCER() | |
950 | AT_CHECK_DANCER([%glr-parser]) | |
951 | AT_CHECK_DANCER([%skeleton "lalr1.cc"]) | |
d6645148 PE |
952 | |
953 | ||
954 | ## ------------------------------------------ ## | |
955 | ## Diagnostic that expects two alternatives. ## | |
956 | ## ------------------------------------------ ## | |
957 | ||
958 | ||
959 | # _AT_DATA_EXPECT2_Y(BISON-OPTIONS) | |
960 | # -------------------------------- | |
961 | m4_define([_AT_DATA_EXPECT2_Y], | |
962 | [AT_DATA_GRAMMAR([expect2.y], | |
963 | [%{ | |
964 | static int yylex (AT_LALR1_CC_IF([int *], [void])); | |
965 | AT_LALR1_CC_IF([], | |
966 | [#include <stdio.h> | |
c4bd5bf7 | 967 | #include <stdlib.h> |
d6645148 PE |
968 | static void yyerror (const char *);]) |
969 | %} | |
970 | $1 | |
971 | %defines | |
972 | %error-verbose | |
973 | %token A 1000 | |
974 | %token B | |
975 | ||
976 | %% | |
977 | program: /* empty */ | |
978 | | program e ';' | |
979 | | program error ';'; | |
980 | ||
981 | e: e '+' t | t; | |
982 | t: A | B; | |
983 | ||
984 | %% | |
985 | AT_LALR1_CC_IF( | |
986 | [/* A C++ error reporting function. */ | |
987 | void | |
988 | yy::parser::error (const location&, const std::string& m) | |
989 | { | |
990 | std::cerr << m << std::endl; | |
991 | } | |
992 | ||
993 | int | |
994 | yyparse () | |
995 | { | |
996 | yy::parser parser; | |
997 | return parser.parse (); | |
998 | } | |
999 | ], | |
1000 | [static void | |
1001 | yyerror (const char *s) | |
1002 | { | |
1003 | fprintf (stderr, "%s\n", s); | |
1004 | }]) | |
1005 | ||
1006 | static int | |
1007 | yylex (AT_LALR1_CC_IF([int *lval], [void])) | |
1008 | [{ | |
cf806753 | 1009 | static int const tokens[] = |
d6645148 PE |
1010 | { |
1011 | 1000, '+', '+', -1 | |
1012 | }; | |
cf806753 | 1013 | static size_t toknum; |
d6645148 | 1014 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
cf806753 PE |
1015 | if (! (toknum < sizeof tokens / sizeof *tokens)) |
1016 | abort (); | |
d6645148 PE |
1017 | return tokens[toknum++]; |
1018 | }] | |
1019 | ||
1020 | int | |
1021 | main (void) | |
1022 | { | |
1023 | return yyparse (); | |
1024 | } | |
1025 | ]) | |
1026 | ])# _AT_DATA_EXPECT2_Y | |
1027 | ||
1028 | ||
1029 | # AT_CHECK_EXPECT2(BISON-OPTIONS) | |
1030 | # ------------------------------ | |
1031 | # Generate the grammar, compile it, run it. | |
1032 | m4_define([AT_CHECK_EXPECT2], | |
1033 | [AT_SETUP([Expecting two tokens $1]) | |
1034 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
1035 | _AT_DATA_EXPECT2_Y([$1]) | |
da730230 | 1036 | AT_BISON_CHECK([-o expect2.c expect2.y]) |
11c4e57d | 1037 | AT_FULL_COMPILE([expect2]) |
d6645148 PE |
1038 | AT_PARSER_CHECK([./expect2], 1, [], |
1039 | [syntax error, unexpected '+', expecting A or B | |
1040 | ]) | |
1041 | AT_BISON_OPTION_POPDEFS | |
1042 | AT_CLEANUP | |
1043 | ]) | |
1044 | ||
1045 | AT_CHECK_EXPECT2() | |
1046 | AT_CHECK_EXPECT2([%glr-parser]) | |
1047 | AT_CHECK_EXPECT2([%skeleton "lalr1.cc"]) | |
4210cd0b JD |
1048 | |
1049 | ||
1050 | ||
1051 | ## --------------------------------------------- ## | |
1052 | ## Braced code in declaration in rules section. ## | |
1053 | ## --------------------------------------------- ## | |
1054 | ||
1055 | AT_SETUP([Braced code in declaration in rules section]) | |
1056 | ||
1057 | # Bison once mistook braced code in a declaration in the rules section to be a | |
1058 | # rule action. | |
1059 | ||
1060 | AT_DATA_GRAMMAR([input.y], | |
1061 | [[%{ | |
1062 | #include <stdio.h> | |
381ecb06 JD |
1063 | static void yyerror (char const *msg); |
1064 | static int yylex (void); | |
4210cd0b JD |
1065 | %} |
1066 | ||
1067 | %error-verbose | |
1068 | ||
1069 | %% | |
1070 | ||
1071 | start: | |
1072 | { | |
1073 | printf ("Bison would once convert this action to a midrule because of the" | |
1074 | " subsequent braced code.\n"); | |
1075 | } | |
1076 | ; | |
1077 | ||
1078 | %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a'; | |
1079 | %printer { fprintf (yyoutput, "PRINTER"); } 'a'; | |
1080 | ||
1081 | %% | |
1082 | ||
381ecb06 | 1083 | static void |
4210cd0b JD |
1084 | yyerror (char const *msg) |
1085 | { | |
1086 | fprintf (stderr, "%s\n", msg); | |
1087 | } | |
1088 | ||
381ecb06 | 1089 | static int |
4210cd0b JD |
1090 | yylex (void) |
1091 | { | |
1092 | return 'a'; | |
1093 | } | |
1094 | ||
1095 | int | |
1096 | main (void) | |
1097 | { | |
1098 | yydebug = 1; | |
1099 | return !yyparse (); | |
1100 | } | |
1101 | ]]) | |
1102 | ||
da730230 | 1103 | AT_BISON_CHECK([-t -o input.c input.y]) |
4210cd0b JD |
1104 | AT_COMPILE([input]) |
1105 | AT_PARSER_CHECK([./input], 0, | |
1106 | [[Bison would once convert this action to a midrule because of the subsequent braced code. | |
1107 | ]], | |
1108 | [[Starting parse | |
1109 | Entering state 0 | |
231ed89a | 1110 | Reducing stack by rule 1 (line 20): |
4210cd0b JD |
1111 | -> $$ = nterm start () |
1112 | Stack now 0 | |
1113 | Entering state 1 | |
1114 | Reading a token: Next token is token 'a' (PRINTER) | |
1115 | syntax error, unexpected 'a', expecting $end | |
1116 | Error: popping nterm start () | |
1117 | Stack now 0 | |
1118 | Cleanup: discarding lookahead token 'a' (PRINTER) | |
1119 | DESTRUCTOR | |
1120 | Stack now 0 | |
1121 | ]]) | |
1122 | ||
1123 | AT_CLEANUP | |
965537bc JD |
1124 | |
1125 | ||
1126 | ||
1127 | ## --------------------------------- ## | |
1128 | ## String alias declared after use. ## | |
1129 | ## --------------------------------- ## | |
1130 | ||
1131 | AT_SETUP([String alias declared after use]) | |
1132 | ||
1133 | # Bison once incorrectly asserted that the symbol number for either a token or | |
1134 | # its alias was the highest symbol number so far at the point of the alias | |
1135 | # declaration. That was true unless the declaration appeared after their first | |
6d0ef4ec | 1136 | # uses and other tokens appeared in between. |
965537bc JD |
1137 | |
1138 | AT_DATA([input.y], | |
1139 | [[%% | |
1140 | start: 'a' "A" 'b'; | |
1141 | %token 'a' "A"; | |
1142 | ]]) | |
1143 | ||
da730230 | 1144 | AT_BISON_CHECK([-t -o input.c input.y]) |
965537bc JD |
1145 | |
1146 | AT_CLEANUP | |
a0de5091 JD |
1147 | |
1148 | ||
1149 | ||
1150 | ## -------------------------------- ## | |
1151 | ## Extra lookahead sets in report. ## | |
1152 | ## -------------------------------- ## | |
1153 | ||
1154 | AT_SETUP([[Extra lookahead sets in report]]) | |
1155 | ||
88c78747 JD |
1156 | # Bison prints each reduction's lookahead set only next to the associated |
1157 | # state's one item that (1) is associated with the same rule as the reduction | |
1158 | # and (2) has its dot at the end of its RHS. Previously, Bison also | |
1159 | # erroneously printed the lookahead set next to all of the state's other items | |
9874f80b | 1160 | # associated with the same rule. This bug affected only the '.output' file and |
88c78747 | 1161 | # not the generated parser source code. |
a0de5091 JD |
1162 | |
1163 | AT_DATA([[input.y]], | |
1164 | [[%% | |
1165 | start: a | 'a' a 'a' ; | |
1166 | a: 'a' ; | |
1167 | ]]) | |
1168 | ||
da730230 | 1169 | AT_BISON_CHECK([[--report=all input.y]]) |
a0de5091 JD |
1170 | AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]], |
1171 | [[state 1 | |
1172 | ||
1173 | 2 start: 'a' . a 'a' | |
1174 | 3 a: . 'a' | |
1175 | 3 | 'a' . [$end] | |
1176 | ||
1177 | 'a' shift, and go to state 4 | |
1178 | ||
1179 | $default reduce using rule 3 (a) | |
1180 | ||
1181 | a go to state 5 | |
1182 | ||
1183 | ||
1184 | state 2 | |
1185 | ]]) | |
1186 | ||
1187 | AT_CLEANUP | |
ab7f29f8 JD |
1188 | |
1189 | ||
1190 | ||
1191 | ## ---------------------------------------- ## | |
1192 | ## Token number in precedence declaration. ## | |
1193 | ## ---------------------------------------- ## | |
1194 | ||
14da0cdd | 1195 | AT_SETUP([[Token number in precedence declaration]]) |
ab7f29f8 JD |
1196 | |
1197 | # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but | |
1198 | # we lost this in Bison 1.50. | |
1199 | ||
1200 | AT_DATA_GRAMMAR([input.y], | |
1201 | [[%{ | |
1202 | #include <stdio.h> | |
1203 | void yyerror (char const *); | |
1204 | int yylex (void); | |
1205 | %} | |
1206 | ||
1207 | %error-verbose | |
9d6af153 | 1208 | %right END 0 |
ab7f29f8 JD |
1209 | %left TK1 1 TK2 2 "tok alias" 3 |
1210 | ||
1211 | %% | |
1212 | ||
9d6af153 JD |
1213 | start: |
1214 | TK1 sr_conflict "tok alias" | |
1215 | | start %prec END | |
1216 | ; | |
ab7f29f8 JD |
1217 | sr_conflict: |
1218 | TK2 | |
1219 | | TK2 "tok alias" | |
1220 | ; | |
1221 | ||
1222 | %% | |
1223 | ||
1224 | void | |
1225 | yyerror (char const *msg) | |
1226 | { | |
1227 | fprintf (stderr, "%s\n", msg); | |
1228 | } | |
1229 | ||
1230 | int | |
1231 | yylex (void) | |
1232 | { | |
1233 | static int const input[] = { 1, 2, 3, 0 }; | |
1234 | static int const *inputp = input; | |
1235 | return *inputp++; | |
1236 | } | |
1237 | ||
1238 | int | |
1239 | main (void) | |
1240 | { | |
1241 | return yyparse (); | |
1242 | } | |
1243 | ]]) | |
1244 | ||
1245 | AT_BISON_CHECK([[-o input.c input.y]], [[0]],, | |
9d6af153 JD |
1246 | [[input.y:23.5-19: warning: rule useless in parser due to conflicts: start: start |
1247 | input.y:27.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias" | |
ab7f29f8 JD |
1248 | ]]) |
1249 | AT_COMPILE([[input]]) | |
1250 | AT_PARSER_CHECK([[./input]]) | |
1251 | ||
1252 | AT_CLEANUP | |
873ac263 JD |
1253 | |
1254 | ||
1255 | ||
1256 | ## --------------------------- ## | |
1257 | ## parse-gram.y: LALR = IELR. ## | |
1258 | ## --------------------------- ## | |
1259 | ||
1260 | # If parse-gram.y's LALR and IELR parser tables ever begin to differ, we | |
1261 | # need to fix parse-gram.y or start using IELR. | |
1262 | ||
1263 | AT_SETUP([[parse-gram.y: LALR = IELR]]) | |
1264 | ||
1265 | # Avoid differences in synclines by telling bison that the output files | |
1266 | # have the same name. | |
4b7a4c1b JD |
1267 | [cp $abs_top_srcdir/src/parse-gram.y input.y] |
1268 | AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]]) | |
7a709ad8 | 1269 | [mv input.c expout] |
4b7a4c1b JD |
1270 | AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]]) |
1271 | [mv input.c ielr.c] | |
7a709ad8 | 1272 | AT_CHECK([[cat ielr.c]], [[0]], [[expout]]) |
873ac263 JD |
1273 | |
1274 | AT_CLEANUP | |
d88cf117 JD |
1275 | |
1276 | ||
1277 | ||
1278 | ## --------------------------------------- ## | |
1279 | ## %error-verbose and YYSTACK_USE_ALLOCA. ## | |
1280 | ## --------------------------------------- ## | |
1281 | ||
1282 | AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]]) | |
1283 | ||
1284 | AT_DATA_GRAMMAR([input.y], | |
1285 | [[%code { | |
1286 | #include <stdio.h> | |
1287 | void yyerror (char const *); | |
1288 | int yylex (void); | |
1289 | #define YYSTACK_USE_ALLOCA 1 | |
1290 | } | |
1291 | ||
1292 | %error-verbose | |
1293 | ||
1294 | %% | |
1295 | ||
1296 | start: check syntax_error syntax_error ; | |
1297 | ||
1298 | check: | |
1299 | { | |
1300 | if (128 < sizeof yymsgbuf) | |
1301 | { | |
1302 | fprintf (stderr, | |
1303 | "The initial size of yymsgbuf in yyparse has increased\n" | |
1304 | "since this test group was last updated. As a result,\n" | |
1305 | "this test group may no longer manage to induce a\n" | |
1306 | "reallocation of the syntax error message buffer.\n" | |
1307 | "This test group must be adjusted to produce a longer\n" | |
1308 | "error message.\n"); | |
1309 | YYABORT; | |
1310 | } | |
1311 | } | |
1312 | ; | |
1313 | ||
1314 | // Induce a syntax error message whose total length is more than | |
1315 | // sizeof yymsgbuf in yyparse. Each token here is 64 bytes. | |
1316 | syntax_error: | |
1317 | "123456789112345678921234567893123456789412345678951234567896123A" | |
1318 | | "123456789112345678921234567893123456789412345678951234567896123B" | |
1319 | | error 'a' 'b' 'c' | |
1320 | ; | |
1321 | ||
1322 | %% | |
1323 | ||
1324 | void | |
1325 | yyerror (char const *msg) | |
1326 | { | |
1327 | fprintf (stderr, "%s\n", msg); | |
1328 | } | |
1329 | ||
1330 | int | |
1331 | yylex (void) | |
1332 | { | |
1333 | /* Induce two syntax error messages (which requires full error | |
1334 | recovery by shifting 3 tokens) in order to detect any loss of the | |
1335 | reallocated buffer. */ | |
1336 | static char const *input = "abc"; | |
1337 | return *input++; | |
1338 | } | |
1339 | ||
1340 | int | |
1341 | main (void) | |
1342 | { | |
1343 | return yyparse (); | |
1344 | } | |
1345 | ]]) | |
1346 | ||
1347 | AT_BISON_CHECK([[-o input.c input.y]]) | |
1348 | AT_COMPILE([[input]]) | |
1349 | AT_PARSER_CHECK([[./input]], [[1]], [], | |
1350 | [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B | |
1351 | syntax error, unexpected $end, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B | |
1352 | ]]) | |
1353 | ||
1354 | AT_CLEANUP | |
1355 | ||
1356 | ||
1357 | ||
1358 | ## ------------------------- ## | |
1359 | ## %error-verbose overflow. ## | |
1360 | ## ------------------------- ## | |
1361 | ||
1362 | # Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an | |
1363 | # invocation of yysyntax_error has caused yymsg_alloc to grow to exactly | |
1364 | # YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had | |
69a2ab11 JD |
1365 | # to be clipped to YYSTACK_ALLOC_MAXIMUM). In an old version of yacc.c, |
1366 | # a subsequent invocation of yysyntax_error that overflows during its | |
1367 | # size calculation would return YYSIZE_MAXIMUM to yyparse. Then, | |
1368 | # yyparse would invoke yyerror using the old contents of yymsg. | |
d88cf117 JD |
1369 | |
1370 | AT_SETUP([[%error-verbose overflow]]) | |
1371 | ||
d88cf117 JD |
1372 | AT_DATA_GRAMMAR([input.y], |
1373 | [[%code { | |
1374 | #include <stdio.h> | |
1375 | void yyerror (char const *); | |
1376 | int yylex (void); | |
1377 | ||
1378 | /* This prevents this test case from having to induce error messages | |
1379 | large enough to overflow size_t. */ | |
1380 | #define YYSIZE_T unsigned char | |
1381 | ||
ea6046b9 | 1382 | /* Bring in malloc and set EXIT_SUCCESS so yacc.c doesn't try to |
23761f42 | 1383 | provide a malloc prototype using our YYSIZE_T. */ |
d88cf117 | 1384 | #include <stdlib.h> |
ea6046b9 PE |
1385 | #ifndef EXIT_SUCCESS |
1386 | # define EXIT_SUCCESS 0 | |
23761f42 | 1387 | #endif |
d88cf117 JD |
1388 | |
1389 | /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and | |
1390 | we don't want gcc to warn everywhere this constant would be too big | |
1391 | to make sense for our YYSIZE_T. */ | |
1392 | #define YYMAXDEPTH 100 | |
1393 | } | |
1394 | ||
1395 | %error-verbose | |
1396 | ||
1397 | %% | |
1398 | ||
1399 | start: syntax_error1 check syntax_error2 ; | |
1400 | ||
1401 | // Induce a syntax error message whose total length causes yymsg in | |
1402 | // yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which | |
1403 | // should be 255. Each token here is 64 bytes. | |
1404 | syntax_error1: | |
1405 | "123456789112345678921234567893123456789412345678951234567896123A" | |
1406 | | "123456789112345678921234567893123456789412345678951234567896123B" | |
1407 | | "123456789112345678921234567893123456789412345678951234567896123C" | |
1408 | | error 'a' 'b' 'c' | |
1409 | ; | |
1410 | ||
1411 | check: | |
1412 | { | |
1413 | if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM | |
1414 | || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM | |
1415 | || YYSIZE_MAXIMUM != 255) | |
1416 | { | |
1417 | fprintf (stderr, | |
1418 | "The assumptions of this test group are no longer\n" | |
1419 | "valid, so it may no longer catch the error it was\n" | |
1420 | "designed to catch. Specifically, the following\n" | |
1421 | "values should all be 255:\n\n"); | |
1422 | fprintf (stderr, " yymsg_alloc = %d\n", yymsg_alloc); | |
1423 | fprintf (stderr, " YYSTACK_ALLOC_MAXIMUM = %d\n", | |
1424 | YYSTACK_ALLOC_MAXIMUM); | |
1425 | fprintf (stderr, " YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM); | |
1426 | YYABORT; | |
1427 | } | |
1428 | } | |
1429 | ; | |
1430 | ||
1431 | // Now overflow. | |
1432 | syntax_error2: | |
1433 | "123456789112345678921234567893123456789412345678951234567896123A" | |
1434 | | "123456789112345678921234567893123456789412345678951234567896123B" | |
1435 | | "123456789112345678921234567893123456789412345678951234567896123C" | |
1436 | | "123456789112345678921234567893123456789412345678951234567896123D" | |
1437 | | "123456789112345678921234567893123456789412345678951234567896123E" | |
1438 | ; | |
1439 | ||
1440 | %% | |
1441 | ||
1442 | void | |
1443 | yyerror (char const *msg) | |
1444 | { | |
1445 | fprintf (stderr, "%s\n", msg); | |
1446 | } | |
1447 | ||
1448 | int | |
1449 | yylex (void) | |
1450 | { | |
1451 | /* Induce two syntax error messages (which requires full error | |
1452 | recovery by shifting 3 tokens). */ | |
1453 | static char const *input = "abc"; | |
1454 | return *input++; | |
1455 | } | |
1456 | ||
1457 | int | |
1458 | main (void) | |
1459 | { | |
1460 | /* Push parsers throw away the message buffer between tokens, so skip | |
1461 | this test under maintainer-push-check. */ | |
1462 | if (YYPUSH) | |
1463 | return 77; | |
1464 | return yyparse (); | |
1465 | } | |
1466 | ]]) | |
1467 | ||
1468 | AT_BISON_CHECK([[-o input.c input.y]]) | |
1469 | ||
1470 | # gcc warns about tautologies and fallacies involving comparisons for | |
1471 | # unsigned char. However, it doesn't produce these same warnings for | |
1472 | # size_t and many other types when the warnings would seem to make just | |
1473 | # as much sense. We ignore the warnings. | |
1474 | [CFLAGS="$NO_WERROR_CFLAGS"] | |
1475 | AT_COMPILE([[input]]) | |
1476 | ||
1477 | AT_PARSER_CHECK([[./input]], [[2]], [], | |
1478 | [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C | |
1479 | syntax error | |
1480 | memory exhausted | |
1481 | ]]) | |
1482 | ||
1483 | AT_CLEANUP | |
ea13bea8 JD |
1484 | |
1485 | ||
1486 | ||
1487 | ## ------------------------ ## | |
1488 | ## LAC: Exploratory stack. ## | |
1489 | ## ------------------------ ## | |
1490 | ||
1491 | AT_SETUP([[LAC: Exploratory stack]]) | |
1492 | ||
1493 | m4_pushdef([AT_LAC_CHECK], [ | |
1494 | ||
1495 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
1496 | ||
1497 | AT_DATA_GRAMMAR([input.y], | |
1498 | [[%code { | |
1499 | #include <stdio.h> | |
1500 | void yyerror (char const *); | |
1501 | int yylex (]AT_PURE_IF([[YYSTYPE *]], [[void]])[); | |
1502 | } | |
1503 | ||
1504 | ]$1[ | |
1505 | %error-verbose | |
1506 | %token 'c' | |
1507 | ||
1508 | %% | |
1509 | ||
1510 | // default reductions in inconsistent states | |
1511 | // v v v v v v v v v v v v v v | |
1512 | S: A B A A B A A A A B A A A A A A A B C C A A A A A A A A A A A A B ; | |
723fe7d1 JD |
1513 | // ^ ^ ^ |
1514 | // LAC reallocs | |
ea13bea8 JD |
1515 | |
1516 | A: 'a' | /*empty*/ { printf ("inconsistent default reduction\n"); } ; | |
1517 | B: 'b' ; | |
1518 | C: /*empty*/ { printf ("consistent default reduction\n"); } ; | |
1519 | ||
1520 | %% | |
1521 | ||
1522 | void | |
1523 | yyerror (char const *msg) | |
1524 | { | |
1525 | fprintf (stderr, "%s\n", msg); | |
1526 | } | |
1527 | ||
1528 | int | |
1529 | yylex (]AT_PURE_IF([[YYSTYPE *v]], [[void]])[) | |
1530 | { | |
1531 | static char const *input = "bbbbc";]AT_PURE_IF([[ | |
1532 | *v = 0;]])[ | |
1533 | return *input++; | |
1534 | } | |
1535 | ||
1536 | int | |
1537 | main (void) | |
1538 | { | |
1539 | yydebug = 1; | |
1540 | return yyparse (); | |
1541 | } | |
1542 | ]]) | |
1543 | ||
723fe7d1 JD |
1544 | AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \ |
1545 | -Dparse.lac.memory-trace=full \ | |
ea13bea8 JD |
1546 | -t -o input.c input.y]], [[0]], [], |
1547 | [[input.y: conflicts: 21 shift/reduce | |
1548 | ]]) | |
1549 | AT_COMPILE([[input]]) | |
1550 | AT_PARSER_CHECK([[./input > stdout.txt 2> stderr.txt]], [[1]]) | |
1551 | ||
1552 | # Make sure syntax error doesn't forget that 'a' is expected. It would | |
1553 | # be forgotten without lookahead correction. | |
1554 | AT_CHECK([[grep 'syntax error,' stderr.txt]], [[0]], | |
1555 | [[syntax error, unexpected 'c', expecting 'a' or 'b' | |
1556 | ]]) | |
1557 | ||
1558 | # Check number of default reductions in inconsistent states to be sure | |
1559 | # syntax error is detected before unnecessary reductions are performed. | |
1560 | AT_CHECK([[perl -0777 -ne 'print s/inconsistent default reduction//g;' \ | |
1561 | < stdout.txt || exit 77]], [[0]], [[14]]) | |
1562 | ||
1563 | # Check number of default reductions in consistent states to be sure | |
1564 | # it is performed before the syntax error is detected. | |
1565 | AT_CHECK([[perl -0777 -ne 'print s/\bconsistent default reduction//g;' \ | |
1566 | < stdout.txt || exit 77]], [[0]], [[2]]) | |
1567 | ||
723fe7d1 JD |
1568 | # Check number of reallocs to be sure reallocated memory isn't somehow |
1569 | # lost between LAC invocations. | |
1570 | AT_CHECK([[perl -0777 -ne 'print s/\(realloc//g;' < stderr.txt \ | |
1571 | || exit 77]], [[0]], [[3]]) | |
1572 | ||
ea13bea8 JD |
1573 | AT_BISON_OPTION_POPDEFS |
1574 | ]) | |
1575 | ||
1576 | AT_LAC_CHECK([[%define api.push-pull pull]]) | |
1577 | AT_LAC_CHECK([[%define api.push-pull pull %define api.pure]]) | |
1578 | AT_LAC_CHECK([[%define api.push-pull both]]) | |
1579 | AT_LAC_CHECK([[%define api.push-pull both %define api.pure]]) | |
1580 | ||
1581 | m4_popdef([AT_LAC_CHECK]) | |
1582 | ||
1583 | AT_CLEANUP | |
1584 | ||
1585 | ||
1586 | ||
1587 | ## ------------------------ ## | |
1588 | ## LAC: Memory exhaustion. ## | |
1589 | ## ------------------------ ## | |
1590 | ||
1591 | AT_SETUP([[LAC: Memory exhaustion]]) | |
1592 | ||
1593 | m4_pushdef([AT_LAC_CHECK], [ | |
1594 | ||
1595 | AT_DATA_GRAMMAR([input.y], | |
1596 | [[%code { | |
1597 | #include <stdio.h> | |
1598 | void yyerror (char const *); | |
1599 | int yylex (void); | |
723fe7d1 | 1600 | #define YYMAXDEPTH 8 |
ea13bea8 JD |
1601 | } |
1602 | ||
1603 | %error-verbose | |
1604 | ||
1605 | %% | |
1606 | ||
1607 | S: A A A A A A A A A ; | |
1608 | A: /*empty*/ | 'a' ; | |
1609 | ||
1610 | %% | |
1611 | ||
1612 | void | |
1613 | yyerror (char const *msg) | |
1614 | { | |
1615 | fprintf (stderr, "%s\n", msg); | |
1616 | } | |
1617 | ||
1618 | int | |
1619 | yylex (void) | |
1620 | { | |
1621 | static char const *input = "]$1["; | |
1622 | return *input++; | |
1623 | } | |
1624 | ||
1625 | int | |
1626 | main (void) | |
1627 | { | |
1628 | yydebug = 1; | |
1629 | return yyparse (); | |
1630 | } | |
1631 | ]]) | |
1632 | ||
723fe7d1 | 1633 | AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \ |
ea13bea8 JD |
1634 | -t -o input.c input.y]], [[0]], [], |
1635 | [[input.y: conflicts: 8 shift/reduce | |
1636 | ]]) | |
1637 | AT_COMPILE([[input]]) | |
1638 | ||
1639 | ]) | |
1640 | ||
1641 | # Check for memory exhaustion during parsing. | |
1642 | AT_LAC_CHECK([[]]) | |
1643 | AT_PARSER_CHECK([[./input]], [[2]], [[]], | |
1644 | [[Starting parse | |
1645 | Entering state 0 | |
1646 | Reading a token: Now at end of input. | |
1647 | LAC: initial context established for $end | |
723fe7d1 | 1648 | LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded) |
ea13bea8 JD |
1649 | memory exhausted |
1650 | Cleanup: discarding lookahead token $end () | |
1651 | Stack now 0 | |
1652 | ]]) | |
1653 | ||
1654 | # Induce an immediate syntax error with an undefined token, and check | |
1655 | # for memory exhaustion while building syntax error message. | |
1656 | AT_LAC_CHECK([[z]], [[0]]) | |
1657 | AT_PARSER_CHECK([[./input]], [[2]], [[]], | |
1658 | [[Starting parse | |
1659 | Entering state 0 | |
1660 | Reading a token: Next token is token $undefined () | |
1661 | LAC: initial context established for $undefined | |
1662 | LAC: checking lookahead $undefined: Always Err | |
1663 | Constructing syntax error message | |
723fe7d1 | 1664 | LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded) |
ea13bea8 JD |
1665 | syntax error |
1666 | memory exhausted | |
1667 | Cleanup: discarding lookahead token $undefined () | |
1668 | Stack now 0 | |
1669 | ]]) | |
1670 | ||
1671 | m4_popdef([AT_LAC_CHECK]) | |
1672 | ||
1673 | AT_CLEANUP |