]> git.saurik.com Git - bison.git/blob - tests/conflicts.at
81765aacf7e5119f51f2e1e5d84114d1be0fbfa4
[bison.git] / tests / conflicts.at
1 # Exercising Bison on conflicts. -*- Autotest -*-
2
3 # Copyright (C) 2002-2005, 2007-2013 Free Software Foundation, Inc.
4
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 AT_BANNER([[Conflicts.]])
19
20
21 ## ---------------- ##
22 ## S/R in initial. ##
23 ## ---------------- ##
24
25 # I once hacked Bison in such a way that it lost its reductions on the
26 # initial state (because it was confusing it with the last state). It
27 # took me a while to strip down my failures to this simple case. So
28 # make sure it finds the s/r conflict below.
29
30 AT_SETUP([S/R in initial])
31
32 AT_DATA([[input.y]],
33 [[%expect 1
34 %%
35 exp: e 'e';
36 e: 'e' | /* Nothing. */;
37 ]])
38
39 AT_BISON_CHECK([-o input.c input.y], 0, [],
40 [[input.y:4.9: warning: rule useless in parser due to conflicts: e: /* empty */ [-Wother]
41 ]])
42
43 AT_BISON_CHECK([-fcaret -o input.c input.y], 0, [],
44 [[input.y:4.9: warning: rule useless in parser due to conflicts [-Wother]
45 e: 'e' | /* Nothing. */;
46 ^
47 ]])
48
49 AT_CLEANUP
50
51
52 ## ------------------- ##
53 ## %nonassoc and eof. ##
54 ## ------------------- ##
55
56 AT_SETUP([%nonassoc and eof])
57
58 AT_BISON_OPTION_PUSHDEFS
59 AT_DATA_GRAMMAR([input.y],
60 [[
61 %{
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <string.h>
65 #include <assert.h>
66
67 #define YYERROR_VERBOSE 1
68 ]AT_YYERROR_DEFINE[
69 /* The current argument. */
70 static const char *input;
71
72 static int
73 yylex (void)
74 {
75 static size_t toknum;
76 assert (toknum <= strlen (input));
77 return input[toknum++];
78 }
79
80 %}
81
82 %nonassoc '<' '>'
83
84 %%
85 expr: expr '<' expr
86 | expr '>' expr
87 | '0'
88 ;
89 %%
90 int
91 main (int argc, const char *argv[])
92 {
93 input = argc <= 1 ? "" : argv[1];
94 return yyparse ();
95 }
96 ]])
97 AT_BISON_OPTION_POPDEFS
98
99 m4_pushdef([AT_NONASSOC_AND_EOF_CHECK],
100 [AT_BISON_CHECK([$1[ -o input.c input.y]])
101 AT_COMPILE([input])
102
103 m4_pushdef([AT_EXPECTING], [m4_if($2, [correct], [[, expecting $end]])])
104
105 AT_PARSER_CHECK([./input '0<0'])
106 AT_PARSER_CHECK([./input '0<0<0'], [1], [],
107 [syntax error, unexpected '<'AT_EXPECTING
108 ])
109
110 AT_PARSER_CHECK([./input '0>0'])
111 AT_PARSER_CHECK([./input '0>0>0'], [1], [],
112 [syntax error, unexpected '>'AT_EXPECTING
113 ])
114
115 AT_PARSER_CHECK([./input '0<0>0'], [1], [],
116 [syntax error, unexpected '>'AT_EXPECTING
117 ])
118
119 m4_popdef([AT_EXPECTING])])
120
121 # Expected token list is missing.
122 AT_NONASSOC_AND_EOF_CHECK([], [[incorrect]])
123
124 # We must disable default reductions in inconsistent states in order to
125 # have an explicit list of all expected tokens.
126 AT_NONASSOC_AND_EOF_CHECK([[-Dlr.default-reduction=consistent]],
127 [[correct]])
128
129 # lr.default-reduction=consistent happens to work for this test case.
130 # However, for other grammars, lookahead sets can be merged for
131 # different left contexts, so it is still possible to have an incorrect
132 # expected list. Canonical LR is almost a general solution (that is, it
133 # can fail only when %nonassoc is used), so make sure it gives the same
134 # result as above.
135 AT_NONASSOC_AND_EOF_CHECK([[-Dlr.type=canonical-lr]], [[correct]])
136
137 # parse.lac=full is a completely general solution that does not require
138 # any of the above sacrifices. Of course, it does not extend the
139 # language-recognition power of LALR to (IE)LR, but it does ensure that
140 # the reported list of expected tokens matches what the given parser
141 # would have accepted in place of the unexpected token.
142 AT_NONASSOC_AND_EOF_CHECK([[-Dparse.lac=full]], [[correct]])
143
144 m4_popdef([AT_NONASSOC_AND_EOF_CHECK])
145
146 AT_CLEANUP
147
148
149
150 ## ------------------------------------------- ##
151 ## parse.error=verbose and consistent errors. ##
152 ## ------------------------------------------- ##
153
154 AT_SETUP([[parse.error=verbose and consistent errors]])
155
156 m4_pushdef([AT_CONSISTENT_ERRORS_CHECK], [
157
158 AT_BISON_OPTION_PUSHDEFS([$1])
159
160 m4_pushdef([AT_YYLEX_PROTOTYPE],
161 [AT_SKEL_CC_IF([[int yylex (yy::parser::semantic_type *lvalp)]],
162 [[int yylex (YYSTYPE *lvalp)]])])
163
164 AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
165 [AT_SKEL_JAVA_IF([[
166
167 %code imports {
168 import java.io.IOException;
169 }]], [[
170
171 %code {]AT_SKEL_CC_IF([[
172 #include <string>]], [[
173 #include <assert.h>
174 #include <stdio.h>
175 ]AT_YYERROR_DECLARE])[
176 ]AT_YYLEX_PROTOTYPE[;
177 #define USE(Var)
178 }
179
180 ]AT_SKEL_CC_IF([[%defines]], [[%define api.pure]])])[
181
182 ]$1[
183
184 %define parse.error verbose
185
186 %%
187
188 ]$2[
189
190 ]AT_SKEL_JAVA_IF([[%code lexer {]], [[%%]])[
191
192 /*--------.
193 | yylex. |
194 `--------*/]AT_SKEL_JAVA_IF([[
195
196 public String input = "]$3[";
197 public int index = 0;
198 public int yylex ()
199 {
200 if (index < input.length ())
201 return input.charAt (index++);
202 else
203 return 0;
204 }
205 public Object getLVal ()
206 {
207 return new Integer(1);
208 }]], [[
209
210 ]AT_YYLEX_PROTOTYPE[
211 {
212 static char const *input = "]$3[";
213 *lvalp = 1;
214 return *input++;
215 }]])[
216 ]AT_YYERROR_DEFINE[
217 ]AT_SKEL_JAVA_IF([[
218 };
219
220 %%]])[
221
222 /*-------.
223 | main. |
224 `-------*/
225 ]AT_MAIN_DEFINE
226 ])
227
228 AT_FULL_COMPILE([[input]])
229
230 m4_pushdef([AT_EXPECTING], [m4_if($5, [ab], [[, expecting 'a' or 'b']],
231 $5, [a], [[, expecting 'a']],
232 $5, [b], [[, expecting 'b']])])
233
234 AT_SKEL_JAVA_IF([AT_JAVA_PARSER_CHECK([[input]], [[0]]],
235 [AT_PARSER_CHECK([[./input]], [[1]]]),
236 [[]],
237 [[syntax error, unexpected ]$4[]AT_EXPECTING[
238 ]])
239
240 m4_popdef([AT_EXPECTING])
241 m4_popdef([AT_YYLEX_PROTOTYPE])
242 AT_BISON_OPTION_POPDEFS
243
244 ])
245
246 m4_pushdef([AT_PREVIOUS_STATE_GRAMMAR],
247 [[%nonassoc 'a';
248
249 start: consistent-error-on-a-a 'a' ;
250
251 consistent-error-on-a-a:
252 'a' default-reduction
253 | 'a' default-reduction 'a'
254 | 'a' shift
255 ;
256
257 default-reduction: /*empty*/ ;
258 shift: 'b' ;
259
260 // Provide another context in which all rules are useful so that this
261 // test case looks a little more realistic.
262 start: 'b' consistent-error-on-a-a 'c' ;
263 ]])
264
265 m4_pushdef([AT_PREVIOUS_STATE_INPUT], [[a]])
266
267 # Unfortunately, no expected tokens are reported even though 'b' can be
268 # accepted. Nevertheless, the main point of this test is to make sure
269 # that at least the unexpected token is reported. In a previous version
270 # of Bison, it wasn't reported because the error is detected in a
271 # consistent state with an error action, and that case always triggered
272 # the simple "syntax error" message.
273 #
274 # The point isn't to test IELR here, but state merging happens to
275 # complicate this example.
276 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr]],
277 [AT_PREVIOUS_STATE_GRAMMAR],
278 [AT_PREVIOUS_STATE_INPUT],
279 [[$end]], [[none]])
280 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
281 %glr-parser]],
282 [AT_PREVIOUS_STATE_GRAMMAR],
283 [AT_PREVIOUS_STATE_INPUT],
284 [[$end]], [[none]])
285 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
286 %language "c++"]],
287 [AT_PREVIOUS_STATE_GRAMMAR],
288 [AT_PREVIOUS_STATE_INPUT],
289 [[$end]], [[none]])
290 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
291 %language "java"]],
292 [AT_PREVIOUS_STATE_GRAMMAR],
293 [AT_PREVIOUS_STATE_INPUT],
294 [[end of input]], [[none]])
295
296 # Even canonical LR doesn't foresee the error for 'a'!
297 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
298 %define lr.default-reduction consistent]],
299 [AT_PREVIOUS_STATE_GRAMMAR],
300 [AT_PREVIOUS_STATE_INPUT],
301 [[$end]], [[ab]])
302 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
303 %define lr.default-reduction accepting]],
304 [AT_PREVIOUS_STATE_GRAMMAR],
305 [AT_PREVIOUS_STATE_INPUT],
306 [[$end]], [[ab]])
307 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
308 [AT_PREVIOUS_STATE_GRAMMAR],
309 [AT_PREVIOUS_STATE_INPUT],
310 [[$end]], [[ab]])
311
312 # Only LAC gets it right.
313 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr
314 %define parse.lac full]],
315 [AT_PREVIOUS_STATE_GRAMMAR],
316 [AT_PREVIOUS_STATE_INPUT],
317 [[$end]], [[b]])
318 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
319 %define parse.lac full]],
320 [AT_PREVIOUS_STATE_GRAMMAR],
321 [AT_PREVIOUS_STATE_INPUT],
322 [[$end]], [[b]])
323
324 m4_popdef([AT_PREVIOUS_STATE_GRAMMAR])
325 m4_popdef([AT_PREVIOUS_STATE_INPUT])
326
327 m4_pushdef([AT_USER_ACTION_GRAMMAR],
328 [[%nonassoc 'a';
329
330 // If $$ = 0 here, then we know that the 'a' destructor is being invoked
331 // incorrectly for the 'b' set in the semantic action below. All 'a'
332 // tokens are returned by yylex, which sets $$ = 1.
333 %destructor {
334 if (!$$)
335 fprintf (stderr, "Wrong destructor.\n");
336 } 'a';
337
338 // Rather than depend on an inconsistent state to induce reading a
339 // lookahead as in the previous grammar, just assign the lookahead in a
340 // semantic action. That lookahead isn't needed before either error
341 // action is encountered. In a previous version of Bison, this was a
342 // problem as it meant yychar was not translated into yytoken before
343 // either error action. The second error action thus invoked a
344 // destructor that it selected according to the incorrect yytoken. The
345 // first error action would have reported an incorrect unexpected token
346 // except that, due to the bug described in the previous grammar, the
347 // unexpected token was not reported at all.
348 start: error-reduce consistent-error 'a' { USE ($][3); } ;
349
350 error-reduce:
351 'a' 'a' consistent-reduction consistent-error 'a'
352 { USE (($][1, $][2, $][5)); }
353 | 'a' error
354 { USE ($][1); }
355 ;
356
357 consistent-reduction: /*empty*/ {
358 assert (yychar == YYEMPTY);
359 yylval = 0;
360 yychar = 'b';
361 } ;
362
363 consistent-error:
364 'a' { USE ($][1); }
365 | /*empty*/ %prec 'a'
366 ;
367
368 // Provide another context in which all rules are useful so that this
369 // test case looks a little more realistic.
370 start: 'b' consistent-error 'b' ;
371 ]])
372 m4_pushdef([AT_USER_ACTION_INPUT], [[aa]])
373
374 AT_CONSISTENT_ERRORS_CHECK([[]],
375 [AT_USER_ACTION_GRAMMAR],
376 [AT_USER_ACTION_INPUT],
377 [['b']], [[none]])
378 AT_CONSISTENT_ERRORS_CHECK([[%glr-parser]],
379 [AT_USER_ACTION_GRAMMAR],
380 [AT_USER_ACTION_INPUT],
381 [['b']], [[none]])
382 # No C++ or Java test because yychar cannot be manipulated by users.
383
384 AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reduction consistent]],
385 [AT_USER_ACTION_GRAMMAR],
386 [AT_USER_ACTION_INPUT],
387 [['b']], [[none]])
388
389 # Canonical LR doesn't foresee the error for 'a'!
390 AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reduction accepting]],
391 [AT_USER_ACTION_GRAMMAR],
392 [AT_USER_ACTION_INPUT],
393 [[$end]], [[a]])
394 AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
395 [AT_USER_ACTION_GRAMMAR],
396 [AT_USER_ACTION_INPUT],
397 [[$end]], [[a]])
398
399 AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full]],
400 [AT_USER_ACTION_GRAMMAR],
401 [AT_USER_ACTION_INPUT],
402 [['b']], [[none]])
403 AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full
404 %define lr.default-reduction accepting]],
405 [AT_USER_ACTION_GRAMMAR],
406 [AT_USER_ACTION_INPUT],
407 [[$end]], [[none]])
408
409 m4_popdef([AT_USER_ACTION_GRAMMAR])
410 m4_popdef([AT_USER_ACTION_INPUT])
411
412 m4_popdef([AT_CONSISTENT_ERRORS_CHECK])
413
414 AT_CLEANUP
415
416
417
418 ## ------------------------------------------------------- ##
419 ## LAC: %nonassoc requires splitting canonical LR states. ##
420 ## ------------------------------------------------------- ##
421
422 # This test case demonstrates that, when %nonassoc is used, canonical
423 # LR(1) parser table construction followed by conflict resolution
424 # without further state splitting is not always sufficient to produce a
425 # parser that can detect all syntax errors as soon as possible on one
426 # token of lookahead. However, LAC solves the problem completely even
427 # with minimal LR parser tables.
428
429 AT_SETUP([[LAC: %nonassoc requires splitting canonical LR states]])
430 AT_BISON_OPTION_PUSHDEFS
431 AT_DATA_GRAMMAR([[input.y]],
432 [[%code {
433 #include <stdio.h>
434 ]AT_YYERROR_DECLARE[
435 ]AT_YYLEX_DECLARE[
436 }
437
438 %error-verbose
439 %nonassoc 'a'
440
441 %%
442
443 start:
444 'a' problem 'a' // First context.
445 | 'b' problem 'b' // Second context.
446 | 'c' reduce-nonassoc // Just makes reduce-nonassoc useful.
447 ;
448
449 problem:
450 look reduce-nonassoc
451 | look 'a'
452 | look 'b'
453 ;
454
455 // For the state reached after shifting the 'a' in these productions,
456 // lookahead sets are the same in both the first and second contexts.
457 // Thus, canonical LR reuses the same state for both contexts. However,
458 // the lookahead 'a' for the reduction "look: 'a'" later becomes an
459 // error action only in the first context. In order to immediately
460 // detect the syntax error on 'a' here for only the first context, this
461 // canonical LR state would have to be split into two states, and the
462 // 'a' lookahead would have to be removed from only one of the states.
463 look:
464 'a' // Reduction lookahead set is always ['a', 'b'].
465 | 'a' 'b'
466 | 'a' 'c' // 'c' is forgotten as an expected token.
467 ;
468
469 reduce-nonassoc: %prec 'a';
470
471 %%
472 ]AT_YYERROR_DEFINE[
473 ]AT_YYLEX_DEFINE(["aaa"])[
474 ]AT_MAIN_DEFINE
475 ])
476 AT_BISON_OPTION_POPDEFS
477
478 # Show canonical LR's failure.
479 AT_BISON_CHECK([[-Dlr.type=canonical-lr -o input.c input.y]],
480 [[0]], [[]],
481 [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
482 ]])
483 AT_COMPILE([[input]])
484 AT_PARSER_CHECK([[./input]], [[1]], [[]],
485 [[syntax error, unexpected 'a', expecting 'b'
486 ]])
487
488 # It's corrected by LAC.
489 AT_BISON_CHECK([[-Dlr.type=canonical-lr -Dparse.lac=full \
490 -o input.c input.y]], [[0]], [[]],
491 [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
492 ]])
493 AT_COMPILE([[input]])
494 AT_PARSER_CHECK([[./input]], [[1]], [[]],
495 [[syntax error, unexpected 'a', expecting 'b' or 'c'
496 ]])
497
498 # IELR is sufficient when LAC is used.
499 AT_BISON_CHECK([[-Dlr.type=ielr -Dparse.lac=full -o input.c input.y]],
500 [[0]], [[]],
501 [[input.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
502 ]])
503 AT_COMPILE([[input]])
504 AT_PARSER_CHECK([[./input]], [[1]], [[]],
505 [[syntax error, unexpected 'a', expecting 'b' or 'c'
506 ]])
507
508 AT_CLEANUP
509
510 ## ------------------------- ##
511 ## Unresolved SR Conflicts. ##
512 ## ------------------------- ##
513
514 AT_SETUP([Unresolved SR Conflicts])
515
516 AT_KEYWORDS([report])
517
518 AT_DATA([input.y],
519 [[%token NUM OP
520 %%
521 exp: exp OP exp | NUM;
522 ]])
523
524 AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
525 [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
526 ]])
527
528 # Check the contents of the report.
529 AT_CHECK([cat input.output], [],
530 [[State 5 conflicts: 1 shift/reduce
531
532
533 Grammar
534
535 0 $accept: exp $end
536
537 1 exp: exp OP exp
538 2 | NUM
539
540
541 Terminals, with rules where they appear
542
543 $end (0) 0
544 error (256)
545 NUM (258) 2
546 OP (259) 1
547
548
549 Nonterminals, with rules where they appear
550
551 $accept (5)
552 on left: 0
553 exp (6)
554 on left: 1 2, on right: 0 1
555
556
557 State 0
558
559 0 $accept: . exp $end
560 1 exp: . exp OP exp
561 2 | . NUM
562
563 NUM shift, and go to state 1
564
565 exp go to state 2
566
567
568 State 1
569
570 2 exp: NUM .
571
572 $default reduce using rule 2 (exp)
573
574
575 State 2
576
577 0 $accept: exp . $end
578 1 exp: exp . OP exp
579
580 $end shift, and go to state 3
581 OP shift, and go to state 4
582
583
584 State 3
585
586 0 $accept: exp $end .
587
588 $default accept
589
590
591 State 4
592
593 1 exp: . exp OP exp
594 1 | exp OP . exp
595 2 | . NUM
596
597 NUM shift, and go to state 1
598
599 exp go to state 5
600
601
602 State 5
603
604 1 exp: exp . OP exp
605 1 | exp OP exp . [$end, OP]
606
607 OP shift, and go to state 4
608
609 OP [reduce using rule 1 (exp)]
610 $default reduce using rule 1 (exp)
611 ]])
612
613 AT_CLEANUP
614
615
616
617 ## ----------------------- ##
618 ## Resolved SR Conflicts. ##
619 ## ----------------------- ##
620
621 AT_SETUP([Resolved SR Conflicts])
622
623 AT_KEYWORDS([report])
624
625 AT_DATA([input.y],
626 [[%token NUM OP
627 %left OP
628 %%
629 exp: exp OP exp | NUM;
630 ]])
631
632 AT_BISON_CHECK([-o input.c --report=all input.y])
633
634 # Check the contents of the report.
635 AT_CHECK([cat input.output], [],
636 [[Grammar
637
638 0 $accept: exp $end
639
640 1 exp: exp OP exp
641 2 | NUM
642
643
644 Terminals, with rules where they appear
645
646 $end (0) 0
647 error (256)
648 NUM (258) 2
649 OP (259) 1
650
651
652 Nonterminals, with rules where they appear
653
654 $accept (5)
655 on left: 0
656 exp (6)
657 on left: 1 2, on right: 0 1
658
659
660 State 0
661
662 0 $accept: . exp $end
663 1 exp: . exp OP exp
664 2 | . NUM
665
666 NUM shift, and go to state 1
667
668 exp go to state 2
669
670
671 State 1
672
673 2 exp: NUM .
674
675 $default reduce using rule 2 (exp)
676
677
678 State 2
679
680 0 $accept: exp . $end
681 1 exp: exp . OP exp
682
683 $end shift, and go to state 3
684 OP shift, and go to state 4
685
686
687 State 3
688
689 0 $accept: exp $end .
690
691 $default accept
692
693
694 State 4
695
696 1 exp: . exp OP exp
697 1 | exp OP . exp
698 2 | . NUM
699
700 NUM shift, and go to state 1
701
702 exp go to state 5
703
704
705 State 5
706
707 1 exp: exp . OP exp
708 1 | exp OP exp . [$end, OP]
709
710 $default reduce using rule 1 (exp)
711
712 Conflict between rule 1 and token OP resolved as reduce (%left OP).
713 ]])
714
715 AT_CLEANUP
716
717
718 ## ---------------------- ##
719 ## %precedence suffices. ##
720 ## ---------------------- ##
721
722 AT_SETUP([%precedence suffices])
723
724 AT_DATA([input.y],
725 [[%precedence "then"
726 %precedence "else"
727 %%
728 stmt:
729 "if" cond "then" stmt
730 | "if" cond "then" stmt "else" stmt
731 | "stmt"
732 ;
733
734 cond:
735 "exp"
736 ;
737 ]])
738
739 AT_BISON_CHECK([-o input.c input.y])
740
741 AT_CLEANUP
742
743
744 ## ------------------------------ ##
745 ## %precedence does not suffice. ##
746 ## ------------------------------ ##
747
748 AT_SETUP([%precedence does not suffice])
749
750 AT_DATA([input.y],
751 [[%precedence "then"
752 %precedence "else"
753 %%
754 stmt:
755 "if" cond "then" stmt
756 | "if" cond "then" stmt "else" stmt
757 | "stmt"
758 ;
759
760 cond:
761 "exp"
762 | cond "then" cond
763 ;
764 ]])
765
766 AT_BISON_CHECK([-o input.c input.y], 0, [],
767 [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
768 input.y:12.3-18: warning: rule useless in parser due to conflicts: cond: cond "then" cond [-Wother]
769 ]])
770
771 AT_CLEANUP
772
773
774 ## -------------------------------- ##
775 ## Defaulted Conflicted Reduction. ##
776 ## -------------------------------- ##
777
778 # When there are RR conflicts, some rules are disabled. Usually it is
779 # simply displayed as:
780 #
781 # $end reduce using rule 3 (num)
782 # $end [reduce using rule 4 (id)]
783 #
784 # But when `reduce 3' is the default action, we'd produce:
785 #
786 # $end [reduce using rule 4 (id)]
787 # $default reduce using rule 3 (num)
788 #
789 # In this precise case (a reduction is masked by the default
790 # reduction), we make the `reduce 3' explicit:
791 #
792 # $end reduce using rule 3 (num)
793 # $end [reduce using rule 4 (id)]
794 # $default reduce using rule 3 (num)
795 #
796 # Maybe that's not the best display, but then, please propose something
797 # else.
798
799 AT_SETUP([Defaulted Conflicted Reduction])
800 AT_KEYWORDS([report])
801
802 AT_DATA([input.y],
803 [[%%
804 exp: num | id;
805 num: '0';
806 id : '0';
807 %%
808 ]])
809
810 AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
811 [[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
812 input.y:4.6-8: warning: rule useless in parser due to conflicts: id: '0' [-Wother]
813 ]])
814
815 # Check the contents of the report.
816 AT_CHECK([cat input.output], [],
817 [[Rules useless in parser due to conflicts
818
819 4 id: '0'
820
821
822 State 1 conflicts: 1 reduce/reduce
823
824
825 Grammar
826
827 0 $accept: exp $end
828
829 1 exp: num
830 2 | id
831
832 3 num: '0'
833
834 4 id: '0'
835
836
837 Terminals, with rules where they appear
838
839 $end (0) 0
840 '0' (48) 3 4
841 error (256)
842
843
844 Nonterminals, with rules where they appear
845
846 $accept (4)
847 on left: 0
848 exp (5)
849 on left: 1 2, on right: 0
850 num (6)
851 on left: 3, on right: 1
852 id (7)
853 on left: 4, on right: 2
854
855
856 State 0
857
858 0 $accept: . exp $end
859 1 exp: . num
860 2 | . id
861 3 num: . '0'
862 4 id: . '0'
863
864 '0' shift, and go to state 1
865
866 exp go to state 2
867 num go to state 3
868 id go to state 4
869
870
871 State 1
872
873 3 num: '0' . [$end]
874 4 id: '0' . [$end]
875
876 $end reduce using rule 3 (num)
877 $end [reduce using rule 4 (id)]
878 $default reduce using rule 3 (num)
879
880
881 State 2
882
883 0 $accept: exp . $end
884
885 $end shift, and go to state 5
886
887
888 State 3
889
890 1 exp: num .
891
892 $default reduce using rule 1 (exp)
893
894
895 State 4
896
897 2 exp: id .
898
899 $default reduce using rule 2 (exp)
900
901
902 State 5
903
904 0 $accept: exp $end .
905
906 $default accept
907 ]])
908
909 AT_CLEANUP
910
911
912
913
914 ## -------------------- ##
915 ## %expect not enough. ##
916 ## -------------------- ##
917
918 AT_SETUP([%expect not enough])
919
920 AT_DATA([input.y],
921 [[%token NUM OP
922 %expect 0
923 %%
924 exp: exp OP exp | NUM;
925 ]])
926
927 AT_BISON_CHECK([-o input.c input.y], 1, [],
928 [[input.y: error: shift/reduce conflicts: 1 found, 0 expected
929 ]])
930 AT_CLEANUP
931
932
933 ## --------------- ##
934 ## %expect right. ##
935 ## --------------- ##
936
937 AT_SETUP([%expect right])
938
939 AT_DATA([input.y],
940 [[%token NUM OP
941 %expect 1
942 %%
943 exp: exp OP exp | NUM;
944 ]])
945
946 AT_BISON_CHECK([-o input.c input.y])
947 AT_CLEANUP
948
949
950 ## ------------------ ##
951 ## %expect too much. ##
952 ## ------------------ ##
953
954 AT_SETUP([%expect too much])
955
956 AT_DATA([input.y],
957 [[%token NUM OP
958 %expect 2
959 %%
960 exp: exp OP exp | NUM;
961 ]])
962
963 AT_BISON_CHECK([-o input.c input.y], 1, [],
964 [[input.y: error: shift/reduce conflicts: 1 found, 2 expected
965 ]])
966 AT_CLEANUP
967
968
969 ## ------------------------------- ##
970 ## %expect with reduce conflicts. ##
971 ## ------------------------------- ##
972
973 AT_SETUP([%expect with reduce conflicts])
974
975 AT_DATA([input.y],
976 [[%expect 0
977 %%
978 program: a 'a' | a a;
979 a: 'a';
980 ]])
981
982 AT_BISON_CHECK([-o input.c input.y], 1, [],
983 [[input.y: error: reduce/reduce conflicts: 1 found, 0 expected
984 ]])
985 AT_CLEANUP
986
987
988 ## ------------------------- ##
989 ## %prec with user strings. ##
990 ## ------------------------- ##
991
992 AT_SETUP([%prec with user string])
993
994 AT_DATA([[input.y]],
995 [[%%
996 exp:
997 "foo" %prec "foo"
998 ;
999 ]])
1000
1001 AT_BISON_CHECK([-o input.c input.y])
1002 AT_CLEANUP
1003
1004
1005 ## -------------------------------- ##
1006 ## %no-default-prec without %prec. ##
1007 ## -------------------------------- ##
1008
1009 AT_SETUP([%no-default-prec without %prec])
1010
1011 AT_DATA([[input.y]],
1012 [[%left '+'
1013 %left '*'
1014
1015 %%
1016
1017 %no-default-prec;
1018
1019 e: e '+' e
1020 | e '*' e
1021 | '0'
1022 ;
1023 ]])
1024
1025 AT_BISON_CHECK([-o input.c input.y], 0, [],
1026 [[input.y: warning: 4 shift/reduce conflicts [-Wconflicts-sr]
1027 ]])
1028 AT_CLEANUP
1029
1030
1031 ## ----------------------------- ##
1032 ## %no-default-prec with %prec. ##
1033 ## ----------------------------- ##
1034
1035 AT_SETUP([%no-default-prec with %prec])
1036
1037 AT_DATA([[input.y]],
1038 [[%left '+'
1039 %left '*'
1040
1041 %%
1042
1043 %no-default-prec;
1044
1045 e: e '+' e %prec '+'
1046 | e '*' e %prec '*'
1047 | '0'
1048 ;
1049 ]])
1050
1051 AT_BISON_CHECK([-o input.c input.y])
1052 AT_CLEANUP
1053
1054
1055 ## --------------- ##
1056 ## %default-prec. ##
1057 ## --------------- ##
1058
1059 AT_SETUP([%default-prec])
1060
1061 AT_DATA([[input.y]],
1062 [[%left '+'
1063 %left '*'
1064
1065 %%
1066
1067 %default-prec;
1068
1069 e: e '+' e
1070 | e '*' e
1071 | '0'
1072 ;
1073 ]])
1074
1075 AT_BISON_CHECK([-o input.c input.y])
1076 AT_CLEANUP
1077
1078
1079 ## ---------------------------------------------- ##
1080 ## Unreachable States After Conflict Resolution. ##
1081 ## ---------------------------------------------- ##
1082
1083 AT_SETUP([[Unreachable States After Conflict Resolution]])
1084
1085 # If conflict resolution makes states unreachable, remove those states, report
1086 # rules that are then unused, and don't report conflicts in those states. Test
1087 # what happens when a nonterminal becomes useless as a result of state removal
1088 # since that causes lalr.o's goto map to be rewritten.
1089
1090 AT_DATA([[input.y]],
1091 [[%output "input.c"
1092 %left 'a'
1093
1094 %%
1095
1096 start: resolved_conflict 'a' reported_conflicts 'a' ;
1097
1098 /* S/R conflict resolved as reduce, so the state with item
1099 * (resolved_conflict: 'a' . unreachable1) and all it transition successors are
1100 * unreachable, and the associated production is useless. */
1101 resolved_conflict:
1102 'a' unreachable1
1103 | %prec 'a'
1104 ;
1105
1106 /* S/R conflict that need not be reported since it is unreachable because of
1107 * the previous conflict resolution. Nonterminal unreachable1 and all its
1108 * productions are useless. */
1109 unreachable1:
1110 'a' unreachable2
1111 |
1112 ;
1113
1114 /* Likewise for a R/R conflict and nonterminal unreachable2. */
1115 unreachable2: | ;
1116
1117 /* Make sure remaining S/R and R/R conflicts are still reported correctly even
1118 * when their states are renumbered due to state removal. */
1119 reported_conflicts:
1120 'a'
1121 | 'a'
1122 |
1123 ;
1124
1125 ]])
1126
1127 AT_BISON_CHECK([[--report=all input.y]], 0, [],
1128 [[input.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
1129 input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1130 input.y:12.5-20: warning: rule useless in parser due to conflicts: resolved_conflict: 'a' unreachable1 [-Wother]
1131 input.y:20.5-20: warning: rule useless in parser due to conflicts: unreachable1: 'a' unreachable2 [-Wother]
1132 input.y:21.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */ [-Wother]
1133 input.y:25.13: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
1134 input.y:25.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
1135 input.y:31.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a' [-Wother]
1136 input.y:32.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */ [-Wother]
1137 ]])
1138
1139 AT_CHECK([[cat input.output]], 0,
1140 [[Rules useless in parser due to conflicts
1141
1142 2 resolved_conflict: 'a' unreachable1
1143
1144 4 unreachable1: 'a' unreachable2
1145 5 | /* empty */
1146
1147 6 unreachable2: /* empty */
1148 7 | /* empty */
1149
1150 9 reported_conflicts: 'a'
1151 10 | /* empty */
1152
1153
1154 State 4 conflicts: 1 shift/reduce
1155 State 5 conflicts: 1 reduce/reduce
1156
1157
1158 Grammar
1159
1160 0 $accept: start $end
1161
1162 1 start: resolved_conflict 'a' reported_conflicts 'a'
1163
1164 2 resolved_conflict: 'a' unreachable1
1165 3 | /* empty */
1166
1167 4 unreachable1: 'a' unreachable2
1168 5 | /* empty */
1169
1170 6 unreachable2: /* empty */
1171 7 | /* empty */
1172
1173 8 reported_conflicts: 'a'
1174 9 | 'a'
1175 10 | /* empty */
1176
1177
1178 Terminals, with rules where they appear
1179
1180 $end (0) 0
1181 'a' (97) 1 2 4 8 9
1182 error (256)
1183
1184
1185 Nonterminals, with rules where they appear
1186
1187 $accept (4)
1188 on left: 0
1189 start (5)
1190 on left: 1, on right: 0
1191 resolved_conflict (6)
1192 on left: 2 3, on right: 1
1193 unreachable1 (7)
1194 on left: 4 5, on right: 2
1195 unreachable2 (8)
1196 on left: 6 7, on right: 4
1197 reported_conflicts (9)
1198 on left: 8 9 10, on right: 1
1199
1200
1201 State 0
1202
1203 0 $accept: . start $end
1204 1 start: . resolved_conflict 'a' reported_conflicts 'a'
1205 2 resolved_conflict: . 'a' unreachable1
1206 3 | . ['a']
1207
1208 $default reduce using rule 3 (resolved_conflict)
1209
1210 start go to state 1
1211 resolved_conflict go to state 2
1212
1213 Conflict between rule 3 and token 'a' resolved as reduce (%left 'a').
1214
1215
1216 State 1
1217
1218 0 $accept: start . $end
1219
1220 $end shift, and go to state 3
1221
1222
1223 State 2
1224
1225 1 start: resolved_conflict . 'a' reported_conflicts 'a'
1226
1227 'a' shift, and go to state 4
1228
1229
1230 State 3
1231
1232 0 $accept: start $end .
1233
1234 $default accept
1235
1236
1237 State 4
1238
1239 1 start: resolved_conflict 'a' . reported_conflicts 'a'
1240 8 reported_conflicts: . 'a'
1241 9 | . 'a'
1242 10 | . ['a']
1243
1244 'a' shift, and go to state 5
1245
1246 'a' [reduce using rule 10 (reported_conflicts)]
1247
1248 reported_conflicts go to state 6
1249
1250
1251 State 5
1252
1253 8 reported_conflicts: 'a' . ['a']
1254 9 | 'a' . ['a']
1255
1256 'a' reduce using rule 8 (reported_conflicts)
1257 'a' [reduce using rule 9 (reported_conflicts)]
1258 $default reduce using rule 8 (reported_conflicts)
1259
1260
1261 State 6
1262
1263 1 start: resolved_conflict 'a' reported_conflicts . 'a'
1264
1265 'a' shift, and go to state 7
1266
1267
1268 State 7
1269
1270 1 start: resolved_conflict 'a' reported_conflicts 'a' .
1271
1272 $default reduce using rule 1 (start)
1273 ]])
1274
1275 AT_DATA([[input-keep.y]],
1276 [[%define lr.keep-unreachable-state
1277 ]])
1278 AT_CHECK([[cat input.y >> input-keep.y]])
1279
1280 AT_BISON_CHECK([[input-keep.y]], 0, [],
1281 [[input-keep.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]
1282 input-keep.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
1283 input-keep.y:22.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */ [-Wother]
1284 input-keep.y:26.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
1285 input-keep.y:32.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a' [-Wother]
1286 input-keep.y:33.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */ [-Wother]
1287 ]])
1288
1289 AT_CLEANUP
1290
1291
1292 ## ------------------------------------------------------------ ##
1293 ## Solved conflicts report for multiple reductions in a state. ##
1294 ## ------------------------------------------------------------ ##
1295
1296 AT_SETUP([[Solved conflicts report for multiple reductions in a state]])
1297
1298 # Used to lose earlier solved conflict messages even within a single S/R/R.
1299
1300 AT_DATA([[input.y]],
1301 [[%left 'a'
1302 %right 'b'
1303 %right 'c'
1304 %right 'd'
1305 %%
1306 start:
1307 'a'
1308 | empty_a 'a'
1309 | 'b'
1310 | empty_b 'b'
1311 | 'c'
1312 | empty_c1 'c'
1313 | empty_c2 'c'
1314 | empty_c3 'c'
1315 ;
1316 empty_a: %prec 'a' ;
1317 empty_b: %prec 'b' ;
1318 empty_c1: %prec 'c' ;
1319 empty_c2: %prec 'c' ;
1320 empty_c3: %prec 'd' ;
1321 ]])
1322 AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
1323 AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
1324 [[State 0
1325
1326 0 $accept: . start $end
1327 1 start: . 'a'
1328 2 | . empty_a 'a'
1329 3 | . 'b'
1330 4 | . empty_b 'b'
1331 5 | . 'c'
1332 6 | . empty_c1 'c'
1333 7 | . empty_c2 'c'
1334 8 | . empty_c3 'c'
1335 9 empty_a: . ['a']
1336 10 empty_b: . []
1337 11 empty_c1: . []
1338 12 empty_c2: . []
1339 13 empty_c3: . ['c']
1340
1341 'b' shift, and go to state 1
1342
1343 'c' reduce using rule 13 (empty_c3)
1344 $default reduce using rule 9 (empty_a)
1345
1346 start go to state 2
1347 empty_a go to state 3
1348 empty_b go to state 4
1349 empty_c1 go to state 5
1350 empty_c2 go to state 6
1351 empty_c3 go to state 7
1352
1353 Conflict between rule 9 and token 'a' resolved as reduce (%left 'a').
1354 Conflict between rule 10 and token 'b' resolved as shift (%right 'b').
1355 Conflict between rule 11 and token 'c' resolved as shift (%right 'c').
1356 Conflict between rule 12 and token 'c' resolved as shift (%right 'c').
1357 Conflict between rule 13 and token 'c' resolved as reduce ('c' < 'd').
1358
1359
1360 State 1
1361 ]])
1362
1363 AT_CLEANUP
1364
1365
1366 ## ------------------------------------------------------------ ##
1367 ## %nonassoc error actions for multiple reductions in a state. ##
1368 ## ------------------------------------------------------------ ##
1369
1370 # Used to abort when trying to resolve conflicts as %nonassoc error actions for
1371 # multiple reductions in a state.
1372
1373 # For a %nonassoc error action token, used to print the first remaining
1374 # reduction on that token without brackets.
1375
1376 AT_SETUP([[%nonassoc error actions for multiple reductions in a state]])
1377
1378 AT_DATA([[input.y]],
1379 [[%nonassoc 'a' 'b' 'c'
1380 %%
1381 start:
1382 'a'
1383 | empty_a 'a'
1384 | 'b'
1385 | empty_b 'b'
1386 | 'c'
1387 | empty_c1 'c'
1388 | empty_c2 'c'
1389 | empty_c3 'c'
1390 ;
1391 empty_a: %prec 'a' ;
1392 empty_b: %prec 'b' ;
1393 empty_c1: %prec 'c' ;
1394 empty_c2: %prec 'c' ;
1395 empty_c3: %prec 'c' ;
1396 ]])
1397
1398 AT_BISON_CHECK([[--report=all -o input.c input.y]], 0, [], [ignore])
1399 AT_CHECK([[cat input.output | sed -n '/^State 0$/,/^State 1$/p']], 0,
1400 [[State 0
1401
1402 0 $accept: . start $end
1403 1 start: . 'a'
1404 2 | . empty_a 'a'
1405 3 | . 'b'
1406 4 | . empty_b 'b'
1407 5 | . 'c'
1408 6 | . empty_c1 'c'
1409 7 | . empty_c2 'c'
1410 8 | . empty_c3 'c'
1411 9 empty_a: . []
1412 10 empty_b: . []
1413 11 empty_c1: . []
1414 12 empty_c2: . ['c']
1415 13 empty_c3: . ['c']
1416
1417 'a' error (nonassociative)
1418 'b' error (nonassociative)
1419 'c' error (nonassociative)
1420
1421 'c' [reduce using rule 12 (empty_c2)]
1422 'c' [reduce using rule 13 (empty_c3)]
1423
1424 start go to state 1
1425 empty_a go to state 2
1426 empty_b go to state 3
1427 empty_c1 go to state 4
1428 empty_c2 go to state 5
1429 empty_c3 go to state 6
1430
1431 Conflict between rule 9 and token 'a' resolved as an error (%nonassoc 'a').
1432 Conflict between rule 10 and token 'b' resolved as an error (%nonassoc 'b').
1433 Conflict between rule 11 and token 'c' resolved as an error (%nonassoc 'c').
1434
1435
1436 State 1
1437 ]])
1438 AT_CLEANUP
1439
1440
1441 ## -------------------- ##
1442 ## %expect-rr non GLR. ##
1443 ## -------------------- ##
1444
1445 AT_SETUP([[%expect-rr non GLR]])
1446
1447 AT_DATA([[1.y]],
1448 [[%expect-rr 0
1449 %%
1450 exp: 'a'
1451 ]])
1452
1453 AT_BISON_CHECK([[1.y]], [[0]], [],
1454 [[1.y: warning: %expect-rr applies only to GLR parsers [-Wother]
1455 ]])
1456
1457 AT_DATA([[2.y]],
1458 [[%expect-rr 1
1459 %%
1460 exp: 'a' | 'a';
1461 ]])
1462
1463 AT_BISON_CHECK([[2.y]], [[0]], [],
1464 [[2.y: warning: %expect-rr applies only to GLR parsers [-Wother]
1465 2.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1466 2.y:3.12-14: warning: rule useless in parser due to conflicts: exp: 'a' [-Wother]
1467 ]])
1468
1469 AT_CLEANUP
1470
1471
1472 ## ---------------------------------- ##
1473 ## -W versus %expect and %expect-rr. ##
1474 ## ---------------------------------- ##
1475
1476 AT_SETUP([[-W versus %expect and %expect-rr]])
1477
1478 AT_DATA([[sr-rr.y]],
1479 [[%glr-parser
1480 %%
1481 start: 'a' | A 'a' | B 'a' ;
1482 A: ;
1483 B: ;
1484 ]])
1485 AT_DATA([[sr.y]],
1486 [[%glr-parser
1487 %%
1488 start: 'a' | A 'a' ;
1489 A: ;
1490 ]])
1491 AT_DATA([[rr.y]],
1492 [[%glr-parser
1493 %%
1494 start: A | B ;
1495 A: ;
1496 B: ;
1497 ]])
1498
1499 AT_BISON_CHECK([[sr-rr.y]], [[0]], [[]],
1500 [[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
1501 sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1502 ]])
1503 AT_BISON_CHECK([[-Wno-conflicts-sr sr-rr.y]], [[0]], [[]],
1504 [[sr-rr.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1505 ]])
1506 AT_BISON_CHECK([[-Wno-conflicts-rr sr-rr.y]], [[0]], [[]],
1507 [[sr-rr.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
1508 ]])
1509
1510 [
1511 # This is piece of code is rather complex for a simple task: try every
1512 # combinaison of (0 or 1 real SR) x (0 or 1 real RR) x (don't %expect
1513 # or %expect 0, 1, or 2 SR) x (don't %expect-rr or %expect-rr 0, 1, or 2
1514 # RR).
1515
1516 # Number and types of genuine conflicts in the grammar.
1517 for gram in sr-rr sr rr; do
1518 # Number of expected s/r conflicts.
1519 for sr_exp_i in '' 0 1 2; do
1520 # Number of expected r/r conflicts.
1521 for rr_exp_i in '' 0 1 2; do
1522 test -z "$sr_exp_i" && test -z "$rr_exp_i" && continue
1523
1524 # Build grammar file.
1525 sr_exp=0
1526 rr_exp=0
1527 file=$gram
1528 directives=
1529 if test -n "$sr_exp_i"; then
1530 sr_exp=$sr_exp_i
1531 file=$file-expect-$sr_exp
1532 directives="%expect $sr_exp"
1533 fi
1534 if test -n "$rr_exp_i"; then
1535 rr_exp=$rr_exp_i
1536 file=$file-expect-rr-$rr_exp
1537 directives="$directives %expect-rr $rr_exp"
1538 fi
1539 file=$file.y
1540 echo "$directives" > $file
1541 cat $gram.y >> $file
1542
1543 # Number of found conflicts.
1544 case $gram in
1545 (sr) sr_count=1; rr_count=0;;
1546 (rr) sr_count=0; rr_count=1;;
1547 (sr-rr) sr_count=1; rr_count=1;;
1548 esac
1549
1550 # Update number of expected conflicts: if %expect is given then
1551 # %expect-rr defaults to 0, and vice-versa. Leave empty if
1552 # nothing expected.
1553 case $sr_exp_i:$rr_exp_i in
1554 ?:) rr_exp_i=0;;
1555 :?) sr_exp_i=0;;
1556 esac
1557
1558 # Run tests.
1559 if test $sr_count -eq $sr_exp && test $rr_count -eq $rr_exp; then
1560 ]AT_BISON_CHECK([[-Wnone $file]])[
1561 ]AT_BISON_CHECK([[-Werror $file]])[
1562 else
1563 {
1564 if test -z "$sr_exp_i" && test "$sr_count" -ne 0; then
1565 echo "warning: $sr_count shift/reduce conflicts"
1566 elif test "$sr_exp_i" -ne "$sr_count"; then
1567 echo "error: shift/reduce conflicts: $sr_count found, $sr_exp_i expected"
1568 fi
1569 if test -z "$rr_exp_i" && test "$rr_count" -ne 0; then
1570 echo "warning: $rr_count reduce/reduce conflicts"
1571 elif test "$rr_exp_i" -ne "$rr_count"; then
1572 echo "error: reduce/reduce conflicts: $rr_count found, $rr_exp_i expected"
1573 fi
1574 } | sed -e "s/^/$file: /" > experr
1575 ]AT_BISON_CHECK([[-Wnone $file]], [[1]], [[]], [[experr]])[
1576 ]AT_BISON_CHECK([[-Werror $file]], [[1]], [[]], [[experr]])[
1577 fi
1578 done
1579 done
1580 done]
1581
1582 AT_CLEANUP