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