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