1 # Exercising Bison on conflicts. -*- Autotest -*-
2 # Copyright 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 ## ------------------- ##
23 ## %nonassoc and eof. ##
24 ## ------------------- ##
26 AT_SETUP([%nonassoc and eof])
35 #define YYERROR_VERBOSE 1
36 #define yyerror(Msg) \
38 fprintf (stderr, "%s\n", Msg); \
42 /* The current argument. */
43 static const char *input = NULL;
48 /* No token stands for end of file. */
66 main (int argc, const char *argv[])
74 # Specify the output files to avoid problems on different file systems.
75 AT_CHECK([bison input.y -o input.c])
76 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
78 AT_CHECK([./input '0<0'])
79 # FIXME: This is an actual bug, but a new one, in the sense that
80 # no one has ever spotted it! The messages are *wrong*: there should
81 # be nothing there, it should be expected eof.
82 AT_CHECK([./input '0<0<0'], [1], [],
83 [parse error, unexpected '<', expecting '<' or '>'
86 AT_CHECK([./input '0>0'])
87 AT_CHECK([./input '0>0>0'], [1], [],
88 [parse error, unexpected '>', expecting '<' or '>'
91 AT_CHECK([./input '0<0>0'], [1], [],
92 [parse error, unexpected '>', expecting '<' or '>'
99 ## ------------------------- ##
100 ## Unresolved SR Conflicts. ##
101 ## ------------------------- ##
103 AT_SETUP([Unresolved SR Conflicts])
108 exp: exp OP exp | NUM;
111 AT_CHECK([bison input.y -o input.c -v], 0, [],
112 [input.y contains 1 shift/reduce conflict.
115 # Check the contents of the report.
116 AT_CHECK([cat input.output], [],
117 [[State 5 contains 1 shift/reduce conflict.
124 1 3 exp -> exp OP exp
128 Terminals, with rules where they appear
136 Nonterminals, with rules where they appear
141 on left: 1 2, on right: 0 1
146 NUM shift, and go to state 1
154 exp -> NUM . (rule 2)
156 $default reduce using rule 2 (exp)
162 $axiom -> exp . $ (rule 0)
163 exp -> exp . OP exp (rule 1)
165 $ shift, and go to state 3
166 OP shift, and go to state 4
172 $axiom -> exp $ . (rule 0)
179 exp -> exp OP . exp (rule 1)
181 NUM shift, and go to state 1
189 exp -> exp . OP exp (rule 1)
190 exp -> exp OP exp . (rule 1)
192 OP shift, and go to state 4
194 OP [reduce using rule 1 (exp)]
195 $default reduce using rule 1 (exp)
204 ## --------------------- ##
205 ## Solved SR Conflicts. ##
206 ## --------------------- ##
208 AT_SETUP([Solved SR Conflicts])
214 exp: exp OP exp | NUM;
217 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
219 # Check the contents of the report.
220 AT_CHECK([cat input.output], [],
221 [[Conflict in state 5 between rule 2 and token OP resolved as shift.
228 1 4 exp -> exp OP exp
232 Terminals, with rules where they appear
240 Nonterminals, with rules where they appear
245 on left: 1 2, on right: 0 1
250 NUM shift, and go to state 1
258 exp -> NUM . (rule 2)
260 $default reduce using rule 2 (exp)
266 $axiom -> exp . $ (rule 0)
267 exp -> exp . OP exp (rule 1)
269 $ shift, and go to state 3
270 OP shift, and go to state 4
276 $axiom -> exp $ . (rule 0)
283 exp -> exp OP . exp (rule 1)
285 NUM shift, and go to state 1
293 exp -> exp . OP exp (rule 1)
294 exp -> exp OP exp . (rule 1)
296 OP shift, and go to state 4
298 $default reduce using rule 1 (exp)
309 ## -------------------- ##
310 ## %expect not enough. ##
311 ## -------------------- ##
313 AT_SETUP([%expect not enough])
319 exp: exp OP exp | NUM;
322 AT_CHECK([bison input.y -o input.c], 1, [],
323 [input.y contains 1 shift/reduce conflict.
324 expected 0 shift/reduce conflicts
329 ## --------------- ##
331 ## --------------- ##
333 AT_SETUP([%expect right])
339 exp: exp OP exp | NUM;
342 AT_CHECK([bison input.y -o input.c], 0)
346 ## ------------------ ##
347 ## %expect too much. ##
348 ## ------------------ ##
350 AT_SETUP([%expect too much])
356 exp: exp OP exp | NUM;
359 AT_CHECK([bison input.y -o input.c], 1, [],
360 [input.y contains 1 shift/reduce conflict.
361 expected 2 shift/reduce conflicts