]> git.saurik.com Git - bison.git/blame - tests/conflicts.at
Make benches in a sub dirs.
[bison.git] / tests / conflicts.at
CommitLineData
3c31a486 1# Exercising Bison on conflicts. -*- Autotest -*-
69363a9e 2
75ad86ee 3# Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
3c31a486 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
3c31a486 6# it under the terms of the GNU General Public License as published by
f16b0819
PE
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
3c31a486
AD
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
f16b0819 14#
3c31a486 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
3c31a486
AD
17
18AT_BANNER([[Conflicts.]])
19
20
643a5994
AD
21## ---------------- ##
22## S/R in initial. ##
23## ---------------- ##
24
25# I once hacked Bison in such a way that it lost its reductions on the
26# initial state (because it was confusing it with the last state). It
27# took me a while to strip down my failures to this simple case. So
28# make sure it finds the s/r conflict below.
29
30AT_SETUP([S/R in initial])
31
32AT_DATA([[input.y]],
33[[%expect 1
34%%
35exp: e 'e';
36e: 'e' | /* Nothing. */;
37]])
38
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
bc933ef1
AD
329## -------------------------------- ##
330## Defaulted Conflicted Reduction. ##
331## -------------------------------- ##
332
333# When there are RR conflicts, some rules are disabled. Usually it is
334# simply displayed as:
335#
88bce5a2
AD
336# $end reduce using rule 3 (num)
337# $end [reduce using rule 4 (id)]
bc933ef1
AD
338#
339# But when `reduce 3' is the default action, we'd produce:
340#
88bce5a2 341# $end [reduce using rule 4 (id)]
bc933ef1
AD
342# $default reduce using rule 3 (num)
343#
344# In this precise case (a reduction is masked by the default
345# reduction), we make the `reduce 3' explicit:
346#
88bce5a2
AD
347# $end reduce using rule 3 (num)
348# $end [reduce using rule 4 (id)]
bc933ef1
AD
349# $default reduce using rule 3 (num)
350#
351# Maybe that's not the best display, but then, please propose something
352# else.
353
354AT_SETUP([Defaulted Conflicted Reduction])
355AT_KEYWORDS([report])
356
357AT_DATA([input.y],
358[[%%
359exp: num | id;
360num: '0';
361id : '0';
362%%
363]])
364
da730230 365AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
2c8ba4cd 366[[input.y: conflicts: 1 reduce/reduce
cff03fb2 367input.y:4.6-8: warning: rule useless in parser due to conflicts: id: '0'
e8832397 368]])
bc933ef1
AD
369
370# Check the contents of the report.
371AT_CHECK([cat input.output], [],
cff03fb2 372[[Rules useless in parser due to conflicts
c8f002c7
AD
373
374 4 id: '0'
375
376
2c8ba4cd 377State 1 conflicts: 1 reduce/reduce
bc933ef1
AD
378
379
380Grammar
381
88bce5a2 382 0 $accept: exp $end
bc933ef1
AD
383
384 1 exp: num
385 2 | id
386
387 3 num: '0'
388
389 4 id: '0'
390
391
392Terminals, with rules where they appear
393
88bce5a2 394$end (0) 0
bc933ef1
AD
395'0' (48) 3 4
396error (256)
397
398
399Nonterminals, with rules where they appear
400
88bce5a2 401$accept (4)
bc933ef1
AD
402 on left: 0
403exp (5)
404 on left: 1 2, on right: 0
405num (6)
406 on left: 3, on right: 1
407id (7)
408 on left: 4, on right: 2
409
410
411state 0
412
88bce5a2 413 0 $accept: . exp $end
ce4ccb4b
AD
414 1 exp: . num
415 2 | . id
416 3 num: . '0'
417 4 id: . '0'
bc933ef1 418
87675353 419 '0' shift, and go to state 1
bc933ef1 420
87675353
AD
421 exp go to state 2
422 num go to state 3
423 id go to state 4
bc933ef1
AD
424
425
426state 1
427
88bce5a2
AD
428 3 num: '0' . [$end]
429 4 id: '0' . [$end]
bc933ef1 430
88bce5a2
AD
431 $end reduce using rule 3 (num)
432 $end [reduce using rule 4 (id)]
87675353 433 $default reduce using rule 3 (num)
bc933ef1
AD
434
435
436state 2
437
88bce5a2 438 0 $accept: exp . $end
bc933ef1 439
88bce5a2 440 $end shift, and go to state 5
bc933ef1
AD
441
442
443state 3
444
ce4ccb4b 445 1 exp: num .
bc933ef1 446
87675353 447 $default reduce using rule 1 (exp)
bc933ef1
AD
448
449
450state 4
451
ce4ccb4b 452 2 exp: id .
bc933ef1 453
87675353 454 $default reduce using rule 2 (exp)
bc933ef1
AD
455
456
457state 5
458
88bce5a2 459 0 $accept: exp $end .
bc933ef1 460
e8832397 461 $default accept
3c31a486
AD
462]])
463
464AT_CLEANUP
465
466
467
468
469## -------------------- ##
470## %expect not enough. ##
471## -------------------- ##
472
473AT_SETUP([%expect not enough])
474
475AT_DATA([input.y],
476[[%token NUM OP
477%expect 0
478%%
479exp: exp OP exp | NUM;
480]])
481
da730230 482AT_BISON_CHECK([-o input.c input.y], 1, [],
2c8ba4cd 483[input.y: conflicts: 1 shift/reduce
035aa4a0 484input.y: expected 0 shift/reduce conflicts
3c31a486
AD
485])
486AT_CLEANUP
487
488
489## --------------- ##
490## %expect right. ##
491## --------------- ##
492
493AT_SETUP([%expect right])
494
495AT_DATA([input.y],
496[[%token NUM OP
497%expect 1
498%%
499exp: exp OP exp | NUM;
500]])
501
da730230 502AT_BISON_CHECK([-o input.c input.y])
3c31a486
AD
503AT_CLEANUP
504
505
506## ------------------ ##
507## %expect too much. ##
508## ------------------ ##
509
510AT_SETUP([%expect too much])
511
512AT_DATA([input.y],
513[[%token NUM OP
514%expect 2
515%%
516exp: exp OP exp | NUM;
517]])
518
da730230 519AT_BISON_CHECK([-o input.c input.y], 1, [],
2c8ba4cd 520[input.y: conflicts: 1 shift/reduce
035aa4a0 521input.y: expected 2 shift/reduce conflicts
3c31a486
AD
522])
523AT_CLEANUP
6876ecd3
PE
524
525
526## ------------------------------ ##
527## %expect with reduce conflicts ##
528## ------------------------------ ##
529
530AT_SETUP([%expect with reduce conflicts])
531
532AT_DATA([input.y],
533[[%expect 0
534%%
535program: a 'a' | a a;
536a: 'a';
537]])
538
da730230 539AT_BISON_CHECK([-o input.c input.y], 1, [],
2c8ba4cd 540[input.y: conflicts: 1 reduce/reduce
035aa4a0 541input.y: expected 0 reduce/reduce conflicts
6876ecd3
PE
542])
543AT_CLEANUP
39a06c25
PE
544
545
22fccf95
PE
546## ------------------------------- ##
547## %no-default-prec without %prec ##
548## ------------------------------- ##
39a06c25 549
22fccf95 550AT_SETUP([%no-default-prec without %prec])
39a06c25
PE
551
552AT_DATA([[input.y]],
553[[%left '+'
554%left '*'
555
556%%
557
22fccf95 558%no-default-prec;
39a06c25
PE
559
560e: e '+' e
561 | e '*' e
562 | '0'
563 ;
564]])
565
da730230 566AT_BISON_CHECK([-o input.c input.y], 0, [],
39a06c25
PE
567[[input.y: conflicts: 4 shift/reduce
568]])
569AT_CLEANUP
570
571
22fccf95
PE
572## ---------------------------- ##
573## %no-default-prec with %prec ##
574## ---------------------------- ##
39a06c25 575
22fccf95 576AT_SETUP([%no-default-prec with %prec])
39a06c25
PE
577
578AT_DATA([[input.y]],
579[[%left '+'
580%left '*'
581
582%%
583
22fccf95 584%no-default-prec;
39a06c25
PE
585
586e: e '+' e %prec '+'
587 | e '*' e %prec '*'
588 | '0'
589 ;
590]])
591
da730230 592AT_BISON_CHECK([-o input.c input.y])
39a06c25
PE
593AT_CLEANUP
594
595
596## ---------------- ##
22fccf95 597## %default-prec ##
39a06c25
PE
598## ---------------- ##
599
22fccf95 600AT_SETUP([%default-prec])
39a06c25
PE
601
602AT_DATA([[input.y]],
603[[%left '+'
604%left '*'
605
606%%
607
22fccf95 608%default-prec;
39a06c25
PE
609
610e: e '+' e
611 | e '*' e
612 | '0'
613 ;
614]])
615
da730230 616AT_BISON_CHECK([-o input.c input.y])
39a06c25 617AT_CLEANUP
5967f0cf
JD
618
619
620## ---------------------------------------------- ##
621## Unreachable States After Conflict Resolution. ##
622## ---------------------------------------------- ##
623
624AT_SETUP([[Unreachable States After Conflict Resolution]])
625
626# If conflict resolution makes states unreachable, remove those states, report
627# rules that are then unused, and don't report conflicts in those states. Test
628# what happens when a nonterminal becomes useless as a result of state removal
629# since that causes lalr.o's goto map to be rewritten.
630
631AT_DATA([[input.y]],
632[[%output "input.c"
633%left 'a'
634
635%%
636
637start: resolved_conflict 'a' reported_conflicts 'a' ;
638
31984206 639/* S/R conflict resolved as reduce, so the state with item
5967f0cf
JD
640 * (resolved_conflict: 'a' . unreachable1) and all it transition successors are
641 * unreachable, and the associated production is useless. */
642resolved_conflict:
643 'a' unreachable1
644 | %prec 'a'
645 ;
646
647/* S/R conflict that need not be reported since it is unreachable because of
648 * the previous conflict resolution. Nonterminal unreachable1 and all its
649 * productions are useless. */
650unreachable1:
651 'a' unreachable2
652 |
653 ;
654
655/* Likewise for a R/R conflict and nonterminal unreachable2. */
656unreachable2: | ;
657
658/* Make sure remaining S/R and R/R conflicts are still reported correctly even
659 * when their states are renumbered due to state removal. */
660reported_conflicts:
661 'a'
662 | 'a'
663 |
664 ;
665
666]])
667
da730230 668AT_BISON_CHECK([[--report=all input.y]], 0, [],
5967f0cf 669[[input.y: conflicts: 1 shift/reduce, 1 reduce/reduce
cff03fb2
JD
670input.y:12.5-20: warning: rule useless in parser due to conflicts: resolved_conflict: 'a' unreachable1
671input.y:20.5-20: warning: rule useless in parser due to conflicts: unreachable1: 'a' unreachable2
672input.y:21.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
673input.y:25.13: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
674input.y:25.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
675input.y:31.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
676input.y:32.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
5967f0cf
JD
677]])
678
679AT_CHECK([[cat input.output]], 0,
cff03fb2 680[[Rules useless in parser due to conflicts
5967f0cf
JD
681
682 2 resolved_conflict: 'a' unreachable1
683
684 4 unreachable1: 'a' unreachable2
685 5 | /* empty */
686
687 6 unreachable2: /* empty */
688 7 | /* empty */
689
690 9 reported_conflicts: 'a'
691 10 | /* empty */
692
693
694State 4 conflicts: 1 shift/reduce
695State 5 conflicts: 1 reduce/reduce
696
697
698Grammar
699
700 0 $accept: start $end
701
702 1 start: resolved_conflict 'a' reported_conflicts 'a'
703
704 2 resolved_conflict: 'a' unreachable1
705 3 | /* empty */
706
707 4 unreachable1: 'a' unreachable2
708 5 | /* empty */
709
710 6 unreachable2: /* empty */
711 7 | /* empty */
712
713 8 reported_conflicts: 'a'
714 9 | 'a'
715 10 | /* empty */
716
717
718Terminals, with rules where they appear
719
720$end (0) 0
721'a' (97) 1 2 4 8 9
722error (256)
723
724
725Nonterminals, with rules where they appear
726
727$accept (4)
728 on left: 0
729start (5)
730 on left: 1, on right: 0
731resolved_conflict (6)
732 on left: 2 3, on right: 1
733unreachable1 (7)
734 on left: 4 5, on right: 2
735unreachable2 (8)
736 on left: 6 7, on right: 4
737reported_conflicts (9)
738 on left: 8 9 10, on right: 1
739
740
741state 0
742
743 0 $accept: . start $end
744 1 start: . resolved_conflict 'a' reported_conflicts 'a'
745 2 resolved_conflict: . 'a' unreachable1
746 3 | . ['a']
747
748 $default reduce using rule 3 (resolved_conflict)
749
750 start go to state 1
751 resolved_conflict go to state 2
752
753 Conflict between rule 3 and token 'a' resolved as reduce (%left 'a').
754
755
756state 1
757
758 0 $accept: start . $end
759
760 $end shift, and go to state 3
761
762
763state 2
764
765 1 start: resolved_conflict . 'a' reported_conflicts 'a'
766
767 'a' shift, and go to state 4
768
769
770state 3
771
772 0 $accept: start $end .
773
774 $default accept
775
776
777state 4
778
779 1 start: resolved_conflict 'a' . reported_conflicts 'a'
780 8 reported_conflicts: . 'a'
781 9 | . 'a'
782 10 | . ['a']
783
784 'a' shift, and go to state 5
785
786 'a' [reduce using rule 10 (reported_conflicts)]
787
788 reported_conflicts go to state 6
789
790
791state 5
792
793 8 reported_conflicts: 'a' . ['a']
794 9 | 'a' . ['a']
795
796 'a' reduce using rule 8 (reported_conflicts)
797 'a' [reduce using rule 9 (reported_conflicts)]
798 $default reduce using rule 8 (reported_conflicts)
799
800
801state 6
802
803 1 start: resolved_conflict 'a' reported_conflicts . 'a'
804
805 'a' shift, and go to state 7
806
807
808state 7
809
810 1 start: resolved_conflict 'a' reported_conflicts 'a' .
9d774aff 811
5967f0cf
JD
812 $default reduce using rule 1 (start)
813]])
814
31984206
JD
815AT_DATA([[input-keep.y]],
816[[%define lr.keep_unreachable_states
817]])
818AT_CHECK([[cat input.y >> input-keep.y]])
819
da730230 820AT_BISON_CHECK([[input-keep.y]], 0, [],
31984206 821[[input-keep.y: conflicts: 2 shift/reduce, 2 reduce/reduce
cff03fb2
JD
822input-keep.y:22.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
823input-keep.y:26.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
824input-keep.y:32.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
825input-keep.y:33.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
31984206
JD
826]])
827
5967f0cf 828AT_CLEANUP
9d774aff
JD
829
830
831## ------------------------------------------------------------ ##
832## Solved conflicts report for multiple reductions in a state. ##
833## ------------------------------------------------------------ ##
834
835AT_SETUP([[Solved conflicts report for multiple reductions in a state]])
836
837# Used to lose earlier solved conflict messages even within a single S/R/R.
838
839AT_DATA([[input.y]],
840[[%left 'a'
841%right 'b'
842%right 'c'
843%right 'd'
844%%
845start:
846 'a'
847 | empty_a 'a'
848 | 'b'
849 | empty_b 'b'
850 | 'c'
851 | empty_c1 'c'
852 | empty_c2 'c'
853 | empty_c3 'c'
854 ;
855empty_a: %prec 'a' ;
856empty_b: %prec 'b' ;
857empty_c1: %prec 'c' ;
858empty_c2: %prec 'c' ;
859empty_c3: %prec 'd' ;
860]])
da730230 861AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
9d774aff
JD
862AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0,
863[[state 0
864
865 0 $accept: . start $end
866 1 start: . 'a'
867 2 | . empty_a 'a'
868 3 | . 'b'
869 4 | . empty_b 'b'
870 5 | . 'c'
871 6 | . empty_c1 'c'
872 7 | . empty_c2 'c'
873 8 | . empty_c3 'c'
874 9 empty_a: . ['a']
875 10 empty_b: . []
876 11 empty_c1: . []
877 12 empty_c2: . []
878 13 empty_c3: . ['c']
879
880 'b' shift, and go to state 1
881
882 'c' reduce using rule 13 (empty_c3)
883 $default reduce using rule 9 (empty_a)
884
885 start go to state 2
886 empty_a go to state 3
887 empty_b go to state 4
888 empty_c1 go to state 5
889 empty_c2 go to state 6
890 empty_c3 go to state 7
891
892 Conflict between rule 9 and token 'a' resolved as reduce (%left 'a').
893 Conflict between rule 10 and token 'b' resolved as shift (%right 'b').
894 Conflict between rule 11 and token 'c' resolved as shift (%right 'c').
895 Conflict between rule 12 and token 'c' resolved as shift (%right 'c').
896 Conflict between rule 13 and token 'c' resolved as reduce ('c' < 'd').
897
898
899state 1
900]])
901
902AT_CLEANUP
903
904
905## ------------------------------------------------------------ ##
906## %nonassoc error actions for multiple reductions in a state. ##
907## ------------------------------------------------------------ ##
908
909# Used to abort when trying to resolve conflicts as %nonassoc error actions for
910# multiple reductions in a state.
911
912# For a %nonassoc error action token, used to print the first remaining
913# reduction on that token without brackets.
914
915AT_SETUP([[%nonassoc error actions for multiple reductions in a state]])
916
917AT_DATA([[input.y]],
918[[%nonassoc 'a' 'b' 'c'
919%%
920start:
921 'a'
922 | empty_a 'a'
923 | 'b'
924 | empty_b 'b'
925 | 'c'
926 | empty_c1 'c'
927 | empty_c2 'c'
928 | empty_c3 'c'
929 ;
930empty_a: %prec 'a' ;
931empty_b: %prec 'b' ;
932empty_c1: %prec 'c' ;
933empty_c2: %prec 'c' ;
934empty_c3: %prec 'c' ;
935]])
936
da730230 937AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
9d774aff
JD
938AT_CHECK([[cat input.output | sed -n '/^state 0$/,/^state 1$/p']], 0,
939[[state 0
940
941 0 $accept: . start $end
942 1 start: . 'a'
943 2 | . empty_a 'a'
944 3 | . 'b'
945 4 | . empty_b 'b'
946 5 | . 'c'
947 6 | . empty_c1 'c'
948 7 | . empty_c2 'c'
949 8 | . empty_c3 'c'
950 9 empty_a: . []
951 10 empty_b: . []
952 11 empty_c1: . []
953 12 empty_c2: . ['c']
954 13 empty_c3: . ['c']
955
956 'a' error (nonassociative)
957 'b' error (nonassociative)
958 'c' error (nonassociative)
959
960 'c' [reduce using rule 12 (empty_c2)]
961 'c' [reduce using rule 13 (empty_c3)]
962
963 start go to state 1
964 empty_a go to state 2
965 empty_b go to state 3
966 empty_c1 go to state 4
967 empty_c2 go to state 5
968 empty_c3 go to state 6
969
970 Conflict between rule 9 and token 'a' resolved as an error (%nonassoc 'a').
971 Conflict between rule 10 and token 'b' resolved as an error (%nonassoc 'b').
972 Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c').
973
974
975state 1
976]])
977AT_CLEANUP