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