]> git.saurik.com Git - bison.git/blame - tests/regression.at
* src/Makefile.am: Add bison.c++.
[bison.git] / tests / regression.at
CommitLineData
342b8b6e
AD
1# Bison Regressions. -*- Autotest -*-
2# Copyright 2001 Free Software Foundation, Inc.
c95f2d78 3
342b8b6e
AD
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
c95f2d78 8
342b8b6e
AD
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
c95f2d78 13
342b8b6e
AD
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17# 02111-1307, USA.
c95f2d78 18
342b8b6e 19AT_BANNER([[Regression tests.]])
c95f2d78 20
2b25d624
AD
21
22## ---------------- ##
23## Braces parsing. ##
24## ---------------- ##
25
26
27AT_SETUP([braces parsing])
28
29AT_DATA([input.y],
30[[/* Bison used to swallow the character after `}'. */
31
32%%
33exp: { tests = {{{{{{{{{{}}}}}}}}}}; }
34%%
35]])
36
37AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
38
39AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
40
41AT_CLEANUP
42
43
c95f2d78
AD
44## ------------------ ##
45## Duplicate string. ##
46## ------------------ ##
47
48
49AT_SETUP([Duplicate string])
50
f499b062 51AT_DATA([input.y],
c95f2d78
AD
52[[/* `Bison -v' used to dump core when two tokens are defined with the same
53 string, as LE and GE below. */
54
55%token NUM
56%token LE "<="
57%token GE "<="
58
59%%
60exp: '(' exp ')' | NUM ;
61%%
62]])
63
f499b062 64AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
c95f2d78 65
d803322e 66AT_CLEANUP
c95f2d78
AD
67
68
ba9dda1a
AD
69## ------------------------- ##
70## Unresolved SR Conflicts. ##
71## ------------------------- ##
0df87bb6 72
ba9dda1a 73AT_SETUP([Unresolved SR Conflicts])
0df87bb6
AD
74
75AT_DATA([input.y],
76[[%token NUM OP
77%%
78exp: exp OP exp | NUM;
79]])
80
81AT_CHECK([bison input.y -o input.c -v], 0, [],
82[input.y contains 1 shift/reduce conflict.
83])
84
85# Check the contents of the report.
86AT_CHECK([cat input.output], [],
b365aa05 87[[State 5 contains 1 shift/reduce conflict.
0df87bb6 88
d2d1b42b 89
0df87bb6
AD
90Grammar
91
b29b2ed5 92 Number, Line, Rule
ff442794 93 0 3 $axiom -> exp $
b29b2ed5
AD
94 1 3 exp -> exp OP exp
95 2 3 exp -> NUM
0df87bb6 96
d2d1b42b 97
0df87bb6
AD
98Terminals, with rules where they appear
99
b365aa05 100$ (0) 0
0df87bb6
AD
101error (256)
102NUM (257) 2
103OP (258) 1
104
d2d1b42b 105
0df87bb6
AD
106Nonterminals, with rules where they appear
107
b365aa05
AD
108$axiom (5)
109 on left: 0
110exp (6)
111 on left: 1 2, on right: 0 1
0df87bb6
AD
112
113
114state 0
115
116 NUM shift, and go to state 1
117
118 exp go to state 2
119
120
121
122state 1
123
124 exp -> NUM . (rule 2)
125
126 $default reduce using rule 2 (exp)
127
128
129
130state 2
131
b365aa05 132 $axiom -> exp . $ (rule 0)
0df87bb6
AD
133 exp -> exp . OP exp (rule 1)
134
b365aa05
AD
135 $ shift, and go to state 3
136 OP shift, and go to state 4
0df87bb6
AD
137
138
139
140state 3
141
b365aa05 142 $axiom -> exp $ . (rule 0)
0df87bb6 143
b365aa05 144 $default accept
0df87bb6
AD
145
146
147state 4
148
b365aa05 149 exp -> exp OP . exp (rule 1)
0df87bb6 150
b365aa05 151 NUM shift, and go to state 1
0df87bb6 152
b365aa05 153 exp go to state 5
c73a41af 154
0df87bb6
AD
155
156
157state 5
158
b365aa05
AD
159 exp -> exp . OP exp (rule 1)
160 exp -> exp OP exp . (rule 1)
0df87bb6 161
b365aa05 162 OP shift, and go to state 4
0df87bb6 163
b365aa05
AD
164 OP [reduce using rule 1 (exp)]
165 $default reduce using rule 1 (exp)
ba9dda1a 166
d2d1b42b
AD
167
168
ba9dda1a
AD
169]])
170
d803322e 171AT_CLEANUP
ba9dda1a
AD
172
173
174## --------------------- ##
175## Solved SR Conflicts. ##
176## --------------------- ##
177
178AT_SETUP([Solved SR Conflicts])
179
180AT_DATA([input.y],
181[[%token NUM OP
182%right OP
183%%
184exp: exp OP exp | NUM;
185]])
186
187AT_CHECK([bison input.y -o input.c -v], 0, [], [])
188
189# Check the contents of the report.
190AT_CHECK([cat input.output], [],
b365aa05 191[[Conflict in state 5 between rule 2 and token OP resolved as shift.
ba9dda1a 192
d2d1b42b 193
ba9dda1a
AD
194Grammar
195
b29b2ed5 196 Number, Line, Rule
ff442794 197 0 4 $axiom -> exp $
b29b2ed5
AD
198 1 4 exp -> exp OP exp
199 2 4 exp -> NUM
ba9dda1a 200
d2d1b42b 201
ba9dda1a
AD
202Terminals, with rules where they appear
203
b365aa05 204$ (0) 0
ba9dda1a
AD
205error (256)
206NUM (257) 2
207OP (258) 1
208
d2d1b42b 209
ba9dda1a
AD
210Nonterminals, with rules where they appear
211
b365aa05
AD
212$axiom (5)
213 on left: 0
214exp (6)
215 on left: 1 2, on right: 0 1
ba9dda1a
AD
216
217
218state 0
219
220 NUM shift, and go to state 1
221
222 exp go to state 2
223
224
225
226state 1
227
228 exp -> NUM . (rule 2)
229
230 $default reduce using rule 2 (exp)
231
232
233
234state 2
235
b365aa05 236 $axiom -> exp . $ (rule 0)
ba9dda1a
AD
237 exp -> exp . OP exp (rule 1)
238
b365aa05
AD
239 $ shift, and go to state 3
240 OP shift, and go to state 4
ba9dda1a
AD
241
242
243
244state 3
245
b365aa05 246 $axiom -> exp $ . (rule 0)
ba9dda1a 247
b365aa05 248 $default accept
ba9dda1a
AD
249
250
251state 4
252
b365aa05 253 exp -> exp OP . exp (rule 1)
ba9dda1a 254
b365aa05 255 NUM shift, and go to state 1
ba9dda1a 256
b365aa05 257 exp go to state 5
ba9dda1a
AD
258
259
260
261state 5
262
b365aa05
AD
263 exp -> exp . OP exp (rule 1)
264 exp -> exp OP exp . (rule 1)
ba9dda1a 265
b365aa05 266 OP shift, and go to state 4
ba9dda1a 267
b365aa05 268 $default reduce using rule 1 (exp)
0df87bb6 269
d2d1b42b
AD
270
271
0df87bb6
AD
272]])
273
d803322e 274AT_CLEANUP
0df87bb6 275
c95f2d78 276
7da99ede 277
2ca209c1
AD
278
279## ------------------- ##
280## Rule Line Numbers. ##
281## ------------------- ##
282
283AT_SETUP([Rule Line Numbers])
284
285AT_DATA([input.y],
286[[%%
287expr:
288'a'
289
290{
291
292}
293
294'b'
295
296{
297
298}
299
300|
301
302
303{
304
305
306}
307
308'c'
309
310{
311
312}
313]])
314
315AT_CHECK([bison input.y -o input.c -v], 0, [], [])
316
317# Check the contents of the report.
318AT_CHECK([cat input.output], [],
d2d1b42b 319[[Grammar
2ca209c1
AD
320
321 Number, Line, Rule
ff442794 322 0 2 $axiom -> expr $
2ca209c1
AD
323 1 2 @1 -> /* empty */
324 2 2 expr -> 'a' @1 'b'
325 3 15 @2 -> /* empty */
326 4 15 expr -> @2 'c'
327
d2d1b42b 328
2ca209c1
AD
329Terminals, with rules where they appear
330
b365aa05 331$ (0) 0
2ca209c1
AD
332'a' (97) 2
333'b' (98) 2
334'c' (99) 4
335error (256)
336
d2d1b42b 337
2ca209c1
AD
338Nonterminals, with rules where they appear
339
b365aa05
AD
340$axiom (6)
341 on left: 0
342expr (7)
343 on left: 2 4, on right: 0
344@1 (8)
2ca209c1 345 on left: 1, on right: 2
b365aa05 346@2 (9)
2ca209c1
AD
347 on left: 3, on right: 4
348
349
350state 0
351
352 'a' shift, and go to state 1
353
610ab194
AD
354 $default reduce using rule 3 (@2)
355
b365aa05
AD
356 expr go to state 2
357 @2 go to state 3
2ca209c1
AD
358
359
360
361state 1
362
363 expr -> 'a' . @1 'b' (rule 2)
364
365 $default reduce using rule 1 (@1)
366
b365aa05 367 @1 go to state 4
2ca209c1
AD
368
369
370
371state 2
372
b365aa05 373 $axiom -> expr . $ (rule 0)
2ca209c1 374
b365aa05 375 $ shift, and go to state 5
2ca209c1
AD
376
377
378
379state 3
380
b365aa05 381 expr -> @2 . 'c' (rule 4)
2ca209c1 382
b365aa05 383 'c' shift, and go to state 6
2ca209c1
AD
384
385
386
387state 4
388
b365aa05 389 expr -> 'a' @1 . 'b' (rule 2)
2ca209c1 390
b365aa05 391 'b' shift, and go to state 7
2ca209c1
AD
392
393
394
395state 5
396
b365aa05 397 $axiom -> expr $ . (rule 0)
2ca209c1 398
b365aa05 399 $default accept
2ca209c1
AD
400
401
402state 6
403
b365aa05
AD
404 expr -> @2 'c' . (rule 4)
405
406 $default reduce using rule 4 (expr)
2ca209c1
AD
407
408
409
410state 7
411
b365aa05
AD
412 expr -> 'a' @1 'b' . (rule 2)
413
414 $default reduce using rule 2 (expr)
415
d2d1b42b
AD
416
417
2ca209c1
AD
418]])
419
420AT_CLEANUP
421
422
423
7da99ede
AD
424## -------------------- ##
425## %expect not enough. ##
426## -------------------- ##
427
428AT_SETUP([%expect not enough])
429
430AT_DATA([input.y],
431[[%token NUM OP
432%expect 0
433%%
434exp: exp OP exp | NUM;
435]])
436
437AT_CHECK([bison input.y -o input.c], 1, [],
438[input.y contains 1 shift/reduce conflict.
439expected 0 shift/reduce conflicts
440])
d803322e 441AT_CLEANUP
7da99ede
AD
442
443
444## --------------- ##
445## %expect right. ##
446## --------------- ##
447
448AT_SETUP([%expect right])
449
450AT_DATA([input.y],
451[[%token NUM OP
452%expect 1
453%%
454exp: exp OP exp | NUM;
455]])
456
a034c8b8 457AT_CHECK([bison input.y -o input.c], 0)
d803322e 458AT_CLEANUP
7da99ede
AD
459
460
461## ------------------ ##
462## %expect too much. ##
463## ------------------ ##
464
465AT_SETUP([%expect too much])
466
467AT_DATA([input.y],
468[[%token NUM OP
469%expect 2
470%%
471exp: exp OP exp | NUM;
472]])
473
474AT_CHECK([bison input.y -o input.c], 1, [],
475[input.y contains 1 shift/reduce conflict.
476expected 2 shift/reduce conflicts
477])
d803322e 478AT_CLEANUP
7da99ede
AD
479
480
cd5aafcf
AD
481## ---------------------- ##
482## Mixing %token styles. ##
483## ---------------------- ##
484
485
486AT_SETUP([Mixing %token styles])
487
488# Taken from the documentation.
489AT_DATA([input.y],
490[[%token <operator> OR "||"
491%token <operator> LE 134 "<="
492%left OR "<="
493%%
494exp: ;
495%%
496]])
497
498AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
499
d803322e 500AT_CLEANUP
cd5aafcf
AD
501
502
503
561f9a30
AD
504## ----------------- ##
505## Invalid input 1. ##
506## ----------------- ##
507
508
509AT_SETUP([Invalid input: 1])
510
511AT_DATA([input.y],
512[[%%
513?
514]])
515
516AT_CHECK([bison input.y], [1], [],
e0c40012 517[[input.y:2: invalid input: `?'
561f9a30 518input.y:3: fatal error: no rules in the input grammar
e0c40012 519]])
561f9a30
AD
520
521AT_CLEANUP
522
523
524## ----------------- ##
525## Invalid input 2. ##
526## ----------------- ##
527
528
529AT_SETUP([Invalid input: 2])
530
531AT_DATA([input.y],
532[[%%
533default: 'a' }
534]])
535
536AT_CHECK([bison input.y], [1], [],
e0c40012
AD
537[[input.y:2: invalid input: `}'
538]])
539
540AT_CLEANUP
541
542
543
544## -------------------- ##
545## Invalid %directive. ##
546## -------------------- ##
547
548
549AT_SETUP([Invalid %directive])
550
551AT_DATA([input.y],
552[[%invalid
553]])
554
555AT_CHECK([bison input.y], [1], [],
556[[input.y:1: unrecognized: %invalid
557input.y:1: Skipping to next %
558input.y:2: fatal error: no input grammar
559]])
561f9a30
AD
560
561AT_CLEANUP
562
563
270a173c 564
b9752825
AD
565## -------------- ##
566## Web2c Report. ##
567## -------------- ##
776209d6
AD
568
569# The generation of the reduction was once wrong in Bison, and made it
570# miss some reductions. In the following test case, the reduction on
571# `undef_id_tok' in state 1 was missing. This is stripped down from
572# the actual web2c.y.
573
b9752825 574AT_SETUP([Web2c Report])
776209d6
AD
575
576AT_DATA([input.y],
577[[%token undef_id_tok const_id_tok
578
579%start CONST_DEC_PART
580\f
581%%
582CONST_DEC_PART:
583 CONST_DEC_LIST
584 ;
585
586CONST_DEC_LIST:
587 CONST_DEC
588 | CONST_DEC_LIST CONST_DEC
589 ;
590
591CONST_DEC:
592 { } undef_id_tok '=' const_id_tok ';'
593 ;
594%%
595
596]])
597
598AT_CHECK([bison -v input.y])
599
600AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
601[[Grammar
602 Number, Line, Rule
78d5bae9 603 0 6 $axiom -> CONST_DEC_PART $
776209d6
AD
604 1 6 CONST_DEC_PART -> CONST_DEC_LIST
605 2 10 CONST_DEC_LIST -> CONST_DEC
606 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
607 4 15 @1 -> /* empty */
608 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
609Terminals, with rules where they appear
78d5bae9 610$ (0) 0
776209d6
AD
611';' (59) 5
612'=' (61) 5
613error (256)
614undef_id_tok (257) 5
615const_id_tok (258) 5
616Nonterminals, with rules where they appear
78d5bae9
AD
617$axiom (7)
618 on left: 0
619CONST_DEC_PART (8)
620 on left: 1, on right: 0
621CONST_DEC_LIST (9)
776209d6 622 on left: 2 3, on right: 1 3
78d5bae9 623CONST_DEC (10)
776209d6 624 on left: 5, on right: 2 3
78d5bae9 625@1 (11)
776209d6
AD
626 on left: 4, on right: 5
627state 0
628 $default reduce using rule 4 (@1)
78d5bae9
AD
629 CONST_DEC_PART go to state 1
630 CONST_DEC_LIST go to state 2
631 CONST_DEC go to state 3
632 @1 go to state 4
776209d6 633state 1
78d5bae9
AD
634 $axiom -> CONST_DEC_PART . $ (rule 0)
635 $ shift, and go to state 5
636state 2
776209d6
AD
637 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
638 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
639 undef_id_tok reduce using rule 4 (@1)
640 $default reduce using rule 1 (CONST_DEC_PART)
78d5bae9
AD
641 CONST_DEC go to state 6
642 @1 go to state 4
643state 3
776209d6
AD
644 CONST_DEC_LIST -> CONST_DEC . (rule 2)
645 $default reduce using rule 2 (CONST_DEC_LIST)
776209d6 646state 4
78d5bae9
AD
647 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
648 undef_id_tok shift, and go to state 7
649state 5
650 $axiom -> CONST_DEC_PART $ . (rule 0)
651 $default accept
652state 6
776209d6
AD
653 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
654 $default reduce using rule 3 (CONST_DEC_LIST)
78d5bae9 655state 7
776209d6 656 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
78d5bae9
AD
657 '=' shift, and go to state 8
658state 8
776209d6 659 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
78d5bae9
AD
660 const_id_tok shift, and go to state 9
661state 9
776209d6 662 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
78d5bae9
AD
663 ';' shift, and go to state 10
664state 10
776209d6
AD
665 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
666 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
667]])
668
669AT_CLEANUP
b9752825
AD
670
671
672## --------------- ##
673## Web2c Actions. ##
674## --------------- ##
675
676# The generation of the mapping `state -> action' was once wrong in
677# extremely specific situations. web2c.y exhibits this situation.
678# Below is a stripped version of the grammar. It looks like one can
679# simplify it further, but just don't: it is tuned to exhibit a bug,
680# which disapears when applying sane grammar transformations.
681#
682# It used to be wrong on yydefact only:
683#
684# static const short yydefact[] =
685# {
686# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
687# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
688# 0, 0
689# };
690#
691# but let's check all the tables.
692
693
694AT_SETUP([Web2c Actions])
695
696AT_DATA([input.y],
697[[%%
698statement: struct_stat;
699struct_stat: /* empty. */ | if else;
700if: "if" "const" "then" statement;
701else: "else" statement;
702%%
703]])
704
705AT_CHECK([bison -v input.y -o input.c])
706
707# Check only the tables. We don't use --no-parser, because it is
708# still to be implemented in the experimental branch of Bison.
709AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
710[[static const char yytranslate[] =
711{
712 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
713 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
714 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
715 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
716 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
717 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
718 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
719 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
720 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
721 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
722 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
723 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
724 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
725 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
726 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
727 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
728 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
729 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
730 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
731 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
732 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
733 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
734 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
735 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
736 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
737 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
738 6
739};
740static const short yyprhs[] =
741{
e7b8bef1 742 0, 0, 3, 5, 6, 9, 14
b9752825
AD
743};
744static const short yyrhs[] =
745{
e7b8bef1
AD
746 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
747 4, 5, 8, -1, 6, 8, -1
b9752825
AD
748};
749static const short yyrline[] =
750{
e7b8bef1 751 0, 2, 2, 3, 3, 4, 5
b9752825
AD
752};
753static const char *const yytname[] =
754{
755 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
e7b8bef1 756 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", NULL
b9752825
AD
757};
758static const short yytoknum[] =
759{
760 0, 256, 2, 257, 258, 259, 260, -1
761};
762static const short yyr1[] =
763{
e7b8bef1 764 0, 7, 8, 9, 9, 10, 11
b9752825
AD
765};
766static const short yyr2[] =
767{
e7b8bef1 768 0, 2, 1, 0, 2, 4, 2
b9752825
AD
769};
770static const short yydefact[] =
771{
e7b8bef1
AD
772 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
773 6, 5
b9752825
AD
774};
775static const short yydefgoto[] =
776{
e7b8bef1 777 -1, 2, 3, 4, 8
b9752825
AD
778};
779static const short yypact[] =
780{
e7b8bef1
AD
781 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
782 -32768,-32768
b9752825
AD
783};
784static const short yypgoto[] =
785{
e7b8bef1 786 -32768, -7,-32768,-32768,-32768
b9752825
AD
787};
788static const short yytable[] =
789{
e7b8bef1 790 10, 1, 11, 5, 6, 0, 7, 9
b9752825
AD
791};
792static const short yycheck[] =
793{
e7b8bef1 794 7, 3, 9, 4, 0, -1, 6, 5
b9752825
AD
795};
796]])
797
798AT_CLEANUP