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