]> git.saurik.com Git - bison.git/blob - tests/regression.at
* tests/regression.at (Conflicts): Rename as...
[bison.git] / tests / regression.at
1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001 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
19 AT_BANNER([[Regression tests.]])
20
21 ## ------------------ ##
22 ## Duplicate string. ##
23 ## ------------------ ##
24
25
26 AT_SETUP([Duplicate string])
27
28 AT_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 %%
37 exp: '(' exp ')' | NUM ;
38 %%
39 ]])
40
41 AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
42
43 AT_CLEANUP([duplicate.*])
44
45
46 ## ------------------------- ##
47 ## Unresolved SR Conflicts. ##
48 ## ------------------------- ##
49
50 AT_SETUP([Unresolved SR Conflicts])
51
52 AT_DATA([input.y],
53 [[%token NUM OP
54 %%
55 exp: exp OP exp | NUM;
56 ]])
57
58 AT_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.
63 AT_CHECK([cat input.output], [],
64 [[State 4 contains 1 shift/reduce conflict.
65
66 Grammar
67
68 rule 1 exp -> exp OP exp
69 rule 2 exp -> NUM
70
71 Terminals, with rules where they appear
72
73 $ (-1)
74 error (256)
75 NUM (257) 2
76 OP (258) 1
77
78 Nonterminals, with rules where they appear
79
80 exp (5)
81 on left: 1 2, on right: 1
82
83
84 state 0
85
86 NUM shift, and go to state 1
87
88 exp go to state 2
89
90
91
92 state 1
93
94 exp -> NUM . (rule 2)
95
96 $default reduce using rule 2 (exp)
97
98
99
100 state 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
109 state 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
119 state 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
126 OP [reduce using rule 1 (exp)]
127 $default reduce using rule 1 (exp)
128
129
130
131 state 5
132
133 $ go to state 6
134
135
136
137 state 6
138
139 $default accept
140 ]])
141
142 AT_CLEANUP(input.c input.output)
143
144
145 ## --------------------- ##
146 ## Solved SR Conflicts. ##
147 ## --------------------- ##
148
149 AT_SETUP([Solved SR Conflicts])
150
151 AT_DATA([input.y],
152 [[%token NUM OP
153 %right OP
154 %%
155 exp: exp OP exp | NUM;
156 ]])
157
158 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
159
160 # Check the contents of the report.
161 AT_CHECK([cat input.output], [],
162 [[Conflict in state 4 between rule 1 and token OP resolved as shift.
163
164 Grammar
165
166 rule 1 exp -> exp OP exp
167 rule 2 exp -> NUM
168
169 Terminals, with rules where they appear
170
171 $ (-1)
172 error (256)
173 NUM (257) 2
174 OP (258) 1
175
176 Nonterminals, with rules where they appear
177
178 exp (5)
179 on left: 1 2, on right: 1
180
181
182 state 0
183
184 NUM shift, and go to state 1
185
186 exp go to state 2
187
188
189
190 state 1
191
192 exp -> NUM . (rule 2)
193
194 $default reduce using rule 2 (exp)
195
196
197
198 state 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
207 state 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
217 state 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
228 state 5
229
230 $ go to state 6
231
232
233
234 state 6
235
236 $default accept
237 ]])
238
239 AT_CLEANUP(input.c input.output)
240
241
242 ## ---------------------- ##
243 ## Mixing %token styles. ##
244 ## ---------------------- ##
245
246
247 AT_SETUP([Mixing %token styles])
248
249 # Taken from the documentation.
250 AT_DATA([input.y],
251 [[%token <operator> OR "||"
252 %token <operator> LE 134 "<="
253 %left OR "<="
254 %%
255 exp: ;
256 %%
257 ]])
258
259 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
260
261 AT_CLEANUP([input.*])
262
263
264
265 ## ---------------------- ##
266 ## %union and --defines. ##
267 ## ---------------------- ##
268
269
270 AT_SETUP([%union and --defines])
271
272 AT_DATA([union.y],
273 [%union
274 {
275 int integer;
276 char *string ;
277 }
278 %%
279 exp: {};
280 ])
281
282 AT_CHECK([bison --defines union.y])
283
284 AT_CLEANUP([union.*])
285
286
287 ## --------------------------------------- ##
288 ## Duplicate '/' in C comments in %union ##
289 ## --------------------------------------- ##
290
291
292 AT_SETUP([%union and C comments])
293
294 AT_DATA([union-comment.y],
295 [%union
296 {
297 /* The int. */ int integer;
298 /* The string. */ char *string ;
299 }
300 %%
301 exp: {};
302 ])
303
304 AT_CHECK([bison union-comment.y])
305 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
306
307 AT_CLEANUP([union-comment.*])
308
309
310 ## ----------------- ##
311 ## Invalid input 1. ##
312 ## ----------------- ##
313
314
315 AT_SETUP([Invalid input: 1])
316
317 AT_DATA([input.y],
318 [[%%
319 ?
320 ]])
321
322 AT_CHECK([bison input.y], [1], [],
323 [input.y:2: invalid input: `?'
324 input.y:3: fatal error: no rules in the input grammar
325 ])
326
327 AT_CLEANUP
328
329
330 ## ----------------- ##
331 ## Invalid input 2. ##
332 ## ----------------- ##
333
334
335 AT_SETUP([Invalid input: 2])
336
337 AT_DATA([input.y],
338 [[%%
339 default: 'a' }
340 ]])
341
342 AT_CHECK([bison input.y], [1], [],
343 [input.y:2: invalid input: `}'
344 ])
345
346 AT_CLEANUP
347
348
349
350 ## --------------------- ##
351 ## Invalid CPP headers. ##
352 ## --------------------- ##
353
354 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
355 # -------------------------------------
356 m4_define([AT_TEST_CPP_GUARD_H],
357 [AT_SETUP([Invalid CPP guards: $1])
358
359 # possibly create and nuke inner directories.
360 m4_bmatch([$1], [[/]],
361 [dirname=`AS_DIRNAME([$1])`
362 AS_MKDIR_P([$dirname])
363 AT_CLEANUP_FILES([$dirname])])
364
365 AT_DATA([$1.y],
366 [%%
367 dummy:
368 ])
369
370 AT_CHECK([bison --defines=$1.h $1.y])
371
372 # CPP should be happy with it.
373 AT_CHECK([$CC -E $1.h], 0, [ignore])
374
375 AT_CLEANUP($1.*)
376 ])
377
378 AT_TEST_CPP_GUARD_H([input/input])
379 AT_TEST_CPP_GUARD_H([9foo])