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