]> git.saurik.com Git - bison.git/blame - tests/regression.at
* src/bison.simple (yyparse): Let yyls1, yyss1 and yyvs1 be
[bison.git] / tests / regression.at
CommitLineData
342b8b6e
AD
1# Bison Regressions. -*- Autotest -*-
2# Copyright 2001 Free Software Foundation, Inc.
c95f2d78 3
342b8b6e
AD
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.
c95f2d78 8
342b8b6e
AD
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.
c95f2d78 13
342b8b6e
AD
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.
c95f2d78 18
342b8b6e 19AT_BANNER([[Regression tests.]])
c95f2d78
AD
20
21## ------------------ ##
22## Duplicate string. ##
23## ------------------ ##
24
25
26AT_SETUP([Duplicate string])
27
28AT_DATA([duplicate.y],
29[[/* `Bison -v' used to dump core when two tokens are defined with the same
30 string, as LE and GE below. */
31
32%token NUM
33%token LE "<="
34%token GE "<="
35
36%%
37exp: '(' exp ')' | NUM ;
38%%
39]])
40
41AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
42
43AT_CLEANUP([duplicate.*])
44
45
ba9dda1a
AD
46## ------------------------- ##
47## Unresolved SR Conflicts. ##
48## ------------------------- ##
0df87bb6 49
ba9dda1a 50AT_SETUP([Unresolved SR Conflicts])
0df87bb6
AD
51
52AT_DATA([input.y],
53[[%token NUM OP
54%%
55exp: exp OP exp | NUM;
56]])
57
58AT_CHECK([bison input.y -o input.c -v], 0, [],
59[input.y contains 1 shift/reduce conflict.
60])
61
62# Check the contents of the report.
63AT_CHECK([cat input.output], [],
64[[State 4 contains 1 shift/reduce conflict.
65
66Grammar
67
68rule 1 exp -> exp OP exp
69rule 2 exp -> NUM
70
71Terminals, with rules where they appear
72
73$ (-1)
74error (256)
75NUM (257) 2
76OP (258) 1
77
78Nonterminals, with rules where they appear
79
80exp (5)
81 on left: 1 2, on right: 1
82
83
84state 0
85
86 NUM shift, and go to state 1
87
88 exp go to state 2
89
90
91
92state 1
93
94 exp -> NUM . (rule 2)
95
96 $default reduce using rule 2 (exp)
97
98
99
100state 2
101
102 exp -> exp . OP exp (rule 1)
103
104 $ go to state 5
105 OP shift, and go to state 3
106
107
108
109state 3
110
111 exp -> exp OP . exp (rule 1)
112
113 NUM shift, and go to state 1
114
115 exp go to state 4
116
117
118
119state 4
120
121 exp -> exp . OP exp (rule 1)
122 exp -> exp OP exp . (rule 1)
123
124 OP shift, and go to state 3
125
c73a41af
AD
126 OP [reduce using rule 1 (exp)]
127 $default reduce using rule 1 (exp)
128
0df87bb6
AD
129
130
131state 5
132
133 $ go to state 6
134
135
136
ba9dda1a
AD
137state 6
138
139 $default accept
140]])
141
142AT_CLEANUP(input.c input.output)
143
144
145## --------------------- ##
146## Solved SR Conflicts. ##
147## --------------------- ##
148
149AT_SETUP([Solved SR Conflicts])
150
151AT_DATA([input.y],
152[[%token NUM OP
153%right OP
154%%
155exp: exp OP exp | NUM;
156]])
157
158AT_CHECK([bison input.y -o input.c -v], 0, [], [])
159
160# Check the contents of the report.
161AT_CHECK([cat input.output], [],
162[[Conflict in state 4 between rule 1 and token OP resolved as shift.
163
164Grammar
165
166rule 1 exp -> exp OP exp
167rule 2 exp -> NUM
168
169Terminals, with rules where they appear
170
171$ (-1)
172error (256)
173NUM (257) 2
174OP (258) 1
175
176Nonterminals, with rules where they appear
177
178exp (5)
179 on left: 1 2, on right: 1
180
181
182state 0
183
184 NUM shift, and go to state 1
185
186 exp go to state 2
187
188
189
190state 1
191
192 exp -> NUM . (rule 2)
193
194 $default reduce using rule 2 (exp)
195
196
197
198state 2
199
200 exp -> exp . OP exp (rule 1)
201
202 $ go to state 5
203 OP shift, and go to state 3
204
205
206
207state 3
208
209 exp -> exp OP . exp (rule 1)
210
211 NUM shift, and go to state 1
212
213 exp go to state 4
214
215
216
217state 4
218
219 exp -> exp . OP exp (rule 1)
220 exp -> exp OP exp . (rule 1)
221
222 OP shift, and go to state 3
223
224 $default reduce using rule 1 (exp)
225
226
227
228state 5
229
230 $ go to state 6
231
232
233
0df87bb6
AD
234state 6
235
236 $default accept
237]])
238
239AT_CLEANUP(input.c input.output)
240
c95f2d78 241
7da99ede
AD
242
243## -------------------- ##
244## %expect not enough. ##
245## -------------------- ##
246
247AT_SETUP([%expect not enough])
248
249AT_DATA([input.y],
250[[%token NUM OP
251%expect 0
252%%
253exp: exp OP exp | NUM;
254]])
255
256AT_CHECK([bison input.y -o input.c], 1, [],
257[input.y contains 1 shift/reduce conflict.
258expected 0 shift/reduce conflicts
259])
260AT_CLEANUP(input.c)
261
262
263## --------------- ##
264## %expect right. ##
265## --------------- ##
266
267AT_SETUP([%expect right])
268
269AT_DATA([input.y],
270[[%token NUM OP
271%expect 1
272%%
273exp: exp OP exp | NUM;
274]])
275
276AT_CHECK([bison input.y -o input.c], 0, [],
277[input.y contains 1 shift/reduce conflict.
278])
279AT_CLEANUP(input.c)
280
281
282## ------------------ ##
283## %expect too much. ##
284## ------------------ ##
285
286AT_SETUP([%expect too much])
287
288AT_DATA([input.y],
289[[%token NUM OP
290%expect 2
291%%
292exp: exp OP exp | NUM;
293]])
294
295AT_CHECK([bison input.y -o input.c], 1, [],
296[input.y contains 1 shift/reduce conflict.
297expected 2 shift/reduce conflicts
298])
299AT_CLEANUP(input.c)
300
301
cd5aafcf
AD
302## ---------------------- ##
303## Mixing %token styles. ##
304## ---------------------- ##
305
306
307AT_SETUP([Mixing %token styles])
308
309# Taken from the documentation.
310AT_DATA([input.y],
311[[%token <operator> OR "||"
312%token <operator> LE 134 "<="
313%left OR "<="
314%%
315exp: ;
316%%
317]])
318
319AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
320
321AT_CLEANUP([input.*])
322
323
324
c95f2d78
AD
325## ---------------------- ##
326## %union and --defines. ##
327## ---------------------- ##
328
329
330AT_SETUP([%union and --defines])
331
332AT_DATA([union.y],
333[%union
334{
335 int integer;
336 char *string ;
337}
338%%
339exp: {};
340])
341
342AT_CHECK([bison --defines union.y])
343
344AT_CLEANUP([union.*])
342b8b6e
AD
345
346
347## --------------------------------------- ##
348## Duplicate '/' in C comments in %union ##
349## --------------------------------------- ##
350
351
352AT_SETUP([%union and C comments])
353
354AT_DATA([union-comment.y],
355[%union
356{
357 /* The int. */ int integer;
358 /* The string. */ char *string ;
359}
360%%
361exp: {};
362])
363
364AT_CHECK([bison union-comment.y])
365AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
366
367AT_CLEANUP([union-comment.*])
368
369
561f9a30
AD
370## ----------------- ##
371## Invalid input 1. ##
372## ----------------- ##
373
374
375AT_SETUP([Invalid input: 1])
376
377AT_DATA([input.y],
378[[%%
379?
380]])
381
382AT_CHECK([bison input.y], [1], [],
383[input.y:2: invalid input: `?'
384input.y:3: fatal error: no rules in the input grammar
385])
386
387AT_CLEANUP
388
389
390## ----------------- ##
391## Invalid input 2. ##
392## ----------------- ##
393
394
395AT_SETUP([Invalid input: 2])
396
397AT_DATA([input.y],
398[[%%
399default: 'a' }
400]])
401
402AT_CHECK([bison input.y], [1], [],
403[input.y:2: invalid input: `}'
404])
405
406AT_CLEANUP
407
408
270a173c 409
342b8b6e
AD
410## --------------------- ##
411## Invalid CPP headers. ##
412## --------------------- ##
413
270a173c
AD
414# AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
415# -------------------------------------
416m4_define([AT_TEST_CPP_GUARD_H],
417[AT_SETUP([Invalid CPP guards: $1])
342b8b6e 418
270a173c
AD
419# possibly create and nuke inner directories.
420m4_bmatch([$1], [[/]],
421[dirname=`AS_DIRNAME([$1])`
422AS_MKDIR_P([$dirname])
423AT_CLEANUP_FILES([$dirname])])
342b8b6e 424
270a173c 425AT_DATA([$1.y],
342b8b6e
AD
426[%%
427dummy:
428])
429
270a173c 430AT_CHECK([bison --defines=$1.h $1.y])
342b8b6e 431
270a173c
AD
432# CPP should be happy with it.
433AT_CHECK([$CC -E $1.h], 0, [ignore])
434
e4d910bf 435AT_CLEANUP($1.*)
270a173c 436])
342b8b6e 437
270a173c
AD
438AT_TEST_CPP_GUARD_H([input/input])
439AT_TEST_CPP_GUARD_H([9foo])