1 # Exercising Bison on conflicts. -*- Autotest -*-
3 # Copyright (C) 2002-2005, 2007-2015, 2018-2021 Free Software
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 AT_BANNER([[Conflicts.]])
21 ## ------------------------- ##
22 ## Token declaration order. ##
23 ## ------------------------- ##
25 # This test checks that token are declared left to right when in a precedence
28 AT_SETUP([Token declaration order])
30 AT_BISON_OPTION_PUSHDEFS
32 AT_DATA_GRAMMAR([[input.y]],
81 AT_BISON_CHECK([-o input.c input.y])
84 AT_PARSER_CHECK([input])
86 AT_BISON_OPTION_POPDEFS
91 ## --------------------------------------------------- ##
92 ## Token declaration order: literals vs. identifiers. ##
93 ## --------------------------------------------------- ##
95 # This test checks that when several tokens are declared by the same keyword,
96 # some of them defined as a character ('a'), others as simple textual reference
97 # (A), they are declared correctly left to right.
98 # Previously, the following test would declare the states in the order 'o' 'p'
99 # M N, instead of M N 'o' 'p'.
101 AT_SETUP([Token declaration order: literals vs. identifiers])
103 AT_BISON_OPTION_PUSHDEFS
104 AT_DATA_GRAMMAR([[input.y]],
130 AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
131 AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
134 0 $accept: . exp $end
152 'a' shift, and go to state 1
153 'b' shift, and go to state 2
154 C shift, and go to state 3
155 D shift, and go to state 4
156 E shift, and go to state 5
157 F shift, and go to state 6
158 'g' shift, and go to state 7
159 'h' shift, and go to state 8
160 'i' shift, and go to state 9
161 'j' shift, and go to state 10
162 K shift, and go to state 11
163 L shift, and go to state 12
164 M shift, and go to state 13
165 N shift, and go to state 14
166 'o' shift, and go to state 15
167 'p' shift, and go to state 16
175 AT_BISON_OPTION_POPDEFS
179 ## ------------------------------- ##
180 ## Useless associativity warning. ##
181 ## ------------------------------- ##
183 AT_SETUP([Useless associativity warning])
186 [[%token EQ "=" PL "+" ST "*" LP "("
205 AT_BISON_CHECK([-Wprecedence input.y], 0, [],
206 [[input.y:2.1-9: warning: useless precedence and associativity for "=" [-Wprecedence]
207 input.y:4.1-5: warning: useless associativity for "*", use %precedence [-Wprecedence]
208 input.y:5.1-11: warning: useless precedence for "(" [-Wprecedence]
214 ## ---------------------------- ##
215 ## Useless precedence warning. ##
216 ## ---------------------------- ##
218 AT_SETUP([Useless precedence warning])
221 [[%token A B U V W X Y Z
248 AT_BISON_CHECK([-Wprecedence -fcaret -o input.c input.y], 0, [],
249 [[input.y:7.1-9: warning: useless precedence and associativity for U [-Wprecedence]
252 input.y:6.1-6: warning: useless precedence and associativity for V [-Wprecedence]
255 input.y:5.1-5: warning: useless precedence and associativity for W [-Wprecedence]
258 input.y:2.1-11: warning: useless precedence for Z [-Wprecedence]
266 ## ---------------- ##
267 ## S/R in initial. ##
268 ## ---------------- ##
270 # I once hacked Bison in such a way that it lost its reductions on the
271 # initial state (because it was confusing it with the last state). It
272 # took me a while to strip down my failures to this simple case. So
273 # make sure it finds the s/r conflict below.
275 AT_SETUP([S/R in initial])
284 AT_BISON_CHECK([-o input.c input.y], 0, [],
285 [[input.y:4.10-15: warning: rule useless in parser due to conflicts [-Wother]
288 AT_BISON_CHECK([-fcaret -o input.c input.y], 0, [],
289 [[input.y:4.10-15: warning: rule useless in parser due to conflicts [-Wother]
297 ## ------------------- ##
298 ## %nonassoc and eof. ##
299 ## ------------------- ##
301 AT_SETUP([%nonassoc and eof])
303 AT_BISON_OPTION_PUSHDEFS
304 AT_DATA_GRAMMAR([input.y],
313 /* The current argument. */
314 static const char *input;
319 static size_t toknum;
320 assert (toknum <= strlen (input));
321 return input[toknum++];
326 %define parse.error verbose
337 main (int argc, const char *argv[])
339 input = argc <= 1 ? "" : argv[1];
343 AT_BISON_OPTION_POPDEFS
345 m4_pushdef([AT_NONASSOC_AND_EOF_CHECK],
346 [AT_BISON_CHECK([$1[ -o input.c input.y]])
349 m4_pushdef([AT_EXPECTING], [m4_if($2, [correct], [[, expecting end of file]])])
351 AT_PARSER_CHECK([input '0<0'])
352 AT_PARSER_CHECK([input '0<0<0'], [1], [],
353 [syntax error, unexpected '<'AT_EXPECTING
356 AT_PARSER_CHECK([input '0>0'])
357 AT_PARSER_CHECK([input '0>0>0'], [1], [],
358 [syntax error, unexpected '>'AT_EXPECTING
361 AT_PARSER_CHECK([input '0<0>0'], [1], [],
362 [syntax error, unexpected '>'AT_EXPECTING
365 m4_popdef([AT_EXPECTING])])
367 # Expected token list is missing.
368 AT_NONASSOC_AND_EOF_CHECK([], [[incorrect]])
370 # We must disable default reductions in inconsistent states in order to
371 # have an explicit list of all expected tokens.
372 AT_NONASSOC_AND_EOF_CHECK([[-Dlr.default-reduction=consistent]],
375 # lr.default-reduction=consistent happens to work for this test case.
376 # However, for other grammars, lookahead sets can be merged for
377 # different left contexts, so it is still possible to have an incorrect
378 # expected list. Canonical LR is almost a general solution (that is, it
379 # can fail only when %nonassoc is used), so make sure it gives the same
381 AT_NONASSOC_AND_EOF_CHECK([[-Dlr.type=canonical-lr]], [[correct]])
383 # parse.lac=full is a completely general solution that does not require
384 # any of the above sacrifices. Of course, it does not extend the
385 # language-recognition power of LALR to (IE)LR, but it does ensure that
386 # the reported list of expected tokens matches what the given parser
387 # would have accepted in place of the unexpected token.
388 AT_NONASSOC_AND_EOF_CHECK([[-Dparse.lac=full]], [[correct]])
390 m4_popdef([AT_NONASSOC_AND_EOF_CHECK])
396 ## ------------------------------------------- ##
397 ## parse.error=verbose and consistent errors. ##
398 ## ------------------------------------------- ##
400 AT_CONSISTENT_ERRORS_CHECK([BISON-DIRECTIVE],
403 [UNEXPECTED-TOKEN], [EXPECTED-TOKEN])
404 m4_pushdef([AT_CONSISTENT_ERRORS_CHECK], [
406 AT_SETUP([[parse.error=verbose and consistent errors: ]$1])
408 AT_BISON_OPTION_PUSHDEFS([$1 AT_CXX_IF([[%header]], [[%define api.pure]])])
410 AT_DATA_GRAMMAR([input.y],
414 import java.io.IOException;
424 ]AT_CXX_IF([[%header]], [[%define api.pure]])])[
428 #if defined __GNUC__ && 8 <= __GNUC__
429 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
436 %define parse.error verbose
442 ]AT_JAVA_IF([[%code lexer {
443 ]AT_YYLEX_DEFINE(["$3"], [[return new Integer(1)]])[
449 ]AT_YYLEX_DEFINE(["$3"], [[*lvalp = 1]])[
459 AT_FULL_COMPILE([[input]])
461 m4_pushdef([AT_EXPECTING], [m4_if($5, [ab], [[, expecting 'a' or 'b']],
462 $5, [a], [[, expecting 'a']],
463 $5, [b], [[, expecting 'b']])])
465 AT_PARSER_CHECK([[input]], [[1]],
467 [[syntax error, unexpected ]$4[]AT_EXPECTING[
470 m4_popdef([AT_EXPECTING])
471 AT_BISON_OPTION_POPDEFS
474 ]) dnl AT_CONSISTENT_ERRORS_CHECK
479 m4_pushdef([AT_PREVIOUS_STATE_GRAMMAR],
482 start: consistent-error-on-a-a 'a' ;
484 consistent-error-on-a-a:
485 'a' default-reduction
486 | 'a' default-reduction 'a'
490 default-reduction: %empty ;
493 // Provide another context in which all rules are useful so that this
494 // test case looks a little more realistic.
495 start: 'b' consistent-error-on-a-a 'c' ;
498 m4_pushdef([AT_PREVIOUS_STATE_INPUT], [[a]])
500 # Unfortunately, no expected tokens are reported even though 'b' can be
501 # accepted. Nevertheless, the main point of this test is to make sure
502 # that at least the unexpected token is reported. In a previous version
503 # of Bison, it wasn't reported because the error is detected in a
504 # consistent state with an error action, and that case always triggered
505 # the simple "syntax error" message.
507 # The point isn't to test IELR here, but state merging happens to
508 # complicate this example.
509 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr]],
510 [AT_PREVIOUS_STATE_GRAMMAR],
511 [AT_PREVIOUS_STATE_INPUT],
512 [[end of file]], [[none]])
513 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
515 [AT_PREVIOUS_STATE_GRAMMAR],
516 [AT_PREVIOUS_STATE_INPUT],
517 [[end of file]], [[none]])
518 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
520 [AT_PREVIOUS_STATE_GRAMMAR],
521 [AT_PREVIOUS_STATE_INPUT],
522 [[end of file]], [[none]])
523 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
525 [AT_PREVIOUS_STATE_GRAMMAR],
526 [AT_PREVIOUS_STATE_INPUT],
527 [[end of file]], [[none]])
529 # Even canonical LR doesn't foresee the error for 'a'!
530 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
531 %define lr.default-reduction consistent]],
532 [AT_PREVIOUS_STATE_GRAMMAR],
533 [AT_PREVIOUS_STATE_INPUT],
534 [[end of file]], [[ab]])
535 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
536 %define lr.default-reduction accepting]],
537 [AT_PREVIOUS_STATE_GRAMMAR],
538 [AT_PREVIOUS_STATE_INPUT],
539 [[end of file]], [[ab]])
540 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
541 [AT_PREVIOUS_STATE_GRAMMAR],
542 [AT_PREVIOUS_STATE_INPUT],
543 [[end of file]], [[ab]])
545 # Only LAC gets it right. In C.
546 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr
547 %define parse.lac full]],
548 [AT_PREVIOUS_STATE_GRAMMAR],
549 [AT_PREVIOUS_STATE_INPUT],
550 [[end of file]], [[b]])
551 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
552 %define parse.lac full]],
553 [AT_PREVIOUS_STATE_GRAMMAR],
554 [AT_PREVIOUS_STATE_INPUT],
555 [[end of file]], [[b]])
557 # Only LAC gets it right. In C++.
558 AT_CONSISTENT_ERRORS_CHECK([[%language "c++"
559 %define lr.type canonical-lr
560 %define parse.lac full]],
561 [AT_PREVIOUS_STATE_GRAMMAR],
562 [AT_PREVIOUS_STATE_INPUT],
563 [[end of file]], [[b]])
564 AT_CONSISTENT_ERRORS_CHECK([[%language "c++"
566 %define parse.lac full]],
567 [AT_PREVIOUS_STATE_GRAMMAR],
568 [AT_PREVIOUS_STATE_INPUT],
569 [[end of file]], [[b]])
571 m4_popdef([AT_PREVIOUS_STATE_GRAMMAR])
572 m4_popdef([AT_PREVIOUS_STATE_INPUT])
574 m4_pushdef([AT_USER_ACTION_GRAMMAR],
577 // If $$ = 0 here, then we know that the 'a' destructor is being invoked
578 // incorrectly for the 'b' set in the semantic action below. All 'a'
579 // tokens are returned by yylex, which sets $$ = 1.
582 fprintf (stderr, "Wrong destructor.\n");
585 // Rather than depend on an inconsistent state to induce reading a
586 // lookahead as in the previous grammar, just assign the lookahead in a
587 // semantic action. That lookahead isn't needed before either error
588 // action is encountered. In a previous version of Bison, this was a
589 // problem as it meant yychar was not translated into yytoken before
590 // either error action. The second error action thus invoked a
591 // destructor that it selected according to the incorrect yytoken. The
592 // first error action would have reported an incorrect unexpected token
593 // except that, due to the bug described in the previous grammar, the
594 // unexpected token was not reported at all.
595 start: error-reduce consistent-error 'a' { USE ($][3); } ;
598 'a' 'a' consistent-reduction consistent-error 'a'
599 { USE (($][1, $][2, $][5)); }
604 consistent-reduction: %empty
606 assert (yychar == YYEMPTY);
616 // Provide another context in which all rules are useful so that this
617 // test case looks a little more realistic.
618 start: 'b' consistent-error 'b' ;
620 m4_pushdef([AT_USER_ACTION_INPUT], [[aa]])
622 AT_CONSISTENT_ERRORS_CHECK([[]],
623 [AT_USER_ACTION_GRAMMAR],
624 [AT_USER_ACTION_INPUT],
626 AT_CONSISTENT_ERRORS_CHECK([[%glr-parser]],
627 [AT_USER_ACTION_GRAMMAR],
628 [AT_USER_ACTION_INPUT],
630 # No C++ or Java test because yychar cannot be manipulated by users.
632 AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reduction consistent]],
633 [AT_USER_ACTION_GRAMMAR],
634 [AT_USER_ACTION_INPUT],
637 # Canonical LR doesn't foresee the error for 'a'!
638 AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reduction accepting]],
639 [AT_USER_ACTION_GRAMMAR],
640 [AT_USER_ACTION_INPUT],
641 [[end of file]], [[a]])
642 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
643 [AT_USER_ACTION_GRAMMAR],
644 [AT_USER_ACTION_INPUT],
645 [[end of file]], [[a]])
647 AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full]],
648 [AT_USER_ACTION_GRAMMAR],
649 [AT_USER_ACTION_INPUT],
651 AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full
652 %define lr.default-reduction accepting]],
653 [AT_USER_ACTION_GRAMMAR],
654 [AT_USER_ACTION_INPUT],
655 [[end of file]], [[none]])
657 m4_popdef([AT_USER_ACTION_GRAMMAR])
658 m4_popdef([AT_USER_ACTION_INPUT])
660 m4_popdef([AT_CONSISTENT_ERRORS_CHECK])
665 ## ------------------------------------------------------- ##
666 ## LAC: %nonassoc requires splitting canonical LR states. ##
667 ## ------------------------------------------------------- ##
669 # This test case demonstrates that, when %nonassoc is used, canonical
670 # LR(1) parser table construction followed by conflict resolution
671 # without further state splitting is not always sufficient to produce a
672 # parser that can detect all syntax errors as soon as possible on one
673 # token of lookahead. However, LAC solves the problem completely even
674 # with minimal LR parser tables.
676 AT_SETUP([[LAC: %nonassoc requires splitting canonical LR states]])
677 AT_BISON_OPTION_PUSHDEFS
678 AT_DATA_GRAMMAR([[input.y]],
685 %define parse.error verbose
691 'a' problem 'a' // First context.
692 | 'b' problem 'b' // Second context.
693 | 'c' reduce-nonassoc // Just makes reduce-nonassoc useful.
702 // For the state reached after shifting the 'a' in these productions,
703 // lookahead sets are the same in both the first and second contexts.
704 // Thus, canonical LR reuses the same state for both contexts. However,
705 // the lookahead 'a' for the reduction "look: 'a'" later becomes an
706 // error action only in the first context. In order to immediately
707 // detect the syntax error on 'a' here for only the first context, this
708 // canonical LR state would have to be split into two states, and the
709 // 'a' lookahead would have to be removed from only one of the states.
711 'a' // Reduction lookahead set is always ['a', 'b'].
713 | 'a' 'c' // 'c' is forgotten as an expected token.
716 reduce-nonassoc: %prec 'a';
720 ]AT_YYLEX_DEFINE(["aaa"])[
723 AT_BISON_OPTION_POPDEFS
725 # Show canonical LR's failure.
726 AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]],
728 [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
729 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
731 AT_COMPILE([[input]])
732 AT_PARSER_CHECK([[input]], [[1]], [[]],
733 [[syntax error, unexpected 'a', expecting 'b'
736 # It's corrected by LAC.
737 AT_BISON_CHECK([[-Dlr.type=canonical-lr -Dparse.lac=full \
738 -o input.c input.y]], [[0]], [[]],
739 [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
740 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
742 AT_COMPILE([[input]])
743 AT_PARSER_CHECK([[input]], [[1]], [[]],
744 [[syntax error, unexpected 'a', expecting 'b' or 'c'
747 # IELR is sufficient when LAC is used.
748 AT_BISON_CHECK([[-Dlr.type=ielr -Dparse.lac=full -o input.c input.y]],
750 [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
751 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
753 AT_COMPILE([[input]])
754 AT_PARSER_CHECK([[input]], [[1]], [[]],
755 [[syntax error, unexpected 'a', expecting 'b' or 'c'
760 ## ------------------------- ##
761 ## Unresolved SR Conflicts. ##
762 ## ------------------------- ##
764 AT_SETUP([Unresolved SR Conflicts])
766 AT_KEYWORDS([cex report])
771 exp: exp OP exp | NUM;
774 AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
775 [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
776 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
779 # Check the contents of the report.
780 AT_CHECK([cat input.output], [],
781 [[State 5 conflicts: 1 shift/reduce
792 Terminals, with rules where they appear
800 Nonterminals, with rules where they appear
811 0 $accept: . exp $end
815 NUM shift, and go to state 1
824 $default reduce using rule 2 (exp)
829 0 $accept: exp . $end
832 $end shift, and go to state 3
833 OP shift, and go to state 4
838 0 $accept: exp $end .
849 NUM shift, and go to state 1
857 1 | exp OP exp . [$end, OP]
859 OP shift, and go to state 4
861 OP [reduce using rule 1 (exp)]
862 $default reduce using rule 1 (exp)
864 shift/reduce conflict on token OP:
867 Example: exp OP exp . OP exp
883 ## ----------------------- ##
884 ## Resolved SR Conflicts. ##
885 ## ----------------------- ##
887 AT_SETUP([Resolved SR Conflicts])
889 AT_KEYWORDS([report])
895 exp: exp OP exp | NUM;
898 AT_BISON_CHECK([-o input.c --report=all input.y])
900 # Check the contents of the report.
901 AT_CHECK([cat input.output], [],
910 Terminals, with rules where they appear
918 Nonterminals, with rules where they appear
929 0 $accept: . exp $end
933 NUM shift, and go to state 1
942 $default reduce using rule 2 (exp)
947 0 $accept: exp . $end
950 $end shift, and go to state 3
951 OP shift, and go to state 4
956 0 $accept: exp $end .
967 NUM shift, and go to state 1
975 1 | exp OP exp . [$end, OP]
977 $default reduce using rule 1 (exp)
979 Conflict between rule 1 and token OP resolved as reduce (%left OP).
985 ## ---------------------- ##
986 ## %precedence suffices. ##
987 ## ---------------------- ##
989 AT_SETUP([%precedence suffices])
996 "if" cond "then" stmt
997 | "if" cond "then" stmt "else" stmt
1006 AT_BISON_CHECK([-o input.c input.y])
1011 ## ------------------------------ ##
1012 ## %precedence does not suffice. ##
1013 ## ------------------------------ ##
1015 AT_SETUP([%precedence does not suffice])
1018 [[%precedence "then"
1022 "if" cond "then" stmt
1023 | "if" cond "then" stmt "else" stmt
1033 AT_BISON_CHECK([-o input.c input.y], 0, [],
1034 [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
1035 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1036 input.y:12.3-18: warning: rule useless in parser due to conflicts [-Wother]
1042 ## ---------------------------------------- ##
1043 ## Syntax error in consistent error state. ##
1044 ## ---------------------------------------- ##
1046 # AT_TEST(SKELETON-NAME)
1047 # ----------------------
1048 # Make sure yysyntax_error does nothing silly when called on yytoken
1051 m4_pushdef([AT_TEST],
1052 [AT_SETUP([Syntax error in consistent error state: $1])
1054 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1"])
1056 AT_DATA_GRAMMAR([input.y],
1057 [[%define parse.error verbose
1062 start: 'a' consistent-error-on-a-a 'a';
1064 consistent-error-on-a-a:
1065 'a' default-reduction
1066 | 'a' default-reduction 'a'
1069 default-reduction: %empty;
1073 ]AT_YYERROR_DECLARE[
1078 ]AT_YYLEX_DEFINE("aa")[
1082 AT_BISON_CHECK([-o input.AT_LANG_EXT input.y], 0, [],
1083 [[input.y:17.5-25: warning: rule useless in parser due to conflicts [-Wother]
1084 input.y:18.5-29: warning: rule useless in parser due to conflicts [-Wother]
1086 AT_LANG_COMPILE([input])
1087 AT_PARSER_CHECK([[input]], 1, [],
1091 AT_BISON_OPTION_POPDEFS
1095 ## FIXME: test Java and D.
1096 m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc], [glr2.cc])
1098 m4_popdef([AT_TEST])
1102 ## -------------------------------- ##
1103 ## Defaulted Conflicted Reduction. ##
1104 ## -------------------------------- ##
1106 # When there are RR conflicts, some rules are disabled. Usually it is
1107 # simply displayed as:
1109 # $end reduce using rule 3 (num)
1110 # $end [reduce using rule 4 (id)]
1112 # But when 'reduce 3' is the default action, we'd produce:
1114 # $end [reduce using rule 4 (id)]
1115 # $default reduce using rule 3 (num)
1117 # In this precise case (a reduction is masked by the default
1118 # reduction), we make the 'reduce 3' explicit:
1120 # $end reduce using rule 3 (num)
1121 # $end [reduce using rule 4 (id)]
1122 # $default reduce using rule 3 (num)
1124 # Maybe that's not the best display, but then, please propose something
1127 AT_SETUP([Defaulted Conflicted Reduction])
1128 AT_KEYWORDS([cex report])
1138 AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
1139 [[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1140 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1141 input.y:4.6-8: warning: rule useless in parser due to conflicts [-Wother]
1144 # Check the contents of the report.
1145 AT_CHECK([cat input.output], [],
1146 [[Rules useless in parser due to conflicts
1151 State 1 conflicts: 1 reduce/reduce
1166 Terminals, with rules where they appear
1173 Nonterminals, with rules where they appear
1190 0 $accept: . exp $end
1196 '0' shift, and go to state 1
1208 $end reduce using rule 3 (num)
1209 $end [reduce using rule 4 (id)]
1210 $default reduce using rule 3 (num)
1212 reduce/reduce conflict on token $end:
1216 First reduce derivation
1220 Second reduce derivation
1229 0 $accept: exp . $end
1231 $end shift, and go to state 5
1238 $default reduce using rule 1 (exp)
1245 $default reduce using rule 2 (exp)
1250 0 $accept: exp $end .
1260 ## -------------------- ##
1261 ## %expect not enough. ##
1262 ## -------------------- ##
1264 AT_SETUP([%expect not enough])
1270 exp: exp OP exp | NUM;
1273 AT_BISON_CHECK([-o input.c input.y], 1, [],
1274 [[input.y: error: shift/reduce conflicts: 1 found, 0 expected
1275 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1280 ## --------------- ##
1281 ## %expect right. ##
1282 ## --------------- ##
1284 AT_SETUP([%expect right])
1290 exp: exp OP exp | NUM;
1293 AT_BISON_CHECK([-o input.c input.y])
1297 ## ------------------ ##
1298 ## %expect too much. ##
1299 ## ------------------ ##
1301 AT_SETUP([%expect too much])
1307 exp: exp OP exp | NUM;
1310 AT_BISON_CHECK([-o input.c input.y], 1, [],
1311 [[input.y: error: shift/reduce conflicts: 1 found, 2 expected
1312 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1317 ## ------------------------------- ##
1318 ## %expect with reduce conflicts. ##
1319 ## ------------------------------- ##
1321 AT_SETUP([%expect with reduce conflicts])
1326 program: a 'a' | a a;
1330 AT_BISON_CHECK([-o input.c input.y], 1, [],
1331 [[input.y: error: reduce/reduce conflicts: 1 found, 0 expected
1332 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1337 ## ------------------------------------ ##
1338 ## %expect in grammar rule not enough. ##
1339 ## ------------------------------------ ##
1341 AT_SETUP([%expect in grammar rule not enough])
1347 exp: exp OP exp %expect 0 | NUM;
1350 AT_BISON_CHECK([-o input.c input.y], 1, [],
1351 [[input.y:4.6-25: error: shift/reduce conflicts for rule 1: 1 found, 0 expected
1356 ## ------------------------------- ##
1357 ## %expect in grammar rule right. ##
1358 ## ------------------------------- ##
1360 AT_SETUP([%expect in grammar rule right])
1366 exp: exp OP exp %expect 1 | NUM;
1369 AT_BISON_CHECK([-o input.c input.y])
1373 ## -------------------------- ##
1374 ## %expect in grammar rules. ##
1375 ## -------------------------- ##
1377 AT_SETUP([%expect in grammar rules])
1384 | exp "+" exp %expect 2
1385 | exp "*" exp %expect 2
1388 AT_BISON_CHECK([-o input.c -rall input.y])
1392 ## ---------------------------------- ##
1393 ## %expect in grammar rule too much. ##
1394 ## ---------------------------------- ##
1396 AT_SETUP([%expect in grammar rule too much])
1402 exp: exp OP exp | NUM %expect 1;
1405 AT_BISON_CHECK([-o input.c input.y], 1, [],
1406 [[input.y:4.19-31: error: shift/reduce conflicts for rule 2: 0 found, 1 expected
1411 ## ---------------------------- ##
1412 ## %expect-rr in grammar rule. ##
1413 ## ---------------------------- ##
1415 AT_SETUP([%expect-rr in grammar rule])
1432 AT_BISON_CHECK([-o input.c input.y])
1436 ## ------------------------------------- ##
1437 ## %expect-rr too much in grammar rule. ##
1438 ## ------------------------------------- ##
1440 AT_SETUP([%expect-rr too much in grammar rule])
1457 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
1458 [[input.y:12.4-15: error: reduce/reduce conflicts for rule 8: 3 found, 4 expected
1459 12 | b: %expect-rr 4
1465 ## --------------------------------------- ##
1466 ## %expect-rr not enough in grammar rule. ##
1467 ## --------------------------------------- ##
1469 AT_SETUP([%expect-rr not enough in grammar rule])
1486 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
1487 [[input.y:12.4-15: error: reduce/reduce conflicts for rule 8: 3 found, 2 expected
1488 12 | b: %expect-rr 2
1494 ## ------------------------- ##
1495 ## %prec with user strings. ##
1496 ## ------------------------- ##
1498 AT_SETUP([%prec with user string])
1500 AT_DATA([[input.y]],
1507 AT_BISON_CHECK([-o input.c input.y])
1511 ## -------------------------------- ##
1512 ## %no-default-prec without %prec. ##
1513 ## -------------------------------- ##
1515 AT_SETUP([%no-default-prec without %prec])
1517 AT_DATA([[input.y]],
1531 AT_BISON_CHECK([-Wall -o input.c input.y], 0, [],
1532 [[input.y: warning: 4 shift/reduce conflicts [-Wconflicts-sr]
1533 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1534 input.y:1.1-5: warning: useless precedence and associativity for '+' [-Wprecedence]
1535 input.y:2.1-5: warning: useless precedence and associativity for '*' [-Wprecedence]
1540 ## ----------------------------- ##
1541 ## %no-default-prec with %prec. ##
1542 ## ----------------------------- ##
1544 AT_SETUP([%no-default-prec with %prec])
1546 AT_DATA([[input.y]],
1554 e: e '+' e %prec '+'
1560 AT_BISON_CHECK([-o input.c input.y])
1564 ## --------------- ##
1565 ## %default-prec. ##
1566 ## --------------- ##
1568 AT_SETUP([%default-prec])
1570 AT_DATA([[input.y]],
1584 AT_BISON_CHECK([-o input.c input.y])
1588 ## ---------------------------------------------- ##
1589 ## Unreachable States After Conflict Resolution. ##
1590 ## ---------------------------------------------- ##
1592 AT_SETUP([[Unreachable States After Conflict Resolution]])
1594 AT_KEYWORDS([cex report])
1596 # If conflict resolution makes states unreachable, remove those states, report
1597 # rules that are then unused, and don't report conflicts in those states. Test
1598 # what happens when a nonterminal becomes useless as a result of state removal
1599 # since that causes lalr.o's goto map to be rewritten.
1601 AT_DATA([[input.y]],
1607 start: resolved_conflict 'a' reported_conflicts 'a' ;
1609 /* S/R conflict resolved as reduce, so the state with item
1610 * (resolved_conflict: 'a' . unreachable1) and all it transition successors are
1611 * unreachable, and the associated production is useless. */
1617 /* S/R conflict that need not be reported since it is unreachable because of
1618 * the previous conflict resolution. Nonterminal unreachable1 and all its
1619 * productions are useless. */
1625 /* Likewise for a R/R conflict and nonterminal unreachable2. */
1628 /* Make sure remaining S/R and R/R conflicts are still reported correctly even
1629 * when their states are renumbered due to state removal. */
1638 AT_BISON_CHECK([[--report=all input.y]], 0, [],
1639 [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
1640 input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1641 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1642 input.y:12.5-20: warning: rule useless in parser due to conflicts [-Wother]
1643 input.y:20.5-20: warning: rule useless in parser due to conflicts [-Wother]
1644 input.y:21.4: warning: rule useless in parser due to conflicts [-Wother]
1645 input.y:25.14: warning: rule useless in parser due to conflicts [-Wother]
1646 input.y:25.16: warning: rule useless in parser due to conflicts [-Wother]
1647 input.y:31.5-7: warning: rule useless in parser due to conflicts [-Wother]
1648 input.y:32.4: warning: rule useless in parser due to conflicts [-Wother]
1651 AT_CHECK([[cat input.output]], 0,
1652 [[Rules useless in parser due to conflicts
1654 2 resolved_conflict: 'a' unreachable1
1656 4 unreachable1: 'a' unreachable2
1659 6 unreachable2: %empty
1662 9 reported_conflicts: 'a'
1666 State 4 conflicts: 1 shift/reduce
1667 State 5 conflicts: 1 reduce/reduce
1672 0 $accept: start $end
1674 1 start: resolved_conflict 'a' reported_conflicts 'a'
1676 2 resolved_conflict: 'a' unreachable1
1679 4 unreachable1: 'a' unreachable2
1682 6 unreachable2: %empty
1685 8 reported_conflicts: 'a'
1690 Terminals, with rules where they appear
1697 Nonterminals, with rules where they appear
1704 resolved_conflict (6)
1713 reported_conflicts (9)
1720 0 $accept: . start $end
1721 1 start: . resolved_conflict 'a' reported_conflicts 'a'
1722 2 resolved_conflict: . 'a' unreachable1
1725 $default reduce using rule 3 (resolved_conflict)
1728 resolved_conflict go to state 2
1730 Conflict between rule 3 and token 'a' resolved as reduce (%left 'a').
1735 0 $accept: start . $end
1737 $end shift, and go to state 3
1742 1 start: resolved_conflict . 'a' reported_conflicts 'a'
1744 'a' shift, and go to state 4
1749 0 $accept: start $end .
1756 1 start: resolved_conflict 'a' . reported_conflicts 'a'
1757 8 reported_conflicts: . 'a'
1761 'a' shift, and go to state 5
1763 'a' [reduce using rule 10 (reported_conflicts)]
1765 reported_conflicts go to state 6
1767 shift/reduce conflict on token 'a':
1768 10 reported_conflicts: %empty .
1769 8 reported_conflicts: . 'a'
1770 First example: resolved_conflict . 'a' 'a'
1773 `-> 1: resolved_conflict reported_conflicts 'a'
1775 Second example: resolved_conflict . 'a'
1778 `-> 1: resolved_conflict reported_conflicts 'a'
1781 shift/reduce conflict on token 'a':
1782 10 reported_conflicts: %empty .
1783 9 reported_conflicts: . 'a'
1784 First example: resolved_conflict . 'a' 'a'
1787 `-> 1: resolved_conflict reported_conflicts 'a'
1789 Second example: resolved_conflict . 'a'
1792 `-> 1: resolved_conflict reported_conflicts 'a'
1799 8 reported_conflicts: 'a' . ['a']
1802 'a' reduce using rule 8 (reported_conflicts)
1803 'a' [reduce using rule 9 (reported_conflicts)]
1804 $default reduce using rule 8 (reported_conflicts)
1806 reduce/reduce conflict on token 'a':
1807 8 reported_conflicts: 'a' .
1808 9 reported_conflicts: 'a' .
1810 First reduce derivation
1813 Second reduce derivation
1821 1 start: resolved_conflict 'a' reported_conflicts . 'a'
1823 'a' shift, and go to state 7
1828 1 start: resolved_conflict 'a' reported_conflicts 'a' .
1830 $default reduce using rule 1 (start)
1833 AT_DATA([[input-keep.y]],
1834 [[%define lr.keep-unreachable-state
1836 AT_CHECK([[cat input.y >> input-keep.y]])
1838 AT_BISON_CHECK([[input-keep.y]], 0, [],
1839 [[input-keep.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
1840 input-keep.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
1841 input-keep.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1842 input-keep.y:22.4: warning: rule useless in parser due to conflicts [-Wother]
1843 input-keep.y:26.16: warning: rule useless in parser due to conflicts [-Wother]
1844 input-keep.y:32.5-7: warning: rule useless in parser due to conflicts [-Wother]
1845 input-keep.y:33.4: warning: rule useless in parser due to conflicts [-Wother]
1851 ## ------------------------------------------------------------ ##
1852 ## Solved conflicts report for multiple reductions in a state. ##
1853 ## ------------------------------------------------------------ ##
1855 AT_SETUP([[Solved conflicts report for multiple reductions in a state]])
1857 # Used to lose earlier solved conflict messages even within a single S/R/R.
1859 AT_DATA([[input.y]],
1875 empty_a: %empty %prec 'a' ;
1876 empty_b: %empty %prec 'b' ;
1877 empty_c1: %empty %prec 'c' ;
1878 empty_c2: %empty %prec 'c' ;
1879 empty_c3: %empty %prec 'd' ;
1881 AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
1882 AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
1885 0 $accept: . start $end
1894 9 empty_a: %empty . ['a']
1895 10 empty_b: %empty . []
1896 11 empty_c1: %empty . []
1897 12 empty_c2: %empty . []
1898 13 empty_c3: %empty . ['c']
1900 'b' shift, and go to state 1
1902 'c' reduce using rule 13 (empty_c3)
1903 $default reduce using rule 9 (empty_a)
1906 empty_a go to state 3
1907 empty_b go to state 4
1908 empty_c1 go to state 5
1909 empty_c2 go to state 6
1910 empty_c3 go to state 7
1912 Conflict between rule 9 and token 'a' resolved as reduce (%left 'a').
1913 Conflict between rule 10 and token 'b' resolved as shift (%right 'b').
1914 Conflict between rule 11 and token 'c' resolved as shift (%right 'c').
1915 Conflict between rule 12 and token 'c' resolved as shift (%right 'c').
1916 Conflict between rule 13 and token 'c' resolved as reduce ('c' < 'd').
1925 ## ------------------------------------------------------------ ##
1926 ## %nonassoc error actions for multiple reductions in a state. ##
1927 ## ------------------------------------------------------------ ##
1929 # Used to abort when trying to resolve conflicts as %nonassoc error actions for
1930 # multiple reductions in a state.
1932 # For a %nonassoc error action token, used to print the first remaining
1933 # reduction on that token without brackets.
1935 AT_SETUP([[%nonassoc error actions for multiple reductions in a state]])
1937 AT_KEYWORDS([cex report])
1939 AT_DATA([[input.y]],
1940 [[%nonassoc 'a' 'b' 'c'
1952 empty_a: %prec 'a' ;
1953 empty_b: %prec 'b' ;
1954 empty_c1: %prec 'c' ;
1955 empty_c2: %prec 'c' ;
1956 empty_c3: %prec 'c' ;
1959 AT_BISON_CHECK([[--trace=cex -fcaret --report=all -o input.c input.y]], 0, [],
1960 [[bison (GNU Bison) ]AT_PACKAGE_VERSION[
1964 0 $accept: . start $end
1965 -> 0 $accept: start . $end
1966 => 2 start: . empty_a 'a'
1967 => 4 start: . empty_b 'b'
1968 => 6 start: . empty_c1 'c'
1969 => 7 start: . empty_c2 'c'
1970 => 8 start: . empty_c3 'c'
1972 1 start: . 'a' DISABLED
1974 2 start: . empty_a 'a'
1975 -> 2 start: empty_a . 'a'
1976 => 9 empty_a: %empty .
1977 <- 0 $accept: . start $end
1979 3 start: . 'b' DISABLED
1981 4 start: . empty_b 'b'
1982 -> 4 start: empty_b . 'b'
1983 => 10 empty_b: %empty .
1984 <- 0 $accept: . start $end
1986 5 start: . 'c' DISABLED
1988 6 start: . empty_c1 'c'
1989 -> 6 start: empty_c1 . 'c'
1990 => 11 empty_c1: %empty .
1991 <- 0 $accept: . start $end
1993 7 start: . empty_c2 'c'
1994 -> 7 start: empty_c2 . 'c'
1995 => 12 empty_c2: %empty .
1996 <- 0 $accept: . start $end
1998 8 start: . empty_c3 'c'
1999 -> 8 start: empty_c3 . 'c'
2000 => 13 empty_c3: %empty .
2001 <- 0 $accept: . start $end
2004 <- 2 start: . empty_a 'a'
2006 10 empty_b: %empty .
2007 <- 4 start: . empty_b 'b'
2009 11 empty_c1: %empty .
2010 <- 6 start: . empty_c1 'c'
2012 12 empty_c2: %empty .
2013 <- 7 start: . empty_c2 'c'
2015 13 empty_c3: %empty .
2016 <- 8 start: . empty_c3 'c'
2019 0 $accept: start . $end
2020 -> 0 $accept: start $end .
2021 <- 0 $accept: . start $end
2024 2 start: empty_a . 'a'
2025 -> 2 start: empty_a 'a' .
2026 <- 2 start: . empty_a 'a'
2029 4 start: empty_b . 'b'
2030 -> 4 start: empty_b 'b' .
2031 <- 4 start: . empty_b 'b'
2034 6 start: empty_c1 . 'c'
2035 -> 6 start: empty_c1 'c' .
2036 <- 6 start: . empty_c1 'c'
2039 7 start: empty_c2 . 'c'
2040 -> 7 start: empty_c2 'c' .
2041 <- 7 start: . empty_c2 'c'
2044 8 start: empty_c3 . 'c'
2045 -> 8 start: empty_c3 'c' .
2046 <- 8 start: . empty_c3 'c'
2049 0 $accept: start $end .
2050 <- 0 $accept: start . $end
2053 2 start: empty_a 'a' .
2054 <- 2 start: empty_a . 'a'
2057 4 start: empty_b 'b' .
2058 <- 4 start: empty_b . 'b'
2061 6 start: empty_c1 'c' .
2062 <- 6 start: empty_c1 . 'c'
2065 7 start: empty_c2 'c' .
2066 <- 7 start: empty_c2 . 'c'
2069 8 start: empty_c3 'c' .
2070 <- 8 start: empty_c3 . 'c'
2088 input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2089 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
2090 input.y:4.5-7: warning: rule useless in parser due to conflicts [-Wother]
2093 input.y:6.5-7: warning: rule useless in parser due to conflicts [-Wother]
2096 input.y:8.5-7: warning: rule useless in parser due to conflicts [-Wother]
2099 input.y:13.10-18: warning: rule useless in parser due to conflicts [-Wother]
2100 13 | empty_a: %prec 'a' ;
2102 input.y:14.10-18: warning: rule useless in parser due to conflicts [-Wother]
2103 14 | empty_b: %prec 'b' ;
2105 input.y:15.11-19: warning: rule useless in parser due to conflicts [-Wother]
2106 15 | empty_c1: %prec 'c' ;
2108 input.y:16.11-19: warning: rule useless in parser due to conflicts [-Wother]
2109 16 | empty_c2: %prec 'c' ;
2111 input.y:17.11-19: warning: rule useless in parser due to conflicts [-Wother]
2112 17 | empty_c3: %prec 'c' ;
2115 0 $accept: . start $end
2116 7 start: . empty_c2 'c'
2117 12 empty_c2: %empty .
2118 CONFLICT 1 (size 1 depth 0 rc 2)
2119 12 empty_c2: %empty .
2120 12 empty_c2: %empty .
2124 CONFLICT 2 (size 1 depth 0 rc 2)
2125 13 empty_c3: %empty .
2126 13 empty_c3: %empty .
2131 CONFLICT 1 (size 2 depth -1 rc 4)
2132 7 start: . empty_c2 'c'
2133 7 start: empty_c2 . 'c'
2138 CONFLICT 2 (size 1 depth 0 rc 3)
2139 13 empty_c3: %empty .
2140 13 empty_c3: %empty .
2145 CONFLICT 1 (size 1 depth 0 rc 3)
2146 12 empty_c2: %empty .
2147 12 empty_c2: %empty .
2151 CONFLICT 2 (size 2 depth -1 rc 2)
2152 8 start: . empty_c3 'c'
2153 8 start: empty_c3 . 'c'
2159 CONFLICT 1 (size 2 depth -1 rc 3)
2160 7 start: . empty_c2 'c'
2161 7 start: empty_c2 . 'c'
2166 CONFLICT 2 (size 2 depth -1 rc 2)
2167 8 start: . empty_c3 'c'
2168 8 start: empty_c3 . 'c'
2174 CONFLICT 1 (size 3 depth -1 rc 2)
2175 7 start: . empty_c2 'c'
2176 7 start: empty_c2 'c' .
2181 CONFLICT 2 (size 3 depth -1 rc 2)
2182 8 start: . empty_c3 'c'
2183 8 start: empty_c3 'c' .
2189 CONFLICT 1 (size 2 depth -1 rc 4)
2190 0 $accept: . start $end
2191 0 $accept: start . $end
2197 CONFLICT 2 (size 3 depth -1 rc 3)
2198 8 start: . empty_c3 'c'
2199 8 start: empty_c3 'c' .
2205 CONFLICT 1 (size 3 depth -1 rc 3)
2206 7 start: . empty_c2 'c'
2207 7 start: empty_c2 'c' .
2212 CONFLICT 2 (size 2 depth -1 rc 2)
2213 0 $accept: . start $end
2214 0 $accept: start . $end
2221 CONFLICT 1 (size 2 depth -1 rc 3)
2222 0 $accept: . start $end
2223 0 $accept: start . $end
2229 CONFLICT 2 (size 2 depth -1 rc 2)
2230 0 $accept: . start $end
2231 0 $accept: start . $end
2239 AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
2242 0 $accept: . start $end
2251 9 empty_a: %empty . []
2252 10 empty_b: %empty . []
2253 11 empty_c1: %empty . []
2254 12 empty_c2: %empty . ['c']
2255 13 empty_c3: %empty . ['c']
2257 'a' error (nonassociative)
2258 'b' error (nonassociative)
2259 'c' error (nonassociative)
2261 'c' [reduce using rule 12 (empty_c2)]
2262 'c' [reduce using rule 13 (empty_c3)]
2265 empty_a go to state 2
2266 empty_b go to state 3
2267 empty_c1 go to state 4
2268 empty_c2 go to state 5
2269 empty_c3 go to state 6
2271 Conflict between rule 9 and token 'a' resolved as an error (%nonassoc 'a').
2272 Conflict between rule 10 and token 'b' resolved as an error (%nonassoc 'b').
2273 Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c').
2275 reduce/reduce conflict on token 'c':
2276 12 empty_c2: %empty .
2277 13 empty_c3: %empty .
2279 First reduce derivation
2283 Second reduce derivation
2295 ## -------------------- ##
2296 ## %expect-rr non GLR. ##
2297 ## -------------------- ##
2299 AT_SETUP([[%expect-rr non GLR]])
2307 AT_BISON_CHECK([[1.y]], [[0]], [],
2308 [[1.y: warning: %expect-rr applies only to GLR parsers [-Wother]
2317 AT_BISON_CHECK([[2.y]], [[0]], [],
2318 [[2.y: warning: %expect-rr applies only to GLR parsers [-Wother]
2319 2.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2320 2.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
2321 2.y:3.12-14: warning: rule useless in parser due to conflicts [-Wother]
2327 ## ---------------------------------- ##
2328 ## -W versus %expect and %expect-rr. ##
2329 ## ---------------------------------- ##
2331 AT_SETUP([[-W versus %expect and %expect-rr]])
2333 AT_DATA([[sr-rr.y]],
2336 start: 'a' | A 'a' | B 'a' ;
2343 start: 'a' | A 'a' ;
2354 AT_BISON_CHECK([[sr-rr.y]], [[0]], [[]],
2355 [[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
2356 sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2357 sr-rr.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
2359 AT_BISON_CHECK([[-Wno-conflicts-sr sr-rr.y]], [[0]], [[]],
2360 [[sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2361 sr-rr.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
2363 AT_BISON_CHECK([[-Wno-conflicts-rr sr-rr.y]], [[0]], [[]],
2364 [[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
2368 # This is piece of code is rather complex for a simple task: try every
2369 # combination of (0 or 1 real SR) x (0 or 1 real RR) x (don't %expect
2370 # or %expect 0, 1, or 2 SR) x (don't %expect-rr or %expect-rr 0, 1, or 2
2373 # Number and types of genuine conflicts in the grammar.
2374 for gram in sr-rr sr rr; do
2375 # Number of expected s/r conflicts.
2376 for sr_exp_i in '' 0 1 2; do
2377 # Number of expected r/r conflicts.
2378 for rr_exp_i in '' 0 1 2; do
2379 test -z "$sr_exp_i" && test -z "$rr_exp_i" && continue
2381 # Build grammar file.
2386 if test -n "$sr_exp_i"; then
2388 file=$file-expect-$sr_exp
2389 directives="%expect $sr_exp"
2391 if test -n "$rr_exp_i"; then
2393 file=$file-expect-rr-$rr_exp
2394 directives="$directives %expect-rr $rr_exp"
2397 echo "$directives" > $file
2398 cat $gram.y >> $file
2400 # Number of found conflicts.
2402 (sr) sr_count=1; rr_count=0;;
2403 (rr) sr_count=0; rr_count=1;;
2404 (sr-rr) sr_count=1; rr_count=1;;
2407 # Update number of expected conflicts: if %expect is given then
2408 # %expect-rr defaults to 0, and vice-versa. Leave empty if
2410 case $sr_exp_i:$rr_exp_i in
2416 if test $sr_count -eq $sr_exp && test $rr_count -eq $rr_exp; then
2417 ]AT_BISON_CHECK([[-Wnone $file]])[
2418 ]AT_BISON_CHECK([[-Werror $file]])[
2422 if test -z "$sr_exp_i" && test "$sr_count" -ne 0; then
2423 echo "warning: $sr_count shift/reduce conflicts"
2425 elif test "$sr_exp_i" -ne "$sr_count"; then
2426 echo "error: shift/reduce conflicts: $sr_count found, $sr_exp_i expected"
2427 if test "$sr_count" -ne 0; then
2431 if test -z "$rr_exp_i" && test "$rr_count" -ne 0; then
2432 echo "warning: $rr_count reduce/reduce conflicts"
2434 elif test "$rr_exp_i" -ne "$rr_count"; then
2435 echo "error: reduce/reduce conflicts: $rr_count found, $rr_exp_i expected"
2436 if test "$rr_count" -ne 0; then
2440 if $issue_note; then
2441 echo "note: rerun with option '-Wcounterexamples' to generate conflict counterexamples"
2443 } | sed -e "s/^/$file: /" > experr
2444 ]AT_BISON_CHECK([[-Wnone $file]], [[1]], [[]], [[experr]])[
2445 ]AT_BISON_CHECK([[-Werror $file]], [[1]], [[]], [[experr]])[