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])
54 /* We don't need a perfect malloc for these tests. */
62 #define YYERROR_VERBOSE 1
64 yyerror (const char *msg)
66 fprintf (stderr, "%s\n", msg);
70 /* The current argument. */
71 static const char *input = NULL;
76 /* No token stands for end of file. */
94 main (int argc, const char *argv[])
102 # Specify the output files to avoid problems on different file systems.
103 AT_CHECK([bison input.y -o input.c])
104 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
106 AT_CHECK([./input '0<0'])
107 # FIXME: This is an actual bug, but a new one, in the sense that
108 # no one has ever spotted it! The messages are *wrong*: there should
109 # be nothing there, it should be expected eof.
110 AT_CHECK([./input '0<0<0'], [1], [],
111 [parse error, unexpected '<', expecting '<' or '>'
114 AT_CHECK([./input '0>0'])
115 AT_CHECK([./input '0>0>0'], [1], [],
116 [parse error, unexpected '>', expecting '<' or '>'
119 AT_CHECK([./input '0<0>0'], [1], [],
120 [parse error, unexpected '>', expecting '<' or '>'
127 ## ------------------------- ##
128 ## Unresolved SR Conflicts. ##
129 ## ------------------------- ##
131 AT_SETUP([Unresolved SR Conflicts])
136 exp: exp OP exp | NUM;
139 AT_CHECK([bison input.y -o input.c --report=all], 0, [],
140 [input.y contains 1 shift/reduce conflict.
143 # Check the contents of the report.
144 AT_CHECK([cat input.output], [],
145 [[State 5 contains 1 shift/reduce conflict.
152 1 3 exp -> exp OP exp
156 Terminals, with rules where they appear
164 Nonterminals, with rules where they appear
169 on left: 1 2, on right: 0 1
174 $axiom -> . exp $ (rule 0)
175 exp -> . exp OP exp (rule 1)
176 exp -> . NUM (rule 2)
178 NUM shift, and go to state 1
186 exp -> NUM . (rule 2)
188 $default reduce using rule 2 (exp)
194 $axiom -> exp . $ (rule 0)
195 exp -> exp . OP exp (rule 1)
197 $ shift, and go to state 3
198 OP shift, and go to state 4
204 $axiom -> exp $ . (rule 0)
211 exp -> . exp OP exp (rule 1)
212 exp -> exp OP . exp (rule 1)
213 exp -> . NUM (rule 2)
215 NUM shift, and go to state 1
223 exp -> exp . OP exp [$, OP] (rule 1)
224 exp -> exp OP exp . [$, OP] (rule 1)
226 OP shift, and go to state 4
228 OP [reduce using rule 1 (exp)]
229 $default reduce using rule 1 (exp)
238 ## --------------------- ##
239 ## Solved SR Conflicts. ##
240 ## --------------------- ##
242 AT_SETUP([Solved SR Conflicts])
248 exp: exp OP exp | NUM;
251 AT_CHECK([bison input.y -o input.c --report=all], 0, [], [])
253 # Check the contents of the report.
254 AT_CHECK([cat input.output], [],
259 1 4 exp -> exp OP exp
263 Terminals, with rules where they appear
271 Nonterminals, with rules where they appear
276 on left: 1 2, on right: 0 1
281 $axiom -> . exp $ (rule 0)
282 exp -> . exp OP exp (rule 1)
283 exp -> . NUM (rule 2)
285 NUM shift, and go to state 1
293 exp -> NUM . (rule 2)
295 $default reduce using rule 2 (exp)
301 $axiom -> exp . $ (rule 0)
302 exp -> exp . OP exp (rule 1)
304 $ shift, and go to state 3
305 OP shift, and go to state 4
311 $axiom -> exp $ . (rule 0)
318 exp -> . exp OP exp (rule 1)
319 exp -> exp OP . exp (rule 1)
320 exp -> . NUM (rule 2)
322 NUM shift, and go to state 1
330 exp -> exp . OP exp [$] (rule 1)
331 exp -> exp OP exp . [$] (rule 1)
333 OP shift, and go to state 4
335 $default reduce using rule 1 (exp)
337 Conflict between rule 2 and token OP resolved as reduce (%right OP).
347 ## -------------------- ##
348 ## %expect not enough. ##
349 ## -------------------- ##
351 AT_SETUP([%expect not enough])
357 exp: exp OP exp | NUM;
360 AT_CHECK([bison input.y -o input.c], 1, [],
361 [input.y contains 1 shift/reduce conflict.
362 expected 0 shift/reduce conflicts
367 ## --------------- ##
369 ## --------------- ##
371 AT_SETUP([%expect right])
377 exp: exp OP exp | NUM;
380 AT_CHECK([bison input.y -o input.c], 0)
384 ## ------------------ ##
385 ## %expect too much. ##
386 ## ------------------ ##
388 AT_SETUP([%expect too much])
394 exp: exp OP exp | NUM;
397 AT_CHECK([bison input.y -o input.c], 1, [],
398 [input.y contains 1 shift/reduce conflict.
399 expected 2 shift/reduce conflicts