]> git.saurik.com Git - bison.git/blame - tests/conflicts.at
* doc/bison.texinfo (Bison Options): Add entry for --print-datadir.
[bison.git] / tests / conflicts.at
CommitLineData
3c31a486 1# Exercising Bison on conflicts. -*- Autotest -*-
69363a9e 2
75ad86ee 3# Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
3c31a486 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
3c31a486 6# it under the terms of the GNU General Public License as published by
f16b0819
PE
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
3c31a486
AD
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
f16b0819 14#
3c31a486 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
3c31a486
AD
17
18AT_BANNER([[Conflicts.]])
19
20
643a5994
AD
21## ---------------- ##
22## S/R in initial. ##
23## ---------------- ##
24
25# I once hacked Bison in such a way that it lost its reductions on the
26# initial state (because it was confusing it with the last state). It
27# took me a while to strip down my failures to this simple case. So
28# make sure it finds the s/r conflict below.
29
30AT_SETUP([S/R in initial])
31
32AT_DATA([[input.y]],
33[[%expect 1
34%%
35exp: e 'e';
36e: 'e' | /* Nothing. */;
37]])
38
b56471a6 39AT_CHECK([bison -o input.c input.y], 0, [],
2bf21a83 40[[input.y:4.9: warning: rule never reduced because of conflicts: e: /* empty */
e8832397 41]])
643a5994
AD
42
43AT_CLEANUP
44
bc933ef1 45
3c31a486
AD
46## ------------------- ##
47## %nonassoc and eof. ##
48## ------------------- ##
49
50AT_SETUP([%nonassoc and eof])
51
9501dc6e 52AT_DATA_GRAMMAR([input.y],
3c31a486
AD
53[[
54%{
55#include <stdio.h>
6e26ca8c 56#include <stdlib.h>
cf806753 57#include <string.h>
1207eeac 58
3c31a486 59#define YYERROR_VERBOSE 1
1207eeac
AD
60static void
61yyerror (const char *msg)
62{
63 fprintf (stderr, "%s\n", msg);
1207eeac 64}
3c31a486
AD
65
66/* The current argument. */
cf806753 67static const char *input;
3c31a486
AD
68
69static int
70yylex (void)
71{
cf806753
PE
72 static size_t toknum;
73 if (! (toknum <= strlen (input)))
74 abort ();
75 return input[toknum++];
3c31a486
AD
76}
77
78%}
79
80%nonassoc '<' '>'
81
82%%
83expr: expr '<' expr
84 | expr '>' expr
85 | '0'
86 ;
87%%
88int
89main (int argc, const char *argv[])
90{
9d774aff 91 input = argc <= 1 ? "" : argv[1];
3c31a486
AD
92 return yyparse ();
93}
94]])
95
96# Specify the output files to avoid problems on different file systems.
b56471a6 97AT_CHECK([bison -o input.c input.y])
1154cced 98AT_COMPILE([input])
3c31a486 99
1154cced 100AT_PARSER_CHECK([./input '0<0'])
3c31a486
AD
101# FIXME: This is an actual bug, but a new one, in the sense that
102# no one has ever spotted it! The messages are *wrong*: there should
103# be nothing there, it should be expected eof.
1154cced 104AT_PARSER_CHECK([./input '0<0<0'], [1], [],
6e649e65 105 [syntax error, unexpected '<', expecting '<' or '>'
3c31a486
AD
106])
107
1154cced
AD
108AT_PARSER_CHECK([./input '0>0'])
109AT_PARSER_CHECK([./input '0>0>0'], [1], [],
6e649e65 110 [syntax error, unexpected '>', expecting '<' or '>'
3c31a486
AD
111])
112
1154cced 113AT_PARSER_CHECK([./input '0<0>0'], [1], [],
6e649e65 114 [syntax error, unexpected '>', expecting '<' or '>'
3c31a486
AD
115])
116
117AT_CLEANUP
118
119
120
121## ------------------------- ##
122## Unresolved SR Conflicts. ##
123## ------------------------- ##
124
125AT_SETUP([Unresolved SR Conflicts])
126
6b98e4b5
AD
127AT_KEYWORDS([report])
128
3c31a486
AD
129AT_DATA([input.y],
130[[%token NUM OP
131%%
132exp: exp OP exp | NUM;
133]])
134
b56471a6 135AT_CHECK([bison -o input.c --report=all input.y], 0, [],
2c8ba4cd 136[input.y: conflicts: 1 shift/reduce
3c31a486
AD
137])
138
139# Check the contents of the report.
140AT_CHECK([cat input.output], [],
2c8ba4cd 141[[State 5 conflicts: 1 shift/reduce
3c31a486
AD
142
143
144Grammar
145
88bce5a2 146 0 $accept: exp $end
6b98e4b5
AD
147
148 1 exp: exp OP exp
149 2 | NUM
3c31a486
AD
150
151
152Terminals, with rules where they appear
153
88bce5a2 154$end (0) 0
3c31a486 155error (256)
007a50a4
AD
156NUM (258) 2
157OP (259) 1
3c31a486
AD
158
159
160Nonterminals, with rules where they appear
161
88bce5a2 162$accept (5)
3c31a486
AD
163 on left: 0
164exp (6)
165 on left: 1 2, on right: 0 1
166
167
168state 0
169
88bce5a2 170 0 $accept: . exp $end
ce4ccb4b
AD
171 1 exp: . exp OP exp
172 2 | . NUM
643a5994 173
87675353 174 NUM shift, and go to state 1
3c31a486 175
87675353 176 exp go to state 2
3c31a486
AD
177
178
179state 1
180
ce4ccb4b 181 2 exp: NUM .
3c31a486 182
87675353 183 $default reduce using rule 2 (exp)
3c31a486
AD
184
185
186state 2
187
88bce5a2 188 0 $accept: exp . $end
ce4ccb4b 189 1 exp: exp . OP exp
3c31a486 190
88bce5a2
AD
191 $end shift, and go to state 3
192 OP shift, and go to state 4
3c31a486
AD
193
194
195state 3
196
88bce5a2 197 0 $accept: exp $end .
3c31a486 198
e8832397 199 $default accept
3c31a486
AD
200
201
202state 4
203
ce4ccb4b
AD
204 1 exp: . exp OP exp
205 1 | exp OP . exp
206 2 | . NUM
3c31a486 207
87675353 208 NUM shift, and go to state 1
3c31a486 209
87675353 210 exp go to state 5
3c31a486
AD
211
212
213state 5
214
a0de5091 215 1 exp: exp . OP exp
88bce5a2 216 1 | exp OP exp . [$end, OP]
3c31a486 217
87675353 218 OP shift, and go to state 4
3c31a486 219
87675353
AD
220 OP [reduce using rule 1 (exp)]
221 $default reduce using rule 1 (exp)
3c31a486
AD
222]])
223
224AT_CLEANUP
225
226
3c31a486 227
ce4ccb4b
AD
228## ----------------------- ##
229## Resolved SR Conflicts. ##
230## ----------------------- ##
231
232AT_SETUP([Resolved SR Conflicts])
3c31a486 233
6b98e4b5
AD
234AT_KEYWORDS([report])
235
3c31a486
AD
236AT_DATA([input.y],
237[[%token NUM OP
ce4ccb4b 238%left OP
3c31a486
AD
239%%
240exp: exp OP exp | NUM;
241]])
242
b56471a6 243AT_CHECK([bison -o input.c --report=all input.y])
3c31a486
AD
244
245# Check the contents of the report.
246AT_CHECK([cat input.output], [],
ce4ccb4b 247[[Grammar
3c31a486 248
88bce5a2 249 0 $accept: exp $end
6b98e4b5
AD
250
251 1 exp: exp OP exp
252 2 | NUM
3c31a486
AD
253
254
255Terminals, with rules where they appear
256
88bce5a2 257$end (0) 0
3c31a486 258error (256)
007a50a4
AD
259NUM (258) 2
260OP (259) 1
3c31a486
AD
261
262
263Nonterminals, with rules where they appear
264
88bce5a2 265$accept (5)
3c31a486
AD
266 on left: 0
267exp (6)
268 on left: 1 2, on right: 0 1
269
270
271state 0
272
88bce5a2 273 0 $accept: . exp $end
ce4ccb4b
AD
274 1 exp: . exp OP exp
275 2 | . NUM
643a5994 276
87675353 277 NUM shift, and go to state 1
3c31a486 278
87675353 279 exp go to state 2
3c31a486
AD
280
281
282state 1
283
ce4ccb4b 284 2 exp: NUM .
3c31a486 285
87675353 286 $default reduce using rule 2 (exp)
3c31a486
AD
287
288
289state 2
290
88bce5a2 291 0 $accept: exp . $end
ce4ccb4b 292 1 exp: exp . OP exp
3c31a486 293
88bce5a2
AD
294 $end shift, and go to state 3
295 OP shift, and go to state 4
3c31a486
AD
296
297
298state 3
299
88bce5a2 300 0 $accept: exp $end .
3c31a486 301
e8832397 302 $default accept
3c31a486
AD
303
304
305state 4
306
ce4ccb4b
AD
307 1 exp: . exp OP exp
308 1 | exp OP . exp
309 2 | . NUM
3c31a486 310
87675353 311 NUM shift, and go to state 1
3c31a486 312
87675353 313 exp go to state 5
3c31a486
AD
314
315
316state 5
317
a0de5091 318 1 exp: exp . OP exp
88bce5a2 319 1 | exp OP exp . [$end, OP]
3c31a486 320
87675353 321 $default reduce using rule 1 (exp)
7ea9a33f 322
4b3d3a8e 323 Conflict between rule 1 and token OP resolved as reduce (%left OP).
bc933ef1
AD
324]])
325
326AT_CLEANUP
327
328
bc933ef1
AD
329## -------------------------------- ##
330## Defaulted Conflicted Reduction. ##
331## -------------------------------- ##
332
333# When there are RR conflicts, some rules are disabled. Usually it is
334# simply displayed as:
335#
88bce5a2
AD
336# $end reduce using rule 3 (num)
337# $end [reduce using rule 4 (id)]
bc933ef1
AD
338#
339# But when `reduce 3' is the default action, we'd produce:
340#
88bce5a2 341# $end [reduce using rule 4 (id)]
bc933ef1
AD
342# $default reduce using rule 3 (num)
343#
344# In this precise case (a reduction is masked by the default
345# reduction), we make the `reduce 3' explicit:
346#
88bce5a2
AD
347# $end reduce using rule 3 (num)
348# $end [reduce using rule 4 (id)]
bc933ef1
AD
349# $default reduce using rule 3 (num)
350#
351# Maybe that's not the best display, but then, please propose something
352# else.
353
354AT_SETUP([Defaulted Conflicted Reduction])
355AT_KEYWORDS([report])
356
357AT_DATA([input.y],
358[[%%
359exp: num | id;
360num: '0';
361id : '0';
362%%
363]])
364
b56471a6 365AT_CHECK([bison -o input.c --report=all input.y], 0, [],
2c8ba4cd 366[[input.y: conflicts: 1 reduce/reduce
2bf21a83 367input.y:4.6-8: warning: rule never reduced because of conflicts: id: '0'
e8832397 368]])
bc933ef1
AD
369
370# Check the contents of the report.
371AT_CHECK([cat input.output], [],
c8f002c7
AD
372[[Rules never reduced
373
374 4 id: '0'
375
376
2c8ba4cd 377State 1 conflicts: 1 reduce/reduce
bc933ef1
AD
378
379
380Grammar
381
88bce5a2 382 0 $accept: exp $end
bc933ef1
AD
383
384 1 exp: num
385 2 | id
386
387 3 num: '0'
388
389 4 id: '0'
390
391
392Terminals, with rules where they appear
393
88bce5a2 394$end (0) 0
bc933ef1
AD
395'0' (48) 3 4
396error (256)
397
398
399Nonterminals, with rules where they appear
400
88bce5a2 401$accept (4)
bc933ef1
AD
402 on left: 0
403exp (5)
404 on left: 1 2, on right: 0
405num (6)
406 on left: 3, on right: 1
407id (7)
408 on left: 4, on right: 2
409
410
411state 0
412
88bce5a2 413 0 $accept: . exp $end
ce4ccb4b
AD
414 1 exp: . num
415 2 | . id
416 3 num: . '0'
417 4 id: . '0'
bc933ef1 418
87675353 419 '0' shift, and go to state 1
bc933ef1 420
87675353
AD
421 exp go to state 2
422 num go to state 3
423 id go to state 4
bc933ef1
AD
424
425
426state 1
427
88bce5a2
AD
428 3 num: '0' . [$end]
429 4 id: '0' . [$end]
bc933ef1 430
88bce5a2
AD
431 $end reduce using rule 3 (num)
432 $end [reduce using rule 4 (id)]
87675353 433 $default reduce using rule 3 (num)
bc933ef1
AD
434
435
436state 2
437
88bce5a2 438 0 $accept: exp . $end
bc933ef1 439
88bce5a2 440 $end shift, and go to state 5
bc933ef1
AD
441
442
443state 3
444
ce4ccb4b 445 1 exp: num .
bc933ef1 446
87675353 447 $default reduce using rule 1 (exp)
bc933ef1
AD
448
449
450state 4
451
ce4ccb4b 452 2 exp: id .
bc933ef1 453
87675353 454 $default reduce using rule 2 (exp)
bc933ef1
AD
455
456
457state 5
458
88bce5a2 459 0 $accept: exp $end .
bc933ef1 460
e8832397 461 $default accept
3c31a486
AD
462]])
463
464AT_CLEANUP
465
466
467
468
469## -------------------- ##
470## %expect not enough. ##
471## -------------------- ##
472
473AT_SETUP([%expect not enough])
474
475AT_DATA([input.y],
476[[%token NUM OP
477%expect 0
478%%
479exp: exp OP exp | NUM;
480]])
481
035aa4a0 482AT_CHECK([bison -o input.c input.y], 1, [],
2c8ba4cd 483[input.y: conflicts: 1 shift/reduce
035aa4a0 484input.y: expected 0 shift/reduce conflicts
3c31a486
AD
485])
486AT_CLEANUP
487
488
489## --------------- ##
490## %expect right. ##
491## --------------- ##
492
493AT_SETUP([%expect right])
494
495AT_DATA([input.y],
496[[%token NUM OP
497%expect 1
498%%
499exp: exp OP exp | NUM;
500]])
501
b56471a6 502AT_CHECK([bison -o input.c input.y])
3c31a486
AD
503AT_CLEANUP
504
505
506## ------------------ ##
507## %expect too much. ##
508## ------------------ ##
509
510AT_SETUP([%expect too much])
511
512AT_DATA([input.y],
513[[%token NUM OP
514%expect 2
515%%
516exp: exp OP exp | NUM;
517]])
518
035aa4a0 519AT_CHECK([bison -o input.c input.y], 1, [],
2c8ba4cd 520[input.y: conflicts: 1 shift/reduce
035aa4a0 521input.y: expected 2 shift/reduce conflicts
3c31a486
AD
522])
523AT_CLEANUP
6876ecd3
PE
524
525
526## ------------------------------ ##
527## %expect with reduce conflicts ##
528## ------------------------------ ##
529
530AT_SETUP([%expect with reduce conflicts])
531
532AT_DATA([input.y],
533[[%expect 0
534%%
535program: a 'a' | a a;
536a: 'a';
537]])
538
035aa4a0 539AT_CHECK([bison -o input.c input.y], 1, [],
2c8ba4cd 540[input.y: conflicts: 1 reduce/reduce
035aa4a0 541input.y: expected 0 reduce/reduce conflicts
6876ecd3
PE
542])
543AT_CLEANUP
39a06c25
PE
544
545
22fccf95
PE
546## ------------------------------- ##
547## %no-default-prec without %prec ##
548## ------------------------------- ##
39a06c25 549
22fccf95 550AT_SETUP([%no-default-prec without %prec])
39a06c25
PE
551
552AT_DATA([[input.y]],
553[[%left '+'
554%left '*'
555
556%%
557
22fccf95 558%no-default-prec;
39a06c25
PE
559
560e: e '+' e
561 | e '*' e
562 | '0'
563 ;
564]])
565
566AT_CHECK([bison -o input.c input.y], 0, [],
567[[input.y: conflicts: 4 shift/reduce
568]])
569AT_CLEANUP
570
571
22fccf95
PE
572## ---------------------------- ##
573## %no-default-prec with %prec ##
574## ---------------------------- ##
39a06c25 575
22fccf95 576AT_SETUP([%no-default-prec with %prec])
39a06c25
PE
577
578AT_DATA([[input.y]],
579[[%left '+'
580%left '*'
581
582%%
583
22fccf95 584%no-default-prec;
39a06c25
PE
585
586e: e '+' e %prec '+'
587 | e '*' e %prec '*'
588 | '0'
589 ;
590]])
591
592AT_CHECK([bison -o input.c input.y])
593AT_CLEANUP
594
595
596## ---------------- ##
22fccf95 597## %default-prec ##
39a06c25
PE
598## ---------------- ##
599
22fccf95 600AT_SETUP([%default-prec])
39a06c25
PE
601
602AT_DATA([[input.y]],
603[[%left '+'
604%left '*'
605
606%%
607
22fccf95 608%default-prec;
39a06c25
PE
609
610e: e '+' e
611 | e '*' e
612 | '0'
613 ;
614]])
615
616AT_CHECK([bison -o input.c input.y])
617AT_CLEANUP
5967f0cf
JD
618
619
620## ---------------------------------------------- ##
621## Unreachable States After Conflict Resolution. ##
622## ---------------------------------------------- ##
623
624AT_SETUP([[Unreachable States After Conflict Resolution]])
625
626# If conflict resolution makes states unreachable, remove those states, report
627# rules that are then unused, and don't report conflicts in those states. Test
628# what happens when a nonterminal becomes useless as a result of state removal
629# since that causes lalr.o's goto map to be rewritten.
630
631AT_DATA([[input.y]],
632[[%output "input.c"
633%left 'a'
634
635%%
636
637start: resolved_conflict 'a' reported_conflicts 'a' ;
638
639/* S/R conflict resolved as shift, so the state with item
640 * (resolved_conflict: 'a' . unreachable1) and all it transition successors are
641 * unreachable, and the associated production is useless. */
642resolved_conflict:
643 'a' unreachable1
644 | %prec 'a'
645 ;
646
647/* S/R conflict that need not be reported since it is unreachable because of
648 * the previous conflict resolution. Nonterminal unreachable1 and all its
649 * productions are useless. */
650unreachable1:
651 'a' unreachable2
652 |
653 ;
654
655/* Likewise for a R/R conflict and nonterminal unreachable2. */
656unreachable2: | ;
657
658/* Make sure remaining S/R and R/R conflicts are still reported correctly even
659 * when their states are renumbered due to state removal. */
660reported_conflicts:
661 'a'
662 | 'a'
663 |
664 ;
665
666]])
667
668AT_CHECK([[bison --report=all input.y]], 0, [],
669[[input.y: conflicts: 1 shift/reduce, 1 reduce/reduce
670input.y:12.5-20: warning: rule never reduced because of conflicts: resolved_conflict: 'a' unreachable1
671input.y:20.5-20: warning: rule never reduced because of conflicts: unreachable1: 'a' unreachable2
672input.y:21.4: warning: rule never reduced because of conflicts: unreachable1: /* empty */
673input.y:25.13: warning: rule never reduced because of conflicts: unreachable2: /* empty */
674input.y:25.16: warning: rule never reduced because of conflicts: unreachable2: /* empty */
675input.y:31.5-7: warning: rule never reduced because of conflicts: reported_conflicts: 'a'
676input.y:32.4: warning: rule never reduced because of conflicts: reported_conflicts: /* empty */
677]])
678
679AT_CHECK([[cat input.output]], 0,
680[[Rules never reduced
681
682 2 resolved_conflict: 'a' unreachable1
683
684 4 unreachable1: 'a' unreachable2
685 5 | /* empty */
686
687 6 unreachable2: /* empty */
688 7 | /* empty */
689
690 9 reported_conflicts: 'a'
691 10 | /* empty */
692
693
694State 4 conflicts: 1 shift/reduce
695State 5 conflicts: 1 reduce/reduce
696
697
698Grammar
699
700 0 $accept: start $end
701
702 1 start: resolved_conflict 'a' reported_conflicts 'a'
703
704 2 resolved_conflict: 'a' unreachable1
705 3 | /* empty */
706
707 4 unreachable1: 'a' unreachable2
708 5 | /* empty */
709
710 6 unreachable2: /* empty */
711 7 | /* empty */
712
713 8 reported_conflicts: 'a'
714 9 | 'a'
715 10 | /* empty */
716
717
718Terminals, with rules where they appear
719
720$end (0) 0
721'a' (97) 1 2 4 8 9
722error (256)
723
724
725Nonterminals, with rules where they appear
726
727$accept (4)
728 on left: 0
729start (5)
730 on left: 1, on right: 0
731resolved_conflict (6)
732 on left: 2 3, on right: 1
733unreachable1 (7)
734 on left: 4 5, on right: 2
735unreachable2 (8)
736 on left: 6 7, on right: 4
737reported_conflicts (9)
738 on left: 8 9 10, on right: 1
739
740
741state 0
742
743 0 $accept: . start $end
744 1 start: . resolved_conflict 'a' reported_conflicts 'a'
745 2 resolved_conflict: . 'a' unreachable1
746 3 | . ['a']
747
748 $default reduce using rule 3 (resolved_conflict)
749
750 start go to state 1
751 resolved_conflict go to state 2
752
753 Conflict between rule 3 and token 'a' resolved as reduce (%left 'a').
754
755
756state 1
757
758 0 $accept: start . $end
759
760 $end shift, and go to state 3
761
762
763state 2
764
765 1 start: resolved_conflict . 'a' reported_conflicts 'a'
766
767 'a' shift, and go to state 4
768
769
770state 3
771
772 0 $accept: start $end .
773
774 $default accept
775
776
777state 4
778
779 1 start: resolved_conflict 'a' . reported_conflicts 'a'
780 8 reported_conflicts: . 'a'
781 9 | . 'a'
782 10 | . ['a']
783
784 'a' shift, and go to state 5
785
786 'a' [reduce using rule 10 (reported_conflicts)]
787
788 reported_conflicts go to state 6
789
790
791state 5
792
793 8 reported_conflicts: 'a' . ['a']
794 9 | 'a' . ['a']
795
796 'a' reduce using rule 8 (reported_conflicts)
797 'a' [reduce using rule 9 (reported_conflicts)]
798 $default reduce using rule 8 (reported_conflicts)
799
800
801state 6
802
803 1 start: resolved_conflict 'a' reported_conflicts . 'a'
804
805 'a' shift, and go to state 7
806
807
808state 7
809
810 1 start: resolved_conflict 'a' reported_conflicts 'a' .
9d774aff 811
5967f0cf
JD
812 $default reduce using rule 1 (start)
813]])
814
815AT_CLEANUP
9d774aff
JD
816
817
818## ------------------------------------------------------------ ##
819## Solved conflicts report for multiple reductions in a state. ##
820## ------------------------------------------------------------ ##
821
822AT_SETUP([[Solved conflicts report for multiple reductions in a state]])
823
824# Used to lose earlier solved conflict messages even within a single S/R/R.
825
826AT_DATA([[input.y]],
827[[%left 'a'
828%right 'b'
829%right 'c'
830%right 'd'
831%%
832start:
833 'a'
834 | empty_a 'a'
835 | 'b'
836 | empty_b 'b'
837 | 'c'
838 | empty_c1 'c'
839 | empty_c2 'c'
840 | empty_c3 'c'
841 ;
842empty_a: %prec 'a' ;
843empty_b: %prec 'b' ;
844empty_c1: %prec 'c' ;
845empty_c2: %prec 'c' ;
846empty_c3: %prec 'd' ;
847]])
848AT_CHECK([[bison --report=all -o input.c input.y]], 0, [], [ignore])
849AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0,
850[[state 0
851
852 0 $accept: . start $end
853 1 start: . 'a'
854 2 | . empty_a 'a'
855 3 | . 'b'
856 4 | . empty_b 'b'
857 5 | . 'c'
858 6 | . empty_c1 'c'
859 7 | . empty_c2 'c'
860 8 | . empty_c3 'c'
861 9 empty_a: . ['a']
862 10 empty_b: . []
863 11 empty_c1: . []
864 12 empty_c2: . []
865 13 empty_c3: . ['c']
866
867 'b' shift, and go to state 1
868
869 'c' reduce using rule 13 (empty_c3)
870 $default reduce using rule 9 (empty_a)
871
872 start go to state 2
873 empty_a go to state 3
874 empty_b go to state 4
875 empty_c1 go to state 5
876 empty_c2 go to state 6
877 empty_c3 go to state 7
878
879 Conflict between rule 9 and token 'a' resolved as reduce (%left 'a').
880 Conflict between rule 10 and token 'b' resolved as shift (%right 'b').
881 Conflict between rule 11 and token 'c' resolved as shift (%right 'c').
882 Conflict between rule 12 and token 'c' resolved as shift (%right 'c').
883 Conflict between rule 13 and token 'c' resolved as reduce ('c' < 'd').
884
885
886state 1
887]])
888
889AT_CLEANUP
890
891
892## ------------------------------------------------------------ ##
893## %nonassoc error actions for multiple reductions in a state. ##
894## ------------------------------------------------------------ ##
895
896# Used to abort when trying to resolve conflicts as %nonassoc error actions for
897# multiple reductions in a state.
898
899# For a %nonassoc error action token, used to print the first remaining
900# reduction on that token without brackets.
901
902AT_SETUP([[%nonassoc error actions for multiple reductions in a state]])
903
904AT_DATA([[input.y]],
905[[%nonassoc 'a' 'b' 'c'
906%%
907start:
908 'a'
909 | empty_a 'a'
910 | 'b'
911 | empty_b 'b'
912 | 'c'
913 | empty_c1 'c'
914 | empty_c2 'c'
915 | empty_c3 'c'
916 ;
917empty_a: %prec 'a' ;
918empty_b: %prec 'b' ;
919empty_c1: %prec 'c' ;
920empty_c2: %prec 'c' ;
921empty_c3: %prec 'c' ;
922]])
923
924AT_CHECK([[bison --report=all -o input.c input.y]], 0, [], [ignore])
925AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0,
926[[state 0
927
928 0 $accept: . start $end
929 1 start: . 'a'
930 2 | . empty_a 'a'
931 3 | . 'b'
932 4 | . empty_b 'b'
933 5 | . 'c'
934 6 | . empty_c1 'c'
935 7 | . empty_c2 'c'
936 8 | . empty_c3 'c'
937 9 empty_a: . []
938 10 empty_b: . []
939 11 empty_c1: . []
940 12 empty_c2: . ['c']
941 13 empty_c3: . ['c']
942
943 'a' error (nonassociative)
944 'b' error (nonassociative)
945 'c' error (nonassociative)
946
947 'c' [reduce using rule 12 (empty_c2)]
948 'c' [reduce using rule 13 (empty_c3)]
949
950 start go to state 1
951 empty_a go to state 2
952 empty_b go to state 3
953 empty_c1 go to state 4
954 empty_c2 go to state 5
955 empty_c3 go to state 6
956
957 Conflict between rule 9 and token 'a' resolved as an error (%nonassoc 'a').
958 Conflict between rule 10 and token 'b' resolved as an error (%nonassoc 'b').
959 Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c').
960
961
962state 1
963]])
964AT_CLEANUP