1 # Exercising Bison Grammar Reduction. -*- Autotest -*-
3 # Copyright (C) 2001-2002, 2007-2015, 2018-2020 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 <http://www.gnu.org/licenses/>.
19 AT_BANNER([[Grammar Reduction.]])
22 ## ------------------- ##
23 ## Useless Terminals. ##
24 ## ------------------- ##
26 AT_SETUP([Useless Terminals])
47 AT_BISON_CHECK([[input.y]])
49 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
50 [[Terminals unused in grammar
66 ## ---------------------- ##
67 ## Useless Nonterminals. ##
68 ## ---------------------- ##
70 AT_SETUP([Useless Nonterminals])
71 AT_BISON_OPTION_PUSHDEFS
75 ]AT_YYERROR_DECLARE_EXTERN[
76 ]AT_YYLEX_DECLARE_EXTERN[
89 AT_BISON_CHECK([[input.y]], 0, [],
90 [[input.y: warning: 3 nonterminals useless in grammar [-Wother]
91 input.y: warning: 3 rules useless in grammar [-Wother]
92 input.y:11.1-8: warning: nonterminal useless in grammar: useless1 [-Wother]
93 input.y:12.1-8: warning: nonterminal useless in grammar: useless2 [-Wother]
94 input.y:13.1-8: warning: nonterminal useless in grammar: useless3 [-Wother]
97 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
98 [[Nonterminals useless in grammar
102 Rules useless in grammar
108 # Make sure the generated parser is correct.
109 AT_COMPILE([input.o])
111 AT_BISON_OPTION_POPDEFS
116 ## --------------- ##
118 ## --------------- ##
120 AT_SETUP([Useless Rules])
122 AT_BISON_OPTION_PUSHDEFS
123 AT_KEYWORDS([report])
127 ]AT_YYERROR_DECLARE_EXTERN[
128 ]AT_YYLEX_DECLARE_EXTERN[
146 AT_BISON_CHECK([[-fcaret input.y]], 0, [],
147 [[input.y: warning: 9 nonterminals useless in grammar [-Wother]
148 input.y: warning: 9 rules useless in grammar [-Wother]
149 input.y:10.1-8: warning: nonterminal useless in grammar: useless1 [-Wother]
152 input.y:11.1-8: warning: nonterminal useless in grammar: useless2 [-Wother]
155 input.y:12.1-8: warning: nonterminal useless in grammar: useless3 [-Wother]
158 input.y:13.1-8: warning: nonterminal useless in grammar: useless4 [-Wother]
161 input.y:14.1-8: warning: nonterminal useless in grammar: useless5 [-Wother]
164 input.y:15.1-8: warning: nonterminal useless in grammar: useless6 [-Wother]
167 input.y:16.1-8: warning: nonterminal useless in grammar: useless7 [-Wother]
170 input.y:17.1-8: warning: nonterminal useless in grammar: useless8 [-Wother]
173 input.y:18.1-8: warning: nonterminal useless in grammar: useless9 [-Wother]
179 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
180 [[Nonterminals useless in grammar
190 Terminals unused in grammar
200 Rules useless in grammar
212 # Make sure the generated parser is correct.
213 AT_COMPILE([input.o])
215 AT_BISON_OPTION_POPDEFS
220 ## --------------- ##
222 ## --------------- ##
224 AT_SETUP([Useless Parts])
226 # We used to emit code that used symbol numbers before the useless
227 # symbol elimination, hence before the renumbering of the useful
228 # symbols. As a result, the evaluation of the skeleton failed because
229 # it used non existing symbol numbers. Which is the happy scenario:
230 # we could use numbers of other existing symbols...
231 # http://lists.gnu.org/archive/html/bug-bison/2019-01/msg00044.html
233 AT_BISON_OPTION_PUSHDEFS
236 ]AT_YYERROR_DECLARE_EXTERN[
237 ]AT_YYLEX_DECLARE_EXTERN[
239 %union { void* ptr; }
257 : { $$ = YY_NULLPTR; }
261 AT_BISON_CHECK([[-fcaret -rall -o input.c input.y]], 0, [],
262 [[input.y: warning: 1 nonterminal useless in grammar [-Wother]
263 input.y: warning: 1 rule useless in grammar [-Wother]
264 input.y:18.1-6: warning: nonterminal useless in grammar: unused [-Wother]
270 AT_CHECK([[sed -n '/^State 0/q;/^$/!p' input.output]], 0,
271 [[Nonterminals useless in grammar
273 Rules useless in grammar
276 0 $accept: start $end
280 Terminals, with rules where they appear
283 Nonterminals, with rules where they appear
297 # Make sure the generated parser is correct.
298 AT_COMPILE([input.o])
300 AT_BISON_OPTION_POPDEFS
305 ## ------------------- ##
306 ## Reduced Automaton. ##
307 ## ------------------- ##
309 # Check that the automaton is that as the for the grammar reduced by
312 AT_SETUP([Reduced Automaton])
314 AT_KEYWORDS([report])
316 # The non reduced grammar.
317 # ------------------------
318 AT_DATA([[not-reduced.y]],
319 [[/* A useless token. */
324 %output "not-reduced.c"
328 exp: useful { /* A useful action. */ }
329 | non_productive { /* A non productive action. */ }
332 not_reachable: useful { /* A not reachable action. */ }
335 non_productive: non_productive useless_token
336 { /* Another non productive action. */ }
341 AT_BISON_CHECK([[-fcaret not-reduced.y]], 0, [],
342 [[not-reduced.y: warning: 2 nonterminals useless in grammar [-Wother]
343 not-reduced.y: warning: 3 rules useless in grammar [-Wother]
344 not-reduced.y:14.1-13: warning: nonterminal useless in grammar: not_reachable [-Wother]
345 14 | not_reachable: useful { /* A not reachable action. */ }
347 not-reduced.y:17.1-14: warning: nonterminal useless in grammar: non_productive [-Wother]
348 17 | non_productive: non_productive useless_token
350 not-reduced.y:11.6-57: warning: rule useless in grammar [-Wother]
351 11 | | non_productive { /* A non productive action. */ }
352 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
355 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' not-reduced.output]], 0,
356 [[Nonterminals useless in grammar
359 Terminals unused in grammar
361 Rules useless in grammar
362 2 exp: non_productive
363 3 not_reachable: useful
364 4 non_productive: non_productive useless_token
367 # The reduced grammar.
368 # --------------------
369 AT_DATA([[reduced.y]],
370 [[/* A useless token. */
379 exp: useful { /* A useful action. */ }
380 // | non_productive { /* A non productive action. */ } */
383 //not_reachable: useful { /* A not reachable action. */ }
386 //non_productive: non_productive useless_token
387 // { /* Another non productive action. */ }
392 AT_BISON_CHECK([[reduced.y]])
394 # Comparing the parsers.
396 AT_CHECK([sed 's/not-reduced/reduced/g' not-reduced.c], 0, [expout])
402 ## ------------------- ##
403 ## Underivable Rules. ##
404 ## ------------------- ##
406 AT_SETUP([Underivable Rules])
408 AT_KEYWORDS([report])
415 exp: useful | underivable;
416 underivable: indirection;
417 indirection: underivable;
420 AT_BISON_CHECK([[-fcaret input.y]], 0, [],
421 [[input.y: warning: 2 nonterminals useless in grammar [-Wother]
422 input.y: warning: 3 rules useless in grammar [-Wother]
423 input.y:6.1-11: warning: nonterminal useless in grammar: underivable [-Wother]
424 6 | underivable: indirection;
426 input.y:7.1-11: warning: nonterminal useless in grammar: indirection [-Wother]
427 7 | indirection: underivable;
429 input.y:5.15-25: warning: rule useless in grammar [-Wother]
430 5 | exp: useful | underivable;
434 AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
435 [[Nonterminals useless in grammar
438 Rules useless in grammar
440 3 underivable: indirection
441 4 indirection: underivable
448 ## ---------------- ##
449 ## Empty Language. ##
450 ## ---------------- ##
452 AT_SETUP([Empty Language])
460 AT_BISON_CHECK([[input.y]], 1, [],
461 [[input.y: warning: 2 nonterminals useless in grammar [-Wother]
462 input.y: warning: 2 rules useless in grammar [-Wother]
463 input.y:3.1-3: fatal error: start symbol exp does not derive any sentence
470 ## ----------------- ##
471 ## %define lr.type. ##
472 ## ----------------- ##
474 # AT_TEST_LR_TYPE(DESCRIPTION,
475 # DECLS, GRAMMAR, INPUT,
476 # BISON-STDERR, TABLES,
478 # [PARSER-EXIT-VALUE],
479 # [PARSER-STDOUT], [PARSER-STDERR])
480 # -------------------------------------------------
481 m4_define([AT_TEST_LR_TYPE],
483 AT_TEST_TABLES_AND_PARSE([[no %define lr.type: ]$1],
485 [$2], m4_shiftn(2, $@))
486 AT_TEST_TABLES_AND_PARSE([[%define lr.type lalr: ]$1],
488 [[%define lr.type lalr
491 AT_TEST_TABLES_AND_PARSE([[%define lr.type ielr: ]$1],
493 [[%define lr.type ielr
496 AT_TEST_TABLES_AND_PARSE([[%define lr.type canonical-lr: ]$1],
497 [[canonical LR]], [[]],
498 [[%define lr.type canonical-lr
503 AT_TEST_LR_TYPE([[Single State Split]],
505 // Conflict resolution renders state 12 unreachable for canonical LR(1). We
506 // keep it so that the parser table diff is easier to code.
507 %define lr.keep-unreachable-state]],
509 S: 'a' A 'a' /* rule 1 */
510 | 'b' A 'b' /* rule 2 */
514 /* A conflict should appear after the first 'a' in rules 4 and 5 but only after
515 having shifted the first 'a' in rule 1. However, when LALR(1) merging is
516 chosen, the state containing that conflict is reused after having seen the
517 first 'b' in rule 2 and then the first 'a' in rules 4 and 5. In both cases,
518 because of the merged state, if the next token is an 'a', the %left forces a
519 reduction action with rule 5. In the latter case, only a shift is actually
520 grammatically correct. Thus, the parser would report a syntax error for the
521 grammatically correct sentence "baab" because it would encounter a syntax
522 error after that incorrect reduction.
524 Despite not being LALR(1), Menhir version 20070322 suffers from this problem
525 as well. It uses David Pager's weak compatibility test for merging states.
526 Bison and Menhir accept non-LR(1) grammars with conflict resolution. Pager
527 designed his algorithm only for LR(1) grammars. */
528 A: 'a' 'a' /* rule 4 */
532 /* Rule 3, rule 6, and rule 7 ensure that Bison does not report rule 4 as
533 useless after conflict resolution. This proves that, even though LALR(1)
534 generates incorrect parser tables sometimes, Bison will not necessarily
535 produce any warning to help the user realize it. */
536 c: 'a' 'b' /* rule 6 */
542 [['b', 'a', 'a', 'b']],
555 'a' shift, and go to state 1
556 'b' shift, and go to state 2
557 'c' shift, and go to state 3
568 'a' shift, and go to state 5
579 'a' shift, and go to state ]AT_COND_CASE([[LALR]], [[5]], [[16]])[
592 'a' shift, and go to state 8
602 $end shift, and go to state 11
608 5 | 'a' . ]AT_COND_CASE([[LALR]], [[['a', 'b']]], [[['a']]])[
610 ]AT_COND_CASE([[canonical LR]], [['a']],
611 [[$default]])[ reduce using rule 5 (A)
613 Conflict between rule 5 and token 'a' resolved as reduce (%left 'a').
620 'a' shift, and go to state 13
627 'b' shift, and go to state 14
636 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[17]],
638 'b' shift, and go to state 15
640 ]AT_COND_CASE([[canonical LR]], [[$end]],
641 [[$default]])[ reduce using rule 5 (A)
646 7 c: A .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
648 ]AT_COND_CASE([[canonical LR]], [[$end]],
649 [[$default]])[ reduce using rule 7 (c)
654 3 S: 'c' c .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
656 ]AT_COND_CASE([[canonical LR]], [[$end]],
657 [[$default]])[ reduce using rule 3 (S)
669 4 A: 'a' 'a' .]AT_COND_CASE([[canonical LR]], [[ ['a']]])[
671 ]AT_COND_CASE([[canonical LR]], [['a']],
672 [[$default]])[ reduce using rule 4 (A)
677 1 S: 'a' A 'a' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
679 ]AT_COND_CASE([[canonical LR]], [[$end]],
680 [[$default]])[ reduce using rule 1 (S)
685 2 S: 'b' A 'b' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
687 ]AT_COND_CASE([[canonical LR]], [[$end]],
688 [[$default]])[ reduce using rule 2 (S)
693 6 c: 'a' 'b' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
695 ]AT_COND_CASE([[canonical LR]], [[$end]],
696 [[$default]])[ reduce using rule 6 (c)]AT_COND_CASE([[LALR]],
705 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[18]],
708 ]AT_COND_CASE([[canonical LR]], [['b']],
709 [[$default]])[ reduce using rule 5 (A)]AT_COND_CASE([[canonical LR]], [[
714 4 A: 'a' 'a' . [$end]
716 $end reduce using rule 4 (A)
723 'b' reduce using rule 4 (A)]])])[
729 dnl PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR
730 [AT_COND_CASE([[LALR]], [[1]], [[0]])],
732 [AT_COND_CASE([[LALR]],
736 AT_TEST_LR_TYPE([[Lane Split]],
738 // Conflict resolution renders state 16 unreachable for canonical LR(1). We
739 // keep it so that the parser table diff is easier to code.
740 %define lr.keep-unreachable-state]],
742 /* Similar to the last test case set but two states must be split. */
743 S: 'a' A 'a' /* rule 1 */
744 | 'b' A 'b' /* rule 2 */
748 A: 'a' 'a' 'a' /* rule 4 */
749 | 'a' 'a' /* rule 5 */
752 c: 'a' 'a' 'b' /* rule 6 */
758 [['b', 'a', 'a', 'a', 'b']],
771 'a' shift, and go to state 1
772 'b' shift, and go to state 2
773 'c' shift, and go to state 3
784 'a' shift, and go to state 5
795 'a' shift, and go to state ]AT_COND_CASE([[LALR]], [[5]], [[18]])[
808 'a' shift, and go to state 8
818 $end shift, and go to state 11
826 'a' shift, and go to state 12
833 'a' shift, and go to state 13
840 'b' shift, and go to state 14
849 'a' shift, and go to state 15
854 7 c: A .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
856 ]AT_COND_CASE([[canonical LR]], [[$end]],
857 [[$default]])[ reduce using rule 7 (c)
862 3 S: 'c' c .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
864 ]AT_COND_CASE([[canonical LR]], [[$end]],
865 [[$default]])[ reduce using rule 3 (S)
878 5 | 'a' 'a' . ]AT_COND_CASE([[LALR]], [[['a', 'b']]], [[['a']]])[
880 ]AT_COND_CASE([[canonical LR]], [['a']],
881 [[$default]])[ reduce using rule 5 (A)
883 Conflict between rule 5 and token 'a' resolved as reduce (%left 'a').
888 1 S: 'a' A 'a' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
890 ]AT_COND_CASE([[canonical LR]], [[$end]],
891 [[$default]])[ reduce using rule 1 (S)
896 2 S: 'b' A 'b' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
898 ]AT_COND_CASE([[canonical LR]], [[$end]],
899 [[$default]])[ reduce using rule 2 (S)
908 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[19]],
910 'b' shift, and go to state 17
912 ]AT_COND_CASE([[canonical LR]], [[$end]],
913 [[$default]])[ reduce using rule 5 (A)
918 4 A: 'a' 'a' 'a' .]AT_COND_CASE([[canonical LR]], [[ ['a']]])[
920 ]AT_COND_CASE([[canonical LR]], [['a']],
921 [[$default]])[ reduce using rule 4 (A)
926 6 c: 'a' 'a' 'b' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
928 ]AT_COND_CASE([[canonical LR]], [[$end]],
929 [[$default]])[ reduce using rule 6 (c)]AT_COND_CASE([[LALR]],
938 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[20]],
942 State 19]AT_COND_CASE([[canonical LR]], [[
944 4 A: 'a' 'a' 'a' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
946 ]AT_COND_CASE([[canonical LR]], [[$end]],
947 [[$default]])[ reduce using rule 4 (A)
955 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[21]],
958 ]AT_COND_CASE([[canonical LR]], [['b']],
959 [[$default]])[ reduce using rule 5 (A)]AT_COND_CASE([[canonical LR]], [[
964 4 A: 'a' 'a' 'a' .]AT_COND_CASE([[canonical LR]], [[ ['b']]])[
966 ]AT_COND_CASE([[canonical LR]], [['b']],
967 [[$default]])[ reduce using rule 4 (A)]])])[
973 dnl PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR
974 [AT_COND_CASE([[LALR]], [[1]], [[0]])],
976 [AT_COND_CASE([[LALR]],
980 AT_TEST_LR_TYPE([[Complex Lane Split]],
982 // Conflict resolution renders state 16 unreachable for canonical LR(1). We
983 // keep it so that the parser table diff is easier to code.
984 %define lr.keep-unreachable-state]],
986 /* Similar to the last test case set but forseeing the S/R conflict from the
987 first state that must be split is becoming difficult. Imagine if B were
988 even more complex. Imagine if A had other RHS's ending in other
1005 [['b', 'a', 'a', 'a', 'b']],
1018 'a' shift, and go to state 1
1019 'b' shift, and go to state 2
1020 'c' shift, and go to state 3
1030 'a' shift, and go to state 5
1040 'a' shift, and go to state ]AT_COND_CASE([[LALR]], [[5]], [[19]])[
1052 'a' shift, and go to state 8
1062 $end shift, and go to state 11
1069 'a' shift, and go to state 12
1076 'a' shift, and go to state 13
1083 'b' shift, and go to state 14
1091 'a' shift, and go to state 15
1096 8 c: A .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1098 ]AT_COND_CASE([[canonical LR]], [[$end]],
1099 [[$default]])[ reduce using rule 8 (c)
1104 3 S: 'c' c .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1106 ]AT_COND_CASE([[canonical LR]], [[$end]],
1107 [[$default]])[ reduce using rule 3 (S)
1121 6 | . %empty ]AT_COND_CASE([[LALR]], [[['a', 'b']]], [[['a']]])[
1123 ]AT_COND_CASE([[canonical LR]], [['a']],
1124 [[$default]])[ reduce using rule 6 (B)
1128 Conflict between rule 6 and token 'a' resolved as reduce (%left 'a').
1133 1 S: 'a' A 'a' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1135 ]AT_COND_CASE([[canonical LR]], [[$end]],
1136 [[$default]])[ reduce using rule 1 (S)
1141 2 S: 'b' A 'b' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1143 ]AT_COND_CASE([[canonical LR]], [[$end]],
1144 [[$default]])[ reduce using rule 2 (S)
1154 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[20]],
1156 'b' shift, and go to state 18
1158 ]AT_COND_CASE([[canonical LR]], [[$end]],
1159 [[$default]])[ reduce using rule 6 (B)
1161 B go to state ]AT_COND_CASE([[canonical LR]], [[21]], [[17]])[
1166 5 B: 'a' .]AT_COND_CASE([[canonical LR]], [[ ['a']]])[
1168 ]AT_COND_CASE([[canonical LR]], [['a']],
1169 [[$default]])[ reduce using rule 5 (B)
1174 4 A: 'a' 'a' B .]AT_COND_CASE([[canonical LR]], [[ ['a']]])[
1176 ]AT_COND_CASE([[canonical LR]], [['a']],
1177 [[$default]])[ reduce using rule 4 (A)
1182 7 c: 'a' 'a' 'b' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1184 ]AT_COND_CASE([[canonical LR]], [[$end]],
1185 [[$default]])[ reduce using rule 7 (c)]AT_COND_CASE([[LALR]], [], [[
1192 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[22]],
1196 State 20]AT_COND_CASE([[canonical LR]], [[
1200 $end reduce using rule 5 (B)
1205 4 A: 'a' 'a' B . [$end]
1207 $end reduce using rule 4 (A)
1216 'a' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[23]],
1219 ]AT_COND_CASE([[canonical LR]], [['b']],
1220 [[$default]])[ reduce using rule 6 (B)
1222 B go to state ]AT_COND_CASE([[canonical LR]], [[24
1229 'b' reduce using rule 5 (B)
1234 4 A: 'a' 'a' B . ['b']
1236 'b' reduce using rule 4 (A)]], [[17]])])[
1242 dnl PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR
1243 [AT_COND_CASE([[LALR]], [[1]], [[0]])],
1245 [AT_COND_CASE([[LALR]],
1249 AT_TEST_LR_TYPE([[Split During Added Lookahead Propagation]],
1250 [[%define lr.keep-unreachable-state]],
1252 /* The partial state chart diagram below is for LALR(1). State 0 is the start
1253 state. States are iterated for successor construction in numerical order.
1254 Transitions are downwards.
1256 State 13 has a R/R conflict that cannot be predicted by Bison's LR(1)
1257 algorithm using annotations alone. That is, when state 11's successor on
1258 'd' is merged with state 5 (which is originally just state 1's successor on
1259 'd'), state 5's successor on 'e' must then be changed because the resulting
1260 lookaheads that propagate to it now make it incompatible with state 8's
1261 successor on 'e'. In other words, state 13 must be split to avoid the
1279 This grammar is designed carefully to make sure that, despite Bison's LR(1)
1280 algorithm's bread-first iteration of transitions to reconstruct states,
1281 state 11's successors are constructed after state 5's and state 8's.
1282 Otherwise (for example, if you remove the first 'c' in each of rules 6 and
1283 7), state 5's successor on 'e' would never be merged with state 8's, so the
1284 split of the resulting state 13 would never need to be performed. */
1298 [['b', 'd', 'e', 'g']],
1301 [AT_COND_CASE([[LALR]],
1302 [[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1303 input.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1318 'a' shift, and go to state 1
1319 'b' shift, and go to state 2
1320 'c' shift, and go to state 3
1332 'd' shift, and go to state 5
1346 'd' shift, and go to state 8
1354 6 S: 'c' . 'c' A 'g'
1357 'c' shift, and go to state 11
1364 $end shift, and go to state 12
1372 'e' shift, and go to state ]AT_COND_CASE([[LALR]], [[13]],
1373 [[canonical LR]], [[13]],
1381 'f' shift, and go to state 14
1386 2 S: 'a' B .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1388 ]AT_COND_CASE([[canonical LR]], [[$end]],
1389 [[$default]])[ reduce using rule 2 (S)
1394 5 S: 'b' 'd' . [$end]
1398 'e' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[20]],
1401 ]AT_COND_CASE([[canonical LR]], [[$end]],
1402 [[$default]])[ reduce using rule 5 (S)
1409 'f' shift, and go to state 15
1416 'g' shift, and go to state 16
1421 6 S: 'c' 'c' . A 'g'
1426 'd' shift, and go to state ]AT_COND_CASE([[canonical LR]], [[21]],
1437 $default accept]AT_COND_CASE([[LALR]], [[
1442 8 A: 'd' 'e' . ['f', 'g']
1443 9 B: 'd' 'e' . [$end, 'g']
1445 $end reduce using rule 9 (B)
1446 'g' reduce using rule 8 (A)
1447 'g' [reduce using rule 9 (B)]
1448 $default reduce using rule 8 (A)]], [[
1453 8 A: 'd' 'e' . ['f']
1454 9 B: 'd' 'e' . ]AT_COND_CASE([[canonical LR]], [[[$end]]], [[['g']]])[
1456 ]AT_COND_CASE([[canonical LR]], [[$end]],
1457 [['g' ]])[ reduce using rule 9 (B)
1458 ]AT_COND_CASE([[canonical LR]], [['f' ]],
1459 [[$default]])[ reduce using rule 8 (A)]])[
1464 1 S: 'a' A 'f' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1466 ]AT_COND_CASE([[canonical LR]], [[$end]],
1467 [[$default]])[ reduce using rule 1 (S)
1472 3 S: 'b' A 'f' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1474 ]AT_COND_CASE([[canonical LR]], [[$end]],
1475 [[$default]])[ reduce using rule 3 (S)
1480 4 S: 'b' B 'g' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1482 ]AT_COND_CASE([[canonical LR]], [[$end]],
1483 [[$default]])[ reduce using rule 4 (S)
1488 6 S: 'c' 'c' A . 'g'
1490 'g' shift, and go to state 19
1495 7 S: 'c' 'c' B .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1497 ]AT_COND_CASE([[canonical LR]], [[$end]],
1498 [[$default]])[ reduce using rule 7 (S)
1503 6 S: 'c' 'c' A 'g' .]AT_COND_CASE([[canonical LR]], [[ [$end]]])[
1505 ]AT_COND_CASE([[canonical LR]], [[$end]],
1506 [[$default]])[ reduce using rule 6 (S)]AT_COND_CASE([[LALR]],
1510 State 20]AT_COND_CASE([[canonical LR]], [[
1512 8 A: 'd' 'e' . ['f']
1513 9 B: 'd' 'e' . ['g']
1515 'f' reduce using rule 8 (A)
1516 'g' reduce using rule 9 (B)
1524 'e' shift, and go to state 22
1529 8 A: 'd' 'e' . ['g']
1530 9 B: 'd' 'e' . [$end]
1532 $end reduce using rule 9 (B)
1533 'g' reduce using rule 8 (A)]], [[
1535 8 A: 'd' 'e' . ['f', 'g']
1536 9 B: 'd' 'e' . [$end]
1538 $end reduce using rule 9 (B)
1539 $default reduce using rule 8 (A)]])])[
1545 dnl PARSER-EXIT-VALUE, PARSER-STDOUT, PARSER-STDERR
1546 [AT_COND_CASE([[LALR]], [[1]], [[0]])],
1548 [AT_COND_CASE([[LALR]],
1554 ## ------------------------------ ##
1555 ## %define lr.default-reduction. ##
1556 ## ------------------------------ ##
1558 # AT_TEST_LR_DEFAULT_REDUCTIONS(GRAMMAR, INPUT, TABLES)
1559 # -----------------------------------------------------
1560 m4_define([AT_TEST_LR_DEFAULT_REDUCTIONS],
1562 AT_TEST_TABLES_AND_PARSE([[no %define lr.default-reduction]],
1565 [$1], [$2], [[]], [$3])
1566 AT_TEST_TABLES_AND_PARSE([[%define lr.default-reduction most]],
1568 [[%define lr.default-reduction most]],
1569 [$1], [$2], [[]], [$3])
1570 AT_TEST_TABLES_AND_PARSE([[%define lr.default-reduction consistent]],
1571 [[consistent]], [[]],
1572 [[%define lr.default-reduction consistent]],
1573 [$1], [$2], [[]], [$3])
1574 AT_TEST_TABLES_AND_PARSE([[%define lr.default-reduction accepting]],
1575 [[accepting]], [[]],
1576 [[%define lr.default-reduction accepting]],
1577 [$1], [$2], [[]], [$3])
1580 AT_TEST_LR_DEFAULT_REDUCTIONS([[
1581 /* The start state is consistent and has a shift on 'a' and no reductions.
1582 After pushing the b below, enter an inconsistent state that has a shift and
1583 one reduction with one lookahead. */
1590 /* After shifting this 'a', enter a consistent state that has no shift and 1
1591 reduction with multiple lookaheads. */
1594 /* After the previous reduction, enter an inconsistent state that has no shift
1595 and multiple reductions. The first reduction has more lookaheads than the
1596 second, so the first should always be preferred as the default reduction if
1597 enabled. The second reduction has one lookahead. */
1601 dnl Visit each state mentioned above.
1605 0 $accept: . start $end
1611 'a' shift, and go to state 1
1619 4 a: 'a' .]AT_COND_CASE([[accepting]], [[ [$end, 'a', 'b']
1621 $end reduce using rule 4 (a)
1622 'a' reduce using rule 4 (a)
1623 'b' reduce using rule 4 (a)]], [[
1625 $default reduce using rule 4 (a)]])[
1630 0 $accept: start . $end
1632 $end shift, and go to state 4
1640 5 b: . %empty [$end, 'a']
1641 6 c: . %empty ['b']]AT_COND_CASE([[most]], [[
1643 'b' reduce using rule 6 (c)
1644 $default reduce using rule 5 (b)]], [[
1646 $end reduce using rule 5 (b)
1647 'a' reduce using rule 5 (b)
1648 'b' reduce using rule 6 (c)]])[
1656 0 $accept: start $end .
1663 1 start: a b . [$end]
1666 'a' shift, and go to state 7
1668 ]AT_COND_CASE([[most]], [[$default]],
1669 [[$end]])[ reduce using rule 1 (start)
1676 'b' shift, and go to state 8
1681 2 start: a b 'a' .]AT_COND_CASE([[accepting]], [[ [$end]
1683 $end reduce using rule 2 (start)]], [[
1685 $default reduce using rule 2 (start)]])[
1690 3 start: a c 'b' .]AT_COND_CASE([[accepting]], [[ [$end]
1692 $end reduce using rule 3 (start)]], [[
1694 $default reduce using rule 3 (start)]])[