]> git.saurik.com Git - bison.git/blob - tests/regression.at
* src/reader.c (read_declarations): Don't abort on tok_illegal,
[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
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 Number, Line, Rule
69 1 3 exp -> exp OP exp
70 2 3 exp -> NUM
71
72 Terminals, with rules where they appear
73
74 $ (-1)
75 error (256)
76 NUM (257) 2
77 OP (258) 1
78
79 Nonterminals, with rules where they appear
80
81 exp (5)
82 on left: 1 2, on right: 1
83
84
85 state 0
86
87 NUM shift, and go to state 1
88
89 exp go to state 2
90
91
92
93 state 1
94
95 exp -> NUM . (rule 2)
96
97 $default reduce using rule 2 (exp)
98
99
100
101 state 2
102
103 exp -> exp . OP exp (rule 1)
104
105 $ go to state 5
106 OP shift, and go to state 3
107
108
109
110 state 3
111
112 exp -> exp OP . exp (rule 1)
113
114 NUM shift, and go to state 1
115
116 exp go to state 4
117
118
119
120 state 4
121
122 exp -> exp . OP exp (rule 1)
123 exp -> exp OP exp . (rule 1)
124
125 OP shift, and go to state 3
126
127 OP [reduce using rule 1 (exp)]
128 $default reduce using rule 1 (exp)
129
130
131
132 state 5
133
134 $ go to state 6
135
136
137
138 state 6
139
140 $default accept
141 ]])
142
143 AT_CLEANUP
144
145
146 ## --------------------- ##
147 ## Solved SR Conflicts. ##
148 ## --------------------- ##
149
150 AT_SETUP([Solved SR Conflicts])
151
152 AT_DATA([input.y],
153 [[%token NUM OP
154 %right OP
155 %%
156 exp: exp OP exp | NUM;
157 ]])
158
159 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
160
161 # Check the contents of the report.
162 AT_CHECK([cat input.output], [],
163 [[Conflict in state 4 between rule 1 and token OP resolved as shift.
164
165 Grammar
166
167 Number, Line, Rule
168 1 4 exp -> exp OP exp
169 2 4 exp -> NUM
170
171 Terminals, with rules where they appear
172
173 $ (-1)
174 error (256)
175 NUM (257) 2
176 OP (258) 1
177
178 Nonterminals, with rules where they appear
179
180 exp (5)
181 on left: 1 2, on right: 1
182
183
184 state 0
185
186 NUM shift, and go to state 1
187
188 exp go to state 2
189
190
191
192 state 1
193
194 exp -> NUM . (rule 2)
195
196 $default reduce using rule 2 (exp)
197
198
199
200 state 2
201
202 exp -> exp . OP exp (rule 1)
203
204 $ go to state 5
205 OP shift, and go to state 3
206
207
208
209 state 3
210
211 exp -> exp OP . exp (rule 1)
212
213 NUM shift, and go to state 1
214
215 exp go to state 4
216
217
218
219 state 4
220
221 exp -> exp . OP exp (rule 1)
222 exp -> exp OP exp . (rule 1)
223
224 OP shift, and go to state 3
225
226 $default reduce using rule 1 (exp)
227
228
229
230 state 5
231
232 $ go to state 6
233
234
235
236 state 6
237
238 $default accept
239 ]])
240
241 AT_CLEANUP
242
243
244
245 ## -------------------- ##
246 ## %expect not enough. ##
247 ## -------------------- ##
248
249 AT_SETUP([%expect not enough])
250
251 AT_DATA([input.y],
252 [[%token NUM OP
253 %expect 0
254 %%
255 exp: exp OP exp | NUM;
256 ]])
257
258 AT_CHECK([bison input.y -o input.c], 1, [],
259 [input.y contains 1 shift/reduce conflict.
260 expected 0 shift/reduce conflicts
261 ])
262 AT_CLEANUP
263
264
265 ## --------------- ##
266 ## %expect right. ##
267 ## --------------- ##
268
269 AT_SETUP([%expect right])
270
271 AT_DATA([input.y],
272 [[%token NUM OP
273 %expect 1
274 %%
275 exp: exp OP exp | NUM;
276 ]])
277
278 AT_CHECK([bison input.y -o input.c], 0)
279 AT_CLEANUP
280
281
282 ## ------------------ ##
283 ## %expect too much. ##
284 ## ------------------ ##
285
286 AT_SETUP([%expect too much])
287
288 AT_DATA([input.y],
289 [[%token NUM OP
290 %expect 2
291 %%
292 exp: exp OP exp | NUM;
293 ]])
294
295 AT_CHECK([bison input.y -o input.c], 1, [],
296 [input.y contains 1 shift/reduce conflict.
297 expected 2 shift/reduce conflicts
298 ])
299 AT_CLEANUP
300
301
302 ## ---------------------- ##
303 ## Mixing %token styles. ##
304 ## ---------------------- ##
305
306
307 AT_SETUP([Mixing %token styles])
308
309 # Taken from the documentation.
310 AT_DATA([input.y],
311 [[%token <operator> OR "||"
312 %token <operator> LE 134 "<="
313 %left OR "<="
314 %%
315 exp: ;
316 %%
317 ]])
318
319 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
320
321 AT_CLEANUP
322
323
324
325 ## ---------------------- ##
326 ## %union and --defines. ##
327 ## ---------------------- ##
328
329
330 AT_SETUP([%union and --defines])
331
332 AT_DATA([union.y],
333 [%union
334 {
335 int integer;
336 char *string ;
337 }
338 %%
339 exp: {};
340 ])
341
342 AT_CHECK([bison --defines union.y])
343
344 AT_CLEANUP
345
346
347 ## --------------------------------------- ##
348 ## Duplicate '/' in C comments in %union ##
349 ## --------------------------------------- ##
350
351
352 AT_SETUP([%union and C comments])
353
354 AT_DATA([union-comment.y],
355 [%union
356 {
357 /* The int. */ int integer;
358 /* The string. */ char *string ;
359 }
360 %%
361 exp: {};
362 ])
363
364 AT_CHECK([bison union-comment.y])
365 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
366
367 AT_CLEANUP
368
369
370 ## ----------------- ##
371 ## Invalid input 1. ##
372 ## ----------------- ##
373
374
375 AT_SETUP([Invalid input: 1])
376
377 AT_DATA([input.y],
378 [[%%
379 ?
380 ]])
381
382 AT_CHECK([bison input.y], [1], [],
383 [[input.y:2: invalid input: `?'
384 input.y:3: fatal error: no rules in the input grammar
385 ]])
386
387 AT_CLEANUP
388
389
390 ## ----------------- ##
391 ## Invalid input 2. ##
392 ## ----------------- ##
393
394
395 AT_SETUP([Invalid input: 2])
396
397 AT_DATA([input.y],
398 [[%%
399 default: 'a' }
400 ]])
401
402 AT_CHECK([bison input.y], [1], [],
403 [[input.y:2: invalid input: `}'
404 ]])
405
406 AT_CLEANUP
407
408
409
410 ## -------------------- ##
411 ## Invalid %directive. ##
412 ## -------------------- ##
413
414
415 AT_SETUP([Invalid %directive])
416
417 AT_DATA([input.y],
418 [[%invalid
419 ]])
420
421 AT_CHECK([bison input.y], [1], [],
422 [[input.y:1: unrecognized: %invalid
423 input.y:1: Skipping to next %
424 input.y:2: fatal error: no input grammar
425 ]])
426
427 AT_CLEANUP
428
429
430
431 ## --------------------- ##
432 ## Invalid CPP headers. ##
433 ## --------------------- ##
434
435 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
436 # -------------------------------------
437 m4_define([AT_TEST_CPP_GUARD_H],
438 [AT_SETUP([Invalid CPP guards: $1])
439
440 # Possibly create inner directories.
441 dirname=`AS_DIRNAME([$1])`
442 AS_MKDIR_P([$dirname])
443
444 AT_DATA([$1.y],
445 [%%
446 dummy:
447 ])
448
449 AT_CHECK([bison --defines=$1.h $1.y])
450
451 # CPP should be happy with it.
452 AT_CHECK([$CC -E $1.h], 0, [ignore])
453
454 AT_CLEANUP
455 ])
456
457 AT_TEST_CPP_GUARD_H([input/input])
458 AT_TEST_CPP_GUARD_H([9foo])