]> git.saurik.com Git - bison.git/blame - tests/conflicts.at
Formatting changes.
[bison.git] / tests / conflicts.at
CommitLineData
3c31a486 1# Exercising Bison on conflicts. -*- Autotest -*-
69363a9e 2
d78f0ac9 3# Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008 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
da730230 39AT_BISON_CHECK([-o input.c input.y], 0, [],
cff03fb2 40[[input.y:4.9: warning: rule useless in parser due to 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.
da730230 97AT_BISON_CHECK([-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
da730230 135AT_BISON_CHECK([-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
da730230 243AT_BISON_CHECK([-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
d78f0ac9
AD
329## ---------------------- ##
330## %precedence suffices. ##
331## ---------------------- ##
332
333AT_SETUP([%precedence suffices])
334
335AT_DATA([input.y],
336[[%precedence "then"
337%precedence "else"
338%%
339stmt:
340 "if" cond "then" stmt
341| "if" cond "then" stmt "else" stmt
342| "stmt"
343;
344
345cond:
346 "exp"
347;
348]])
349
350AT_BISON_CHECK([-o input.c input.y])
351
352AT_CLEANUP
353
354
355## ------------------------------ ##
356## %precedence does not suffice. ##
357## ------------------------------ ##
358
359AT_SETUP([%precedence does not suffice])
360
361AT_DATA([input.y],
362[[%precedence "then"
363%precedence "else"
364%%
365stmt:
366 "if" cond "then" stmt
367| "if" cond "then" stmt "else" stmt
368| "stmt"
369;
370
371cond:
372 "exp"
373| cond "then" cond
374;
375]])
376
377AT_BISON_CHECK([-o input.c input.y], 0, [],
378[[input.y: conflicts: 1 shift/reduce
379input.y:12.3-18: warning: rule useless in parser due to conflicts: cond: cond "then" cond
380]])
381
382AT_CLEANUP
383
384
bc933ef1
AD
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#
88bce5a2
AD
392# $end reduce using rule 3 (num)
393# $end [reduce using rule 4 (id)]
bc933ef1
AD
394#
395# But when `reduce 3' is the default action, we'd produce:
396#
88bce5a2 397# $end [reduce using rule 4 (id)]
bc933ef1
AD
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#
88bce5a2
AD
403# $end reduce using rule 3 (num)
404# $end [reduce using rule 4 (id)]
bc933ef1
AD
405# $default reduce using rule 3 (num)
406#
407# Maybe that's not the best display, but then, please propose something
408# else.
409
410AT_SETUP([Defaulted Conflicted Reduction])
411AT_KEYWORDS([report])
412
413AT_DATA([input.y],
414[[%%
415exp: num | id;
416num: '0';
417id : '0';
418%%
419]])
420
da730230 421AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
2c8ba4cd 422[[input.y: conflicts: 1 reduce/reduce
cff03fb2 423input.y:4.6-8: warning: rule useless in parser due to conflicts: id: '0'
e8832397 424]])
bc933ef1
AD
425
426# Check the contents of the report.
427AT_CHECK([cat input.output], [],
cff03fb2 428[[Rules useless in parser due to conflicts
c8f002c7
AD
429
430 4 id: '0'
431
432
2c8ba4cd 433State 1 conflicts: 1 reduce/reduce
bc933ef1
AD
434
435
436Grammar
437
88bce5a2 438 0 $accept: exp $end
bc933ef1
AD
439
440 1 exp: num
441 2 | id
442
443 3 num: '0'
444
445 4 id: '0'
446
447
448Terminals, with rules where they appear
449
88bce5a2 450$end (0) 0
bc933ef1
AD
451'0' (48) 3 4
452error (256)
453
454
455Nonterminals, with rules where they appear
456
88bce5a2 457$accept (4)
bc933ef1
AD
458 on left: 0
459exp (5)
460 on left: 1 2, on right: 0
461num (6)
462 on left: 3, on right: 1
463id (7)
464 on left: 4, on right: 2
465
466
467state 0
468
88bce5a2 469 0 $accept: . exp $end
ce4ccb4b
AD
470 1 exp: . num
471 2 | . id
472 3 num: . '0'
473 4 id: . '0'
bc933ef1 474
87675353 475 '0' shift, and go to state 1
bc933ef1 476
87675353
AD
477 exp go to state 2
478 num go to state 3
479 id go to state 4
bc933ef1
AD
480
481
482state 1
483
88bce5a2
AD
484 3 num: '0' . [$end]
485 4 id: '0' . [$end]
bc933ef1 486
88bce5a2
AD
487 $end reduce using rule 3 (num)
488 $end [reduce using rule 4 (id)]
87675353 489 $default reduce using rule 3 (num)
bc933ef1
AD
490
491
492state 2
493
88bce5a2 494 0 $accept: exp . $end
bc933ef1 495
88bce5a2 496 $end shift, and go to state 5
bc933ef1
AD
497
498
499state 3
500
ce4ccb4b 501 1 exp: num .
bc933ef1 502
87675353 503 $default reduce using rule 1 (exp)
bc933ef1
AD
504
505
506state 4
507
ce4ccb4b 508 2 exp: id .
bc933ef1 509
87675353 510 $default reduce using rule 2 (exp)
bc933ef1
AD
511
512
513state 5
514
88bce5a2 515 0 $accept: exp $end .
bc933ef1 516
e8832397 517 $default accept
3c31a486
AD
518]])
519
520AT_CLEANUP
521
522
523
524
525## -------------------- ##
526## %expect not enough. ##
527## -------------------- ##
528
529AT_SETUP([%expect not enough])
530
531AT_DATA([input.y],
532[[%token NUM OP
533%expect 0
534%%
535exp: exp OP exp | NUM;
536]])
537
da730230 538AT_BISON_CHECK([-o input.c input.y], 1, [],
2c8ba4cd 539[input.y: conflicts: 1 shift/reduce
035aa4a0 540input.y: expected 0 shift/reduce conflicts
3c31a486
AD
541])
542AT_CLEANUP
543
544
545## --------------- ##
546## %expect right. ##
547## --------------- ##
548
549AT_SETUP([%expect right])
550
551AT_DATA([input.y],
552[[%token NUM OP
553%expect 1
554%%
555exp: exp OP exp | NUM;
556]])
557
da730230 558AT_BISON_CHECK([-o input.c input.y])
3c31a486
AD
559AT_CLEANUP
560
561
562## ------------------ ##
563## %expect too much. ##
564## ------------------ ##
565
566AT_SETUP([%expect too much])
567
568AT_DATA([input.y],
569[[%token NUM OP
570%expect 2
571%%
572exp: exp OP exp | NUM;
573]])
574
da730230 575AT_BISON_CHECK([-o input.c input.y], 1, [],
2c8ba4cd 576[input.y: conflicts: 1 shift/reduce
035aa4a0 577input.y: expected 2 shift/reduce conflicts
3c31a486
AD
578])
579AT_CLEANUP
6876ecd3
PE
580
581
582## ------------------------------ ##
583## %expect with reduce conflicts ##
584## ------------------------------ ##
585
586AT_SETUP([%expect with reduce conflicts])
587
588AT_DATA([input.y],
589[[%expect 0
590%%
591program: a 'a' | a a;
592a: 'a';
593]])
594
da730230 595AT_BISON_CHECK([-o input.c input.y], 1, [],
2c8ba4cd 596[input.y: conflicts: 1 reduce/reduce
035aa4a0 597input.y: expected 0 reduce/reduce conflicts
6876ecd3
PE
598])
599AT_CLEANUP
39a06c25
PE
600
601
22fccf95
PE
602## ------------------------------- ##
603## %no-default-prec without %prec ##
604## ------------------------------- ##
39a06c25 605
22fccf95 606AT_SETUP([%no-default-prec without %prec])
39a06c25
PE
607
608AT_DATA([[input.y]],
609[[%left '+'
610%left '*'
611
612%%
613
22fccf95 614%no-default-prec;
39a06c25
PE
615
616e: e '+' e
617 | e '*' e
618 | '0'
619 ;
620]])
621
da730230 622AT_BISON_CHECK([-o input.c input.y], 0, [],
39a06c25
PE
623[[input.y: conflicts: 4 shift/reduce
624]])
625AT_CLEANUP
626
627
22fccf95
PE
628## ---------------------------- ##
629## %no-default-prec with %prec ##
630## ---------------------------- ##
39a06c25 631
22fccf95 632AT_SETUP([%no-default-prec with %prec])
39a06c25
PE
633
634AT_DATA([[input.y]],
635[[%left '+'
636%left '*'
637
638%%
639
22fccf95 640%no-default-prec;
39a06c25
PE
641
642e: e '+' e %prec '+'
643 | e '*' e %prec '*'
644 | '0'
645 ;
646]])
647
da730230 648AT_BISON_CHECK([-o input.c input.y])
39a06c25
PE
649AT_CLEANUP
650
651
652## ---------------- ##
22fccf95 653## %default-prec ##
39a06c25
PE
654## ---------------- ##
655
22fccf95 656AT_SETUP([%default-prec])
39a06c25
PE
657
658AT_DATA([[input.y]],
659[[%left '+'
660%left '*'
661
662%%
663
22fccf95 664%default-prec;
39a06c25
PE
665
666e: e '+' e
667 | e '*' e
668 | '0'
669 ;
670]])
671
da730230 672AT_BISON_CHECK([-o input.c input.y])
39a06c25 673AT_CLEANUP
5967f0cf
JD
674
675
676## ---------------------------------------------- ##
677## Unreachable States After Conflict Resolution. ##
678## ---------------------------------------------- ##
679
680AT_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
687AT_DATA([[input.y]],
688[[%output "input.c"
689%left 'a'
690
691%%
692
693start: resolved_conflict 'a' reported_conflicts 'a' ;
694
31984206 695/* S/R conflict resolved as reduce, so the state with item
5967f0cf
JD
696 * (resolved_conflict: 'a' . unreachable1) and all it transition successors are
697 * unreachable, and the associated production is useless. */
698resolved_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. */
706unreachable1:
707 'a' unreachable2
708 |
709 ;
710
711/* Likewise for a R/R conflict and nonterminal unreachable2. */
712unreachable2: | ;
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. */
716reported_conflicts:
717 'a'
718 | 'a'
719 |
720 ;
721
722]])
723
da730230 724AT_BISON_CHECK([[--report=all input.y]], 0, [],
5967f0cf 725[[input.y: conflicts: 1 shift/reduce, 1 reduce/reduce
cff03fb2
JD
726input.y:12.5-20: warning: rule useless in parser due to conflicts: resolved_conflict: 'a' unreachable1
727input.y:20.5-20: warning: rule useless in parser due to conflicts: unreachable1: 'a' unreachable2
728input.y:21.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
729input.y:25.13: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
730input.y:25.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
731input.y:31.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
732input.y:32.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
5967f0cf
JD
733]])
734
735AT_CHECK([[cat input.output]], 0,
cff03fb2 736[[Rules useless in parser due to conflicts
5967f0cf
JD
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
750State 4 conflicts: 1 shift/reduce
751State 5 conflicts: 1 reduce/reduce
752
753
754Grammar
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
774Terminals, with rules where they appear
775
776$end (0) 0
777'a' (97) 1 2 4 8 9
778error (256)
779
780
781Nonterminals, with rules where they appear
782
783$accept (4)
784 on left: 0
785start (5)
786 on left: 1, on right: 0
787resolved_conflict (6)
788 on left: 2 3, on right: 1
789unreachable1 (7)
790 on left: 4 5, on right: 2
791unreachable2 (8)
792 on left: 6 7, on right: 4
793reported_conflicts (9)
794 on left: 8 9 10, on right: 1
795
796
797state 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
812state 1
813
814 0 $accept: start . $end
815
816 $end shift, and go to state 3
817
818
819state 2
820
821 1 start: resolved_conflict . 'a' reported_conflicts 'a'
822
823 'a' shift, and go to state 4
824
825
826state 3
827
828 0 $accept: start $end .
829
830 $default accept
831
832
833state 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
847state 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
857state 6
858
859 1 start: resolved_conflict 'a' reported_conflicts . 'a'
860
861 'a' shift, and go to state 7
862
863
864state 7
865
866 1 start: resolved_conflict 'a' reported_conflicts 'a' .
9d774aff 867
5967f0cf
JD
868 $default reduce using rule 1 (start)
869]])
870
31984206
JD
871AT_DATA([[input-keep.y]],
872[[%define lr.keep_unreachable_states
873]])
874AT_CHECK([[cat input.y >> input-keep.y]])
875
da730230 876AT_BISON_CHECK([[input-keep.y]], 0, [],
31984206 877[[input-keep.y: conflicts: 2 shift/reduce, 2 reduce/reduce
cff03fb2
JD
878input-keep.y:22.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
879input-keep.y:26.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
880input-keep.y:32.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
881input-keep.y:33.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
31984206
JD
882]])
883
5967f0cf 884AT_CLEANUP
9d774aff
JD
885
886
887## ------------------------------------------------------------ ##
888## Solved conflicts report for multiple reductions in a state. ##
889## ------------------------------------------------------------ ##
890
891AT_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
895AT_DATA([[input.y]],
896[[%left 'a'
897%right 'b'
898%right 'c'
899%right 'd'
900%%
901start:
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 ;
911empty_a: %prec 'a' ;
912empty_b: %prec 'b' ;
913empty_c1: %prec 'c' ;
914empty_c2: %prec 'c' ;
915empty_c3: %prec 'd' ;
916]])
da730230 917AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
9d774aff
JD
918AT_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
d78f0ac9 937
9d774aff
JD
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
955state 1
956]])
957
958AT_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
971AT_SETUP([[%nonassoc error actions for multiple reductions in a state]])
972
973AT_DATA([[input.y]],
974[[%nonassoc 'a' 'b' 'c'
975%%
976start:
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 ;
986empty_a: %prec 'a' ;
987empty_b: %prec 'b' ;
988empty_c1: %prec 'c' ;
989empty_c2: %prec 'c' ;
990empty_c3: %prec 'c' ;
991]])
992
da730230 993AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
9d774aff
JD
994AT_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
1031state 1
1032]])
1033AT_CLEANUP