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