1 # Exercising Bison on conflicts. -*- Autotest -*-
2 # Copyright (C) 2002 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 AT_BANNER([[Conflicts.]])
22 ## ---------------- ##
24 ## ---------------- ##
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.
31 AT_SETUP([S/R in initial])
37 e: 'e' | /* Nothing. */;
40 AT_CHECK([bison input.y -o input.c])
44 ## ------------------- ##
45 ## %nonassoc and eof. ##
46 ## ------------------- ##
48 AT_SETUP([%nonassoc and eof])
57 #define YYERROR_VERBOSE 1
58 #define yyerror(Msg) \
60 fprintf (stderr, "%s\n", Msg); \
64 /* The current argument. */
65 static const char *input = NULL;
70 /* No token stands for end of file. */
88 main (int argc, const char *argv[])
96 # Specify the output files to avoid problems on different file systems.
97 AT_CHECK([bison input.y -o input.c])
98 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
100 AT_CHECK([./input '0<0'])
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.
104 AT_CHECK([./input '0<0<0'], [1], [],
105 [parse error, unexpected '<', expecting '<' or '>'
108 AT_CHECK([./input '0>0'])
109 AT_CHECK([./input '0>0>0'], [1], [],
110 [parse error, unexpected '>', expecting '<' or '>'
113 AT_CHECK([./input '0<0>0'], [1], [],
114 [parse error, unexpected '>', expecting '<' or '>'
121 ## ------------------------- ##
122 ## Unresolved SR Conflicts. ##
123 ## ------------------------- ##
125 AT_SETUP([Unresolved SR Conflicts])
130 exp: exp OP exp | NUM;
133 AT_CHECK([bison input.y -o input.c -v], 0, [],
134 [input.y contains 1 shift/reduce conflict.
137 # Check the contents of the report.
138 AT_CHECK([cat input.output], [],
139 [[State 5 contains 1 shift/reduce conflict.
146 1 3 exp -> exp OP exp
150 Terminals, with rules where they appear
158 Nonterminals, with rules where they appear
163 on left: 1 2, on right: 0 1
168 $axiom -> . exp $ (rule 0)
170 NUM shift, and go to state 1
178 exp -> NUM . (rule 2)
180 $default reduce using rule 2 (exp)
186 $axiom -> exp . $ (rule 0)
187 exp -> exp . OP exp (rule 1)
189 $ shift, and go to state 3
190 OP shift, and go to state 4
196 $axiom -> exp $ . (rule 0)
203 exp -> exp OP . exp (rule 1)
205 NUM shift, and go to state 1
213 exp -> exp . OP exp (rule 1)
214 exp -> exp OP exp . (rule 1)
216 OP shift, and go to state 4
218 OP [reduce using rule 1 (exp)]
219 $default reduce using rule 1 (exp)
228 ## --------------------- ##
229 ## Solved SR Conflicts. ##
230 ## --------------------- ##
232 AT_SETUP([Solved SR Conflicts])
238 exp: exp OP exp | NUM;
241 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
243 # Check the contents of the report.
244 AT_CHECK([cat input.output], [],
245 [[Conflict in state 5 between rule 2 and token OP resolved as shift.
252 1 4 exp -> exp OP exp
256 Terminals, with rules where they appear
264 Nonterminals, with rules where they appear
269 on left: 1 2, on right: 0 1
274 $axiom -> . exp $ (rule 0)
276 NUM shift, and go to state 1
284 exp -> NUM . (rule 2)
286 $default reduce using rule 2 (exp)
292 $axiom -> exp . $ (rule 0)
293 exp -> exp . OP exp (rule 1)
295 $ shift, and go to state 3
296 OP shift, and go to state 4
302 $axiom -> exp $ . (rule 0)
309 exp -> exp OP . exp (rule 1)
311 NUM shift, and go to state 1
319 exp -> exp . OP exp (rule 1)
320 exp -> exp OP exp . (rule 1)
322 OP shift, and go to state 4
324 $default reduce using rule 1 (exp)
335 ## -------------------- ##
336 ## %expect not enough. ##
337 ## -------------------- ##
339 AT_SETUP([%expect not enough])
345 exp: exp OP exp | NUM;
348 AT_CHECK([bison input.y -o input.c], 1, [],
349 [input.y contains 1 shift/reduce conflict.
350 expected 0 shift/reduce conflicts
355 ## --------------- ##
357 ## --------------- ##
359 AT_SETUP([%expect right])
365 exp: exp OP exp | NUM;
368 AT_CHECK([bison input.y -o input.c], 0)
372 ## ------------------ ##
373 ## %expect too much. ##
374 ## ------------------ ##
376 AT_SETUP([%expect too much])
382 exp: exp OP exp | NUM;
385 AT_CHECK([bison input.y -o input.c], 1, [],
386 [input.y contains 1 shift/reduce conflict.
387 expected 2 shift/reduce conflicts