]> git.saurik.com Git - bison.git/blame - tests/conflicts.at
* src/LR0.c (allocate_itemsets): Don't loop over ritem: loop over
[bison.git] / tests / conflicts.at
CommitLineData
3c31a486
AD
1# Exercising Bison on conflicts. -*- Autotest -*-
2# Copyright 2002 Free Software Foundation, Inc.
3
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)
7# any later version.
8
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.
13
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
17# 02111-1307, USA.
18
19AT_BANNER([[Conflicts.]])
20
21
22## ------------------- ##
23## %nonassoc and eof. ##
24## ------------------- ##
25
26AT_SETUP([%nonassoc and eof])
27
28AT_DATA([input.y],
29[[
30%{
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <error.h>
35#define YYERROR_VERBOSE 1
36#define yyerror(Msg) \
37do { \
38 fprintf (stderr, "%s\n", Msg); \
39 exit (1); \
40} while (0)
41
42/* The current argument. */
43static const char *input = NULL;
44
45static int
46yylex (void)
47{
48 /* No token stands for end of file. */
49 if (input && *input)
50 return *input++;
51 else
52 return 0;
53}
54
55%}
56
57%nonassoc '<' '>'
58
59%%
60expr: expr '<' expr
61 | expr '>' expr
62 | '0'
63 ;
64%%
65int
66main (int argc, const char *argv[])
67{
68 if (argc > 1)
69 input = argv[1];
70 return yyparse ();
71}
72]])
73
74# Specify the output files to avoid problems on different file systems.
75AT_CHECK([bison input.y -o input.c])
76AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
77
78AT_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.
82AT_CHECK([./input '0<0<0'], [1], [],
83 [parse error, unexpected '<', expecting '<' or '>'
84])
85
86AT_CHECK([./input '0>0'])
87AT_CHECK([./input '0>0>0'], [1], [],
88 [parse error, unexpected '>', expecting '<' or '>'
89])
90
91AT_CHECK([./input '0<0>0'], [1], [],
92 [parse error, unexpected '>', expecting '<' or '>'
93])
94
95AT_CLEANUP
96
97
98
99## ------------------------- ##
100## Unresolved SR Conflicts. ##
101## ------------------------- ##
102
103AT_SETUP([Unresolved SR Conflicts])
104
105AT_DATA([input.y],
106[[%token NUM OP
107%%
108exp: exp OP exp | NUM;
109]])
110
111AT_CHECK([bison input.y -o input.c -v], 0, [],
112[input.y contains 1 shift/reduce conflict.
113])
114
115# Check the contents of the report.
116AT_CHECK([cat input.output], [],
117[[State 5 contains 1 shift/reduce conflict.
118
119
120Grammar
121
122 Number, Line, Rule
123 0 3 $axiom -> exp $
124 1 3 exp -> exp OP exp
125 2 3 exp -> NUM
126
127
128Terminals, with rules where they appear
129
130$ (0) 0
131error (256)
132NUM (257) 2
133OP (258) 1
134
135
136Nonterminals, with rules where they appear
137
138$axiom (5)
139 on left: 0
140exp (6)
141 on left: 1 2, on right: 0 1
142
143
144state 0
145
146 NUM shift, and go to state 1
147
148 exp go to state 2
149
150
151
152state 1
153
154 exp -> NUM . (rule 2)
155
156 $default reduce using rule 2 (exp)
157
158
159
160state 2
161
162 $axiom -> exp . $ (rule 0)
163 exp -> exp . OP exp (rule 1)
164
165 $ shift, and go to state 3
166 OP shift, and go to state 4
167
168
169
170state 3
171
172 $axiom -> exp $ . (rule 0)
173
174 $default accept
175
176
177state 4
178
179 exp -> exp OP . exp (rule 1)
180
181 NUM shift, and go to state 1
182
183 exp go to state 5
184
185
186
187state 5
188
189 exp -> exp . OP exp (rule 1)
190 exp -> exp OP exp . (rule 1)
191
192 OP shift, and go to state 4
193
194 OP [reduce using rule 1 (exp)]
195 $default reduce using rule 1 (exp)
196
197
198
199]])
200
201AT_CLEANUP
202
203
204## --------------------- ##
205## Solved SR Conflicts. ##
206## --------------------- ##
207
208AT_SETUP([Solved SR Conflicts])
209
210AT_DATA([input.y],
211[[%token NUM OP
212%right OP
213%%
214exp: exp OP exp | NUM;
215]])
216
217AT_CHECK([bison input.y -o input.c -v], 0, [], [])
218
219# Check the contents of the report.
220AT_CHECK([cat input.output], [],
221[[Conflict in state 5 between rule 2 and token OP resolved as shift.
222
223
224Grammar
225
226 Number, Line, Rule
227 0 4 $axiom -> exp $
228 1 4 exp -> exp OP exp
229 2 4 exp -> NUM
230
231
232Terminals, with rules where they appear
233
234$ (0) 0
235error (256)
236NUM (257) 2
237OP (258) 1
238
239
240Nonterminals, with rules where they appear
241
242$axiom (5)
243 on left: 0
244exp (6)
245 on left: 1 2, on right: 0 1
246
247
248state 0
249
250 NUM shift, and go to state 1
251
252 exp go to state 2
253
254
255
256state 1
257
258 exp -> NUM . (rule 2)
259
260 $default reduce using rule 2 (exp)
261
262
263
264state 2
265
266 $axiom -> exp . $ (rule 0)
267 exp -> exp . OP exp (rule 1)
268
269 $ shift, and go to state 3
270 OP shift, and go to state 4
271
272
273
274state 3
275
276 $axiom -> exp $ . (rule 0)
277
278 $default accept
279
280
281state 4
282
283 exp -> exp OP . exp (rule 1)
284
285 NUM shift, and go to state 1
286
287 exp go to state 5
288
289
290
291state 5
292
293 exp -> exp . OP exp (rule 1)
294 exp -> exp OP exp . (rule 1)
295
296 OP shift, and go to state 4
297
298 $default reduce using rule 1 (exp)
299
300
301
302]])
303
304AT_CLEANUP
305
306
307
308
309## -------------------- ##
310## %expect not enough. ##
311## -------------------- ##
312
313AT_SETUP([%expect not enough])
314
315AT_DATA([input.y],
316[[%token NUM OP
317%expect 0
318%%
319exp: exp OP exp | NUM;
320]])
321
322AT_CHECK([bison input.y -o input.c], 1, [],
323[input.y contains 1 shift/reduce conflict.
324expected 0 shift/reduce conflicts
325])
326AT_CLEANUP
327
328
329## --------------- ##
330## %expect right. ##
331## --------------- ##
332
333AT_SETUP([%expect right])
334
335AT_DATA([input.y],
336[[%token NUM OP
337%expect 1
338%%
339exp: exp OP exp | NUM;
340]])
341
342AT_CHECK([bison input.y -o input.c], 0)
343AT_CLEANUP
344
345
346## ------------------ ##
347## %expect too much. ##
348## ------------------ ##
349
350AT_SETUP([%expect too much])
351
352AT_DATA([input.y],
353[[%token NUM OP
354%expect 2
355%%
356exp: exp OP exp | NUM;
357]])
358
359AT_CHECK([bison input.y -o input.c], 1, [],
360[input.y contains 1 shift/reduce conflict.
361expected 2 shift/reduce conflicts
362])
363AT_CLEANUP