1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001 Free Software Foundation, Inc.
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)
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.
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
19 AT_BANNER([[Regression tests.]])
22 ## ---------------- ##
24 ## ---------------- ##
27 AT_SETUP([braces parsing])
30 [[/* Bison used to swallow the character after `}'. */
33 exp: { tests = {{{{{{{{{{}}}}}}}}}}; }
37 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
39 AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
44 ## ------------------ ##
45 ## Duplicate string. ##
46 ## ------------------ ##
49 AT_SETUP([Duplicate string])
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. */
60 exp: '(' exp ')' | NUM ;
64 AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
69 ## ------------------------- ##
70 ## Unresolved SR Conflicts. ##
71 ## ------------------------- ##
73 AT_SETUP([Unresolved SR Conflicts])
78 exp: exp OP exp | NUM;
81 AT_CHECK([bison input.y -o input.c -v], 0, [],
82 [input.y contains 1 shift/reduce conflict.
85 # Check the contents of the report.
86 AT_CHECK([cat input.output], [],
87 [[State 4 contains 1 shift/reduce conflict.
97 Terminals, with rules where they appear
105 Nonterminals, with rules where they appear
108 on left: 1 2, on right: 1
113 NUM shift, and go to state 1
121 exp -> NUM . (rule 2)
123 $default reduce using rule 2 (exp)
129 exp -> exp . OP exp (rule 1)
132 OP shift, and go to state 3
138 exp -> exp OP . exp (rule 1)
140 NUM shift, and go to state 1
148 exp -> exp . OP exp (rule 1)
149 exp -> exp OP exp . (rule 1)
151 OP shift, and go to state 3
153 OP [reduce using rule 1 (exp)]
154 $default reduce using rule 1 (exp)
174 ## --------------------- ##
175 ## Solved SR Conflicts. ##
176 ## --------------------- ##
178 AT_SETUP([Solved SR Conflicts])
184 exp: exp OP exp | NUM;
187 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
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.
197 1 4 exp -> exp OP exp
201 Terminals, with rules where they appear
209 Nonterminals, with rules where they appear
212 on left: 1 2, on right: 1
217 NUM shift, and go to state 1
225 exp -> NUM . (rule 2)
227 $default reduce using rule 2 (exp)
233 exp -> exp . OP exp (rule 1)
236 OP shift, and go to state 3
242 exp -> exp OP . exp (rule 1)
244 NUM shift, and go to state 1
252 exp -> exp . OP exp (rule 1)
253 exp -> exp OP exp . (rule 1)
255 OP shift, and go to state 3
257 $default reduce using rule 1 (exp)
279 ## ------------------- ##
280 ## Rule Line Numbers. ##
281 ## ------------------- ##
283 AT_SETUP([Rule Line Numbers])
315 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
317 # Check the contents of the report.
318 AT_CHECK([cat input.output], [],
322 1 2 @1 -> /* empty */
323 2 2 expr -> 'a' @1 'b'
324 3 15 @2 -> /* empty */
328 Terminals, with rules where they appear
337 Nonterminals, with rules where they appear
342 on left: 1, on right: 2
344 on left: 3, on right: 4
349 'a' shift, and go to state 1
351 $default reduce using rule 3 (@2)
360 expr -> 'a' . @1 'b' (rule 2)
362 $default reduce using rule 1 (@1)
370 expr -> @2 . 'c' (rule 4)
372 'c' shift, and go to state 4
378 expr -> 'a' @1 . 'b' (rule 2)
380 'b' shift, and go to state 5
386 expr -> @2 'c' . (rule 4)
388 $default reduce using rule 4 (expr)
394 expr -> 'a' @1 'b' . (rule 2)
396 $default reduce using rule 2 (expr)
423 ## -------------------- ##
424 ## %expect not enough. ##
425 ## -------------------- ##
427 AT_SETUP([%expect not enough])
433 exp: exp OP exp | NUM;
436 AT_CHECK([bison input.y -o input.c], 1, [],
437 [input.y contains 1 shift/reduce conflict.
438 expected 0 shift/reduce conflicts
443 ## --------------- ##
445 ## --------------- ##
447 AT_SETUP([%expect right])
453 exp: exp OP exp | NUM;
456 AT_CHECK([bison input.y -o input.c], 0)
460 ## ------------------ ##
461 ## %expect too much. ##
462 ## ------------------ ##
464 AT_SETUP([%expect too much])
470 exp: exp OP exp | NUM;
473 AT_CHECK([bison input.y -o input.c], 1, [],
474 [input.y contains 1 shift/reduce conflict.
475 expected 2 shift/reduce conflicts
480 ## ---------------------- ##
481 ## Mixing %token styles. ##
482 ## ---------------------- ##
485 AT_SETUP([Mixing %token styles])
487 # Taken from the documentation.
489 [[%token <operator> OR "||"
490 %token <operator> LE 134 "<="
497 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
503 ## ---------------------- ##
504 ## %union and --defines. ##
505 ## ---------------------- ##
508 AT_SETUP([%union and --defines])
520 AT_CHECK([bison --defines union.y])
525 ## --------------------------------------- ##
526 ## Duplicate '/' in C comments in %union ##
527 ## --------------------------------------- ##
530 AT_SETUP([%union and C comments])
532 AT_DATA([union-comment.y],
535 /* The int. */ int integer;
536 /* The string. */ char *string ;
542 AT_CHECK([bison union-comment.y])
543 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
548 ## ----------------- ##
549 ## Invalid input 1. ##
550 ## ----------------- ##
553 AT_SETUP([Invalid input: 1])
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
568 ## ----------------- ##
569 ## Invalid input 2. ##
570 ## ----------------- ##
573 AT_SETUP([Invalid input: 2])
580 AT_CHECK([bison input.y], [1], [],
581 [[input.y:2: invalid input: `}'
588 ## -------------------- ##
589 ## Invalid %directive. ##
590 ## -------------------- ##
593 AT_SETUP([Invalid %directive])
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
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.
618 AT_SETUP([Web2c Report])
621 [[%token undef_id_tok const_id_tok
623 %start CONST_DEC_PART
632 | CONST_DEC_LIST CONST_DEC
636 { } undef_id_tok '=' const_id_tok ';'
642 AT_CHECK([bison -v input.y])
644 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
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
659 Nonterminals, with rules where they appear
663 on left: 2 3, on right: 1 3
665 on left: 5, on right: 2 3
667 on left: 4, on right: 5
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
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
682 CONST_DEC_LIST -> CONST_DEC . (rule 2)
683 $default reduce using rule 2 (CONST_DEC_LIST)
685 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
686 undef_id_tok shift, and go to state 5
688 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
689 $default reduce using rule 3 (CONST_DEC_LIST)
691 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
692 '=' shift, and go to state 6
694 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
695 const_id_tok shift, and go to state 7
697 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
698 ';' shift, and go to state 8
700 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
701 $default reduce using rule 5 (CONST_DEC)
713 ## --------------- ##
715 ## --------------- ##
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.
723 # It used to be wrong on yydefact only:
725 # static const short yydefact[] =
727 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
728 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
732 # but let's check all the tables.
735 AT_SETUP([Web2c Actions])
739 statement: struct_stat;
740 struct_stat: /* empty. */ | if else;
741 if: "if" "const" "then" statement;
742 else: "else" statement;
746 AT_CHECK([bison -v input.y -o input.c])
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[] =
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,
781 static const short yyprhs[] =
785 static const short yyrhs[] =
787 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
790 static const short yyrline[] =
794 static const char *const yytname[] =
796 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
797 "\"else\"", "statement", "struct_stat", "if", "else", NULL
799 static const short yyr1[] =
803 static const short yyr2[] =
807 static const short yydefact[] =
809 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
812 static const short yydefgoto[] =
816 static const short yypact[] =
818 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
821 static const short yypgoto[] =
823 0,-32768,-32768,-32768
825 static const short yytable[] =
827 10, 1, 5, 4, 11, 12, 7, 9
829 static const short yycheck[] =
831 0, 3, 6, 4, 0, 0, 5, 7