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