1 # Exercising Bison on conflicts. -*- Autotest -*-
3 # Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free
4 # Software Foundation, Inc.
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 <http://www.gnu.org/licenses/>.
19 AT_BANNER([[Conflicts.]])
22 ## ---------------- ##
24 ## ---------------- ##
26 # I once hacked Bison in such a way that it lost its reductions on the
27 # initial state (because it was confusing it with the last state). It
28 # took me a while to strip down my failures to this simple case. So
29 # make sure it finds the s/r conflict below.
31 AT_SETUP([S/R in initial])
37 e: 'e' | /* Nothing. */;
40 AT_BISON_CHECK([-o input.c input.y], 0, [],
41 [[input.y:4.9: warning: rule useless in parser due to conflicts: e: /* empty */
47 ## ------------------- ##
48 ## %nonassoc and eof. ##
49 ## ------------------- ##
51 AT_SETUP([%nonassoc and eof])
53 AT_DATA_GRAMMAR([input.y],
60 #define YYERROR_VERBOSE 1
62 yyerror (const char *msg)
64 fprintf (stderr, "%s\n", msg);
67 /* The current argument. */
68 static const char *input;
74 if (! (toknum <= strlen (input)))
76 return input[toknum++];
90 main (int argc, const char *argv[])
92 input = argc <= 1 ? "" : argv[1];
97 m4_pushdef([AT_NONASSOC_AND_EOF_CHECK],
98 [AT_BISON_CHECK([$1[ -o input.c input.y]])
101 m4_pushdef([AT_EXPECTING], [m4_if($2, [correct], [[, expecting $end]])])
103 AT_PARSER_CHECK([./input '0<0'])
104 AT_PARSER_CHECK([./input '0<0<0'], [1], [],
105 [syntax error, unexpected '<'AT_EXPECTING
108 AT_PARSER_CHECK([./input '0>0'])
109 AT_PARSER_CHECK([./input '0>0>0'], [1], [],
110 [syntax error, unexpected '>'AT_EXPECTING
113 AT_PARSER_CHECK([./input '0<0>0'], [1], [],
114 [syntax error, unexpected '>'AT_EXPECTING
117 m4_popdef([AT_EXPECTING])])
119 # Expected token list is missing.
120 AT_NONASSOC_AND_EOF_CHECK([], [[incorrect]])
122 # We must disable default reductions in inconsistent states in order to
123 # have an explicit list of all expected tokens.
124 AT_NONASSOC_AND_EOF_CHECK([[-Dlr.default-reductions=consistent]],
127 # lr.default-reductions=consistent happens to work for this test case.
128 # However, for other grammars, lookahead sets can be merged for
129 # different left contexts, so it is still possible to have an incorrect
130 # expected list. Canonical LR is almost a general solution (that is, it
131 # can fail only when %nonassoc is used), so make sure it gives the same
133 AT_NONASSOC_AND_EOF_CHECK([[-Dlr.type=canonical-lr]], [[correct]])
135 # parse.lac=full is a completely general solution that does not require
136 # any of the above sacrifices. Of course, it does not extend the
137 # language-recognition power of LALR to (IE)LR, but it does ensure that
138 # the reported list of expected tokens matches what the given parser
139 # would have accepted in place of the unexpected token.
140 AT_NONASSOC_AND_EOF_CHECK([[-Dparse.lac=full]], [[correct]])
142 m4_popdef([AT_NONASSOC_AND_EOF_CHECK])
148 ## ------------------------------------------- ##
149 ## parse.error=verbose and consistent errors. ##
150 ## ------------------------------------------- ##
152 AT_SETUP([[parse.error=verbose and consistent errors]])
154 m4_pushdef([AT_CONSISTENT_ERRORS_CHECK], [
156 AT_BISON_OPTION_PUSHDEFS([$1])
158 m4_pushdef([AT_YYLEX_PROTOTYPE],
159 [AT_SKEL_CC_IF([[int yylex (yy::parser::semantic_type *lvalp)]],
160 [[int yylex (YYSTYPE *lvalp)]])])
162 AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
166 import java.io.IOException;
169 %code {]AT_SKEL_CC_IF([[
170 #include <string>]], [[
173 void yyerror (char const *msg);]])[
174 ]AT_YYLEX_PROTOTYPE[;
178 ]AT_SKEL_CC_IF([[%defines]], [[%define api.pure]])])[
182 %define parse.error verbose
188 ]AT_SKEL_JAVA_IF([[%code lexer {]], [[%%]])[
192 `--------*/]AT_SKEL_JAVA_IF([[
194 public String input = "]$3[";
195 public int index = 0;
198 if (index < input.length ())
199 return input.charAt (index++);
203 public Object getLVal ()
205 return new Integer(1);
210 static char const *input = "]$3[";
217 `----------*/]AT_SKEL_JAVA_IF([[
219 public void yyerror (String msg)
221 System.err.println (msg);
226 %%]], [AT_SKEL_CC_IF([[
229 yy::parser::error (std::string const &msg)
231 std::cerr << msg << std::endl;
235 yyerror (char const *msg)
237 fprintf (stderr, "%s\n", msg);
242 `-------*/]AT_SKEL_JAVA_IF([[
246 public static void main (String args[]) throws IOException
248 YYParser p = new YYParser ();
251 }]], [AT_SKEL_CC_IF([[
257 return parser.parse ();
267 AT_FULL_COMPILE([[input]])
269 m4_pushdef([AT_EXPECTING], [m4_if($5, [ab], [[, expecting 'a' or 'b']],
270 $5, [a], [[, expecting 'a']],
271 $5, [b], [[, expecting 'b']])])
273 AT_SKEL_JAVA_IF([AT_JAVA_PARSER_CHECK([[input]], [[0]]],
274 [AT_PARSER_CHECK([[./input]], [[1]]]),
276 [[syntax error, unexpected ]$4[]AT_EXPECTING[
279 m4_popdef([AT_EXPECTING])
280 m4_popdef([AT_YYLEX_PROTOTYPE])
281 AT_BISON_OPTION_POPDEFS
285 m4_pushdef([AT_PREVIOUS_STATE_GRAMMAR],
288 start: consistent-error-on-a-a 'a' ;
290 consistent-error-on-a-a:
291 'a' default-reduction
292 | 'a' default-reduction 'a'
296 default-reduction: /*empty*/ ;
299 // Provide another context in which all rules are useful so that this
300 // test case looks a little more realistic.
301 start: 'b' consistent-error-on-a-a 'c' ;
304 m4_pushdef([AT_PREVIOUS_STATE_INPUT], [[a]])
306 # Unfortunately, no expected tokens are reported even though 'b' can be
307 # accepted. Nevertheless, the main point of this test is to make sure
308 # that at least the unexpected token is reported. In a previous version
309 # of Bison, it wasn't reported because the error is detected in a
310 # consistent state with an error action, and that case always triggered
311 # the simple "syntax error" message.
313 # The point isn't to test IELR here, but state merging happens to
314 # complicate this example.
315 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr]],
316 [AT_PREVIOUS_STATE_GRAMMAR],
317 [AT_PREVIOUS_STATE_INPUT],
319 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
321 [AT_PREVIOUS_STATE_GRAMMAR],
322 [AT_PREVIOUS_STATE_INPUT],
324 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
326 [AT_PREVIOUS_STATE_GRAMMAR],
327 [AT_PREVIOUS_STATE_INPUT],
329 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
331 [AT_PREVIOUS_STATE_GRAMMAR],
332 [AT_PREVIOUS_STATE_INPUT],
333 [[end of input]], [[none]])
335 # Even canonical LR doesn't foresee the error for 'a'!
336 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
337 %define lr.default-reductions consistent]],
338 [AT_PREVIOUS_STATE_GRAMMAR],
339 [AT_PREVIOUS_STATE_INPUT],
341 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
342 %define lr.default-reductions accepting]],
343 [AT_PREVIOUS_STATE_GRAMMAR],
344 [AT_PREVIOUS_STATE_INPUT],
346 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
347 [AT_PREVIOUS_STATE_GRAMMAR],
348 [AT_PREVIOUS_STATE_INPUT],
351 # Only LAC gets it right.
352 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr
353 %define parse.lac full]],
354 [AT_PREVIOUS_STATE_GRAMMAR],
355 [AT_PREVIOUS_STATE_INPUT],
357 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
358 %define parse.lac full]],
359 [AT_PREVIOUS_STATE_GRAMMAR],
360 [AT_PREVIOUS_STATE_INPUT],
363 m4_popdef([AT_PREVIOUS_STATE_GRAMMAR])
364 m4_popdef([AT_PREVIOUS_STATE_INPUT])
366 m4_pushdef([AT_USER_ACTION_GRAMMAR],
369 // If $$ = 0 here, then we know that the 'a' destructor is being invoked
370 // incorrectly for the 'b' set in the semantic action below. All 'a'
371 // tokens are returned by yylex, which sets $$ = 1.
374 fprintf (stderr, "Wrong destructor.\n");
377 // Rather than depend on an inconsistent state to induce reading a
378 // lookahead as in the previous grammar, just assign the lookahead in a
379 // semantic action. That lookahead isn't needed before either error
380 // action is encountered. In a previous version of Bison, this was a
381 // problem as it meant yychar was not translated into yytoken before
382 // either error action. The second error action thus invoked a
383 // destructor that it selected according to the incorrect yytoken. The
384 // first error action would have reported an incorrect unexpected token
385 // except that, due to the bug described in the previous grammar, the
386 // unexpected token was not reported at all.
387 start: error-reduce consistent-error 'a' { USE ($][3); } ;
390 'a' 'a' consistent-reduction consistent-error 'a'
391 { USE (($][1, $][2, $][5)); }
396 consistent-reduction: /*empty*/ {
397 assert (yychar == YYEMPTY);
404 | /*empty*/ %prec 'a'
407 // Provide another context in which all rules are useful so that this
408 // test case looks a little more realistic.
409 start: 'b' consistent-error 'b' ;
411 m4_pushdef([AT_USER_ACTION_INPUT], [[aa]])
413 AT_CONSISTENT_ERRORS_CHECK([[]],
414 [AT_USER_ACTION_GRAMMAR],
415 [AT_USER_ACTION_INPUT],
417 AT_CONSISTENT_ERRORS_CHECK([[%glr-parser]],
418 [AT_USER_ACTION_GRAMMAR],
419 [AT_USER_ACTION_INPUT],
421 # No C++ or Java test because yychar cannot be manipulated by users.
423 AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions consistent]],
424 [AT_USER_ACTION_GRAMMAR],
425 [AT_USER_ACTION_INPUT],
428 # Canonical LR doesn't foresee the error for 'a'!
429 AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions accepting]],
430 [AT_USER_ACTION_GRAMMAR],
431 [AT_USER_ACTION_INPUT],
433 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
434 [AT_USER_ACTION_GRAMMAR],
435 [AT_USER_ACTION_INPUT],
438 AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full]],
439 [AT_USER_ACTION_GRAMMAR],
440 [AT_USER_ACTION_INPUT],
442 AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full
443 %define lr.default-reductions accepting]],
444 [AT_USER_ACTION_GRAMMAR],
445 [AT_USER_ACTION_INPUT],
448 m4_popdef([AT_USER_ACTION_GRAMMAR])
449 m4_popdef([AT_USER_ACTION_INPUT])
451 m4_popdef([AT_CONSISTENT_ERRORS_CHECK])
457 ## ------------------------------------------------------- ##
458 ## LAC: %nonassoc requires splitting canonical LR states. ##
459 ## ------------------------------------------------------- ##
461 # This test case demonstrates that, when %nonassoc is used, canonical
462 # LR(1) parser table construction followed by conflict resolution
463 # without further state splitting is not always sufficient to produce a
464 # parser that can detect all syntax errors as soon as possible on one
465 # token of lookahead. However, LAC solves the problem completely even
466 # with minimal LR parser tables.
468 AT_SETUP([[LAC: %nonassoc requires splitting canonical LR states]])
470 AT_DATA_GRAMMAR([[input.y]],
473 void yyerror (char const *);
483 'a' problem 'a' // First context.
484 | 'b' problem 'b' // Second context.
485 | 'c' reduce-nonassoc // Just makes reduce-nonassoc useful.
494 // For the state reached after shifting the 'a' in these productions,
495 // lookahead sets are the same in both the first and second contexts.
496 // Thus, canonical LR reuses the same state for both contexts. However,
497 // the lookahead 'a' for the reduction "look: 'a'" later becomes an
498 // error action only in the first context. In order to immediately
499 // detect the syntax error on 'a' here for only the first context, this
500 // canonical LR state would have to be split into two states, and the
501 // 'a' lookahead would have to be removed from only one of the states.
503 'a' // Reduction lookahead set is always ['a', 'b'].
505 | 'a' 'c' // 'c' is forgotten as an expected token.
508 reduce-nonassoc: %prec 'a';
513 yyerror (char const *msg)
515 fprintf (stderr, "%s\n", msg);
521 char const *input = "aaa";
532 # Show canonical LR's failure.
533 AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]],
535 [[input.y: conflicts: 2 shift/reduce
537 AT_COMPILE([[input]])
538 AT_PARSER_CHECK([[./input]], [[1]], [[]],
539 [[syntax error, unexpected 'a', expecting 'b'
542 # It's corrected by LAC.
543 AT_BISON_CHECK([[-Dlr.type=canonical-lr -Dparse.lac=full \
544 -o input.c input.y]], [[0]], [[]],
545 [[input.y: conflicts: 2 shift/reduce
547 AT_COMPILE([[input]])
548 AT_PARSER_CHECK([[./input]], [[1]], [[]],
549 [[syntax error, unexpected 'a', expecting 'b' or 'c'
552 # IELR is sufficient when LAC is used.
553 AT_BISON_CHECK([[-Dlr.type=ielr -Dparse.lac=full -o input.c input.y]],
555 [[input.y: conflicts: 2 shift/reduce
557 AT_COMPILE([[input]])
558 AT_PARSER_CHECK([[./input]], [[1]], [[]],
559 [[syntax error, unexpected 'a', expecting 'b' or 'c'
564 ## ------------------------- ##
565 ## Unresolved SR Conflicts. ##
566 ## ------------------------- ##
568 AT_SETUP([Unresolved SR Conflicts])
570 AT_KEYWORDS([report])
575 exp: exp OP exp | NUM;
578 AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
579 [input.y: conflicts: 1 shift/reduce
582 # Check the contents of the report.
583 AT_CHECK([cat input.output], [],
584 [[State 5 conflicts: 1 shift/reduce
595 Terminals, with rules where they appear
603 Nonterminals, with rules where they appear
608 on left: 1 2, on right: 0 1
613 0 $accept: . exp $end
617 NUM shift, and go to state 1
626 $default reduce using rule 2 (exp)
631 0 $accept: exp . $end
634 $end shift, and go to state 3
635 OP shift, and go to state 4
640 0 $accept: exp $end .
651 NUM shift, and go to state 1
659 1 | exp OP exp . [$end, OP]
661 OP shift, and go to state 4
663 OP [reduce using rule 1 (exp)]
664 $default reduce using rule 1 (exp)
671 ## ----------------------- ##
672 ## Resolved SR Conflicts. ##
673 ## ----------------------- ##
675 AT_SETUP([Resolved SR Conflicts])
677 AT_KEYWORDS([report])
683 exp: exp OP exp | NUM;
686 AT_BISON_CHECK([-o input.c --report=all input.y])
688 # Check the contents of the report.
689 AT_CHECK([cat input.output], [],
698 Terminals, with rules where they appear
706 Nonterminals, with rules where they appear
711 on left: 1 2, on right: 0 1
716 0 $accept: . exp $end
720 NUM shift, and go to state 1
729 $default reduce using rule 2 (exp)
734 0 $accept: exp . $end
737 $end shift, and go to state 3
738 OP shift, and go to state 4
743 0 $accept: exp $end .
754 NUM shift, and go to state 1
762 1 | exp OP exp . [$end, OP]
764 $default reduce using rule 1 (exp)
766 Conflict between rule 1 and token OP resolved as reduce (%left OP).
772 ## ---------------------- ##
773 ## %precedence suffices. ##
774 ## ---------------------- ##
776 AT_SETUP([%precedence suffices])
783 "if" cond "then" stmt
784 | "if" cond "then" stmt "else" stmt
793 AT_BISON_CHECK([-o input.c input.y])
798 ## ------------------------------ ##
799 ## %precedence does not suffice. ##
800 ## ------------------------------ ##
802 AT_SETUP([%precedence does not suffice])
809 "if" cond "then" stmt
810 | "if" cond "then" stmt "else" stmt
820 AT_BISON_CHECK([-o input.c input.y], 0, [],
821 [[input.y: conflicts: 1 shift/reduce
822 input.y:12.3-18: warning: rule useless in parser due to conflicts: cond: cond "then" cond
828 ## -------------------------------- ##
829 ## Defaulted Conflicted Reduction. ##
830 ## -------------------------------- ##
832 # When there are RR conflicts, some rules are disabled. Usually it is
833 # simply displayed as:
835 # $end reduce using rule 3 (num)
836 # $end [reduce using rule 4 (id)]
838 # But when `reduce 3' is the default action, we'd produce:
840 # $end [reduce using rule 4 (id)]
841 # $default reduce using rule 3 (num)
843 # In this precise case (a reduction is masked by the default
844 # reduction), we make the `reduce 3' explicit:
846 # $end reduce using rule 3 (num)
847 # $end [reduce using rule 4 (id)]
848 # $default reduce using rule 3 (num)
850 # Maybe that's not the best display, but then, please propose something
853 AT_SETUP([Defaulted Conflicted Reduction])
854 AT_KEYWORDS([report])
864 AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
865 [[input.y: conflicts: 1 reduce/reduce
866 input.y:4.6-8: warning: rule useless in parser due to conflicts: id: '0'
869 # Check the contents of the report.
870 AT_CHECK([cat input.output], [],
871 [[Rules useless in parser due to conflicts
876 State 1 conflicts: 1 reduce/reduce
891 Terminals, with rules where they appear
898 Nonterminals, with rules where they appear
903 on left: 1 2, on right: 0
905 on left: 3, on right: 1
907 on left: 4, on right: 2
912 0 $accept: . exp $end
918 '0' shift, and go to state 1
930 $end reduce using rule 3 (num)
931 $end [reduce using rule 4 (id)]
932 $default reduce using rule 3 (num)
937 0 $accept: exp . $end
939 $end shift, and go to state 5
946 $default reduce using rule 1 (exp)
953 $default reduce using rule 2 (exp)
958 0 $accept: exp $end .
968 ## -------------------- ##
969 ## %expect not enough. ##
970 ## -------------------- ##
972 AT_SETUP([%expect not enough])
978 exp: exp OP exp | NUM;
981 AT_BISON_CHECK([-o input.c input.y], 1, [],
982 [input.y: conflicts: 1 shift/reduce
983 input.y: expected 0 shift/reduce conflicts
988 ## --------------- ##
990 ## --------------- ##
992 AT_SETUP([%expect right])
998 exp: exp OP exp | NUM;
1001 AT_BISON_CHECK([-o input.c input.y])
1005 ## ------------------ ##
1006 ## %expect too much. ##
1007 ## ------------------ ##
1009 AT_SETUP([%expect too much])
1015 exp: exp OP exp | NUM;
1018 AT_BISON_CHECK([-o input.c input.y], 1, [],
1019 [input.y: conflicts: 1 shift/reduce
1020 input.y: expected 2 shift/reduce conflicts
1025 ## ------------------------------- ##
1026 ## %expect with reduce conflicts. ##
1027 ## ------------------------------- ##
1029 AT_SETUP([%expect with reduce conflicts])
1034 program: a 'a' | a a;
1038 AT_BISON_CHECK([-o input.c input.y], 1, [],
1039 [input.y: conflicts: 1 reduce/reduce
1040 input.y: expected 0 reduce/reduce conflicts
1045 ## ------------------------- ##
1046 ## %prec with user strings. ##
1047 ## ------------------------- ##
1049 AT_SETUP([%prec with user string])
1051 AT_DATA([[input.y]],
1058 AT_BISON_CHECK([-o input.c input.y])
1062 ## -------------------------------- ##
1063 ## %no-default-prec without %prec. ##
1064 ## -------------------------------- ##
1066 AT_SETUP([%no-default-prec without %prec])
1068 AT_DATA([[input.y]],
1082 AT_BISON_CHECK([-o input.c input.y], 0, [],
1083 [[input.y: conflicts: 4 shift/reduce
1088 ## ----------------------------- ##
1089 ## %no-default-prec with %prec. ##
1090 ## ----------------------------- ##
1092 AT_SETUP([%no-default-prec with %prec])
1094 AT_DATA([[input.y]],
1102 e: e '+' e %prec '+'
1108 AT_BISON_CHECK([-o input.c input.y])
1112 ## --------------- ##
1113 ## %default-prec. ##
1114 ## --------------- ##
1116 AT_SETUP([%default-prec])
1118 AT_DATA([[input.y]],
1132 AT_BISON_CHECK([-o input.c input.y])
1136 ## ---------------------------------------------- ##
1137 ## Unreachable States After Conflict Resolution. ##
1138 ## ---------------------------------------------- ##
1140 AT_SETUP([[Unreachable States After Conflict Resolution]])
1142 # If conflict resolution makes states unreachable, remove those states, report
1143 # rules that are then unused, and don't report conflicts in those states. Test
1144 # what happens when a nonterminal becomes useless as a result of state removal
1145 # since that causes lalr.o's goto map to be rewritten.
1147 AT_DATA([[input.y]],
1153 start: resolved_conflict 'a' reported_conflicts 'a' ;
1155 /* S/R conflict resolved as reduce, so the state with item
1156 * (resolved_conflict: 'a' . unreachable1) and all it transition successors are
1157 * unreachable, and the associated production is useless. */
1163 /* S/R conflict that need not be reported since it is unreachable because of
1164 * the previous conflict resolution. Nonterminal unreachable1 and all its
1165 * productions are useless. */
1171 /* Likewise for a R/R conflict and nonterminal unreachable2. */
1174 /* Make sure remaining S/R and R/R conflicts are still reported correctly even
1175 * when their states are renumbered due to state removal. */
1184 AT_BISON_CHECK([[--report=all input.y]], 0, [],
1185 [[input.y: conflicts: 1 shift/reduce, 1 reduce/reduce
1186 input.y:12.5-20: warning: rule useless in parser due to conflicts: resolved_conflict: 'a' unreachable1
1187 input.y:20.5-20: warning: rule useless in parser due to conflicts: unreachable1: 'a' unreachable2
1188 input.y:21.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
1189 input.y:25.13: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
1190 input.y:25.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
1191 input.y:31.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
1192 input.y:32.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
1195 AT_CHECK([[cat input.output]], 0,
1196 [[Rules useless in parser due to conflicts
1198 2 resolved_conflict: 'a' unreachable1
1200 4 unreachable1: 'a' unreachable2
1203 6 unreachable2: /* empty */
1206 9 reported_conflicts: 'a'
1210 State 4 conflicts: 1 shift/reduce
1211 State 5 conflicts: 1 reduce/reduce
1216 0 $accept: start $end
1218 1 start: resolved_conflict 'a' reported_conflicts 'a'
1220 2 resolved_conflict: 'a' unreachable1
1223 4 unreachable1: 'a' unreachable2
1226 6 unreachable2: /* empty */
1229 8 reported_conflicts: 'a'
1234 Terminals, with rules where they appear
1241 Nonterminals, with rules where they appear
1246 on left: 1, on right: 0
1247 resolved_conflict (6)
1248 on left: 2 3, on right: 1
1250 on left: 4 5, on right: 2
1252 on left: 6 7, on right: 4
1253 reported_conflicts (9)
1254 on left: 8 9 10, on right: 1
1259 0 $accept: . start $end
1260 1 start: . resolved_conflict 'a' reported_conflicts 'a'
1261 2 resolved_conflict: . 'a' unreachable1
1264 $default reduce using rule 3 (resolved_conflict)
1267 resolved_conflict go to state 2
1269 Conflict between rule 3 and token 'a' resolved as reduce (%left 'a').
1274 0 $accept: start . $end
1276 $end shift, and go to state 3
1281 1 start: resolved_conflict . 'a' reported_conflicts 'a'
1283 'a' shift, and go to state 4
1288 0 $accept: start $end .
1295 1 start: resolved_conflict 'a' . reported_conflicts 'a'
1296 8 reported_conflicts: . 'a'
1300 'a' shift, and go to state 5
1302 'a' [reduce using rule 10 (reported_conflicts)]
1304 reported_conflicts go to state 6
1309 8 reported_conflicts: 'a' . ['a']
1312 'a' reduce using rule 8 (reported_conflicts)
1313 'a' [reduce using rule 9 (reported_conflicts)]
1314 $default reduce using rule 8 (reported_conflicts)
1319 1 start: resolved_conflict 'a' reported_conflicts . 'a'
1321 'a' shift, and go to state 7
1326 1 start: resolved_conflict 'a' reported_conflicts 'a' .
1328 $default reduce using rule 1 (start)
1331 AT_DATA([[input-keep.y]],
1332 [[%define lr.keep-unreachable-states
1334 AT_CHECK([[cat input.y >> input-keep.y]])
1336 AT_BISON_CHECK([[input-keep.y]], 0, [],
1337 [[input-keep.y: conflicts: 2 shift/reduce, 2 reduce/reduce
1338 input-keep.y:22.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
1339 input-keep.y:26.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
1340 input-keep.y:32.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
1341 input-keep.y:33.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
1347 ## ------------------------------------------------------------ ##
1348 ## Solved conflicts report for multiple reductions in a state. ##
1349 ## ------------------------------------------------------------ ##
1351 AT_SETUP([[Solved conflicts report for multiple reductions in a state]])
1353 # Used to lose earlier solved conflict messages even within a single S/R/R.
1355 AT_DATA([[input.y]],
1371 empty_a: %prec 'a' ;
1372 empty_b: %prec 'b' ;
1373 empty_c1: %prec 'c' ;
1374 empty_c2: %prec 'c' ;
1375 empty_c3: %prec 'd' ;
1377 AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
1378 AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0,
1381 0 $accept: . start $end
1394 13 empty_c3: . ['c']
1396 'b' shift, and go to state 1
1398 'c' reduce using rule 13 (empty_c3)
1399 $default reduce using rule 9 (empty_a)
1402 empty_a go to state 3
1403 empty_b go to state 4
1404 empty_c1 go to state 5
1405 empty_c2 go to state 6
1406 empty_c3 go to state 7
1408 Conflict between rule 9 and token 'a' resolved as reduce (%left 'a').
1409 Conflict between rule 10 and token 'b' resolved as shift (%right 'b').
1410 Conflict between rule 11 and token 'c' resolved as shift (%right 'c').
1411 Conflict between rule 12 and token 'c' resolved as shift (%right 'c').
1412 Conflict between rule 13 and token 'c' resolved as reduce ('c' < 'd').
1421 ## ------------------------------------------------------------ ##
1422 ## %nonassoc error actions for multiple reductions in a state. ##
1423 ## ------------------------------------------------------------ ##
1425 # Used to abort when trying to resolve conflicts as %nonassoc error actions for
1426 # multiple reductions in a state.
1428 # For a %nonassoc error action token, used to print the first remaining
1429 # reduction on that token without brackets.
1431 AT_SETUP([[%nonassoc error actions for multiple reductions in a state]])
1433 AT_DATA([[input.y]],
1434 [[%nonassoc 'a' 'b' 'c'
1446 empty_a: %prec 'a' ;
1447 empty_b: %prec 'b' ;
1448 empty_c1: %prec 'c' ;
1449 empty_c2: %prec 'c' ;
1450 empty_c3: %prec 'c' ;
1453 AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
1454 AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0,
1457 0 $accept: . start $end
1469 12 empty_c2: . ['c']
1470 13 empty_c3: . ['c']
1472 'a' error (nonassociative)
1473 'b' error (nonassociative)
1474 'c' error (nonassociative)
1476 'c' [reduce using rule 12 (empty_c2)]
1477 'c' [reduce using rule 13 (empty_c3)]
1480 empty_a go to state 2
1481 empty_b go to state 3
1482 empty_c1 go to state 4
1483 empty_c2 go to state 5
1484 empty_c3 go to state 6
1486 Conflict between rule 9 and token 'a' resolved as an error (%nonassoc 'a').
1487 Conflict between rule 10 and token 'b' resolved as an error (%nonassoc 'b').
1488 Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c').