]>
Commit | Line | Data |
---|---|---|
1 | # Bison Regressions. -*- Autotest -*- | |
2 | # Copyright 2001, 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 | ||
19 | AT_BANNER([[Regression tests.]]) | |
20 | ||
21 | ||
22 | ## ---------------- ## | |
23 | ## Braces parsing. ## | |
24 | ## ---------------- ## | |
25 | ||
26 | ||
27 | AT_SETUP([braces parsing]) | |
28 | ||
29 | AT_DATA([input.y], | |
30 | [[/* Bison used to swallow the character after `}'. */ | |
31 | ||
32 | %% | |
33 | exp: { tests = {{{{{{{{{{}}}}}}}}}}; }; | |
34 | %% | |
35 | ]]) | |
36 | ||
37 | AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore) | |
38 | ||
39 | AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore]) | |
40 | ||
41 | AT_CLEANUP | |
42 | ||
43 | ||
44 | ## ------------------ ## | |
45 | ## Duplicate string. ## | |
46 | ## ------------------ ## | |
47 | ||
48 | ||
49 | AT_SETUP([Duplicate string]) | |
50 | ||
51 | AT_DATA([input.y], | |
52 | [[/* `Bison -v' used to dump core when two tokens are defined with the same | |
53 | string, as LE and GE below. */ | |
54 | ||
55 | %token NUM | |
56 | %token LE "<=" | |
57 | %token GE "<=" | |
58 | ||
59 | %% | |
60 | exp: '(' exp ')' | NUM ; | |
61 | %% | |
62 | ]]) | |
63 | ||
64 | AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore) | |
65 | ||
66 | AT_CLEANUP | |
67 | ||
68 | ||
69 | ## ------------------- ## | |
70 | ## Rule Line Numbers. ## | |
71 | ## ------------------- ## | |
72 | ||
73 | AT_SETUP([Rule Line Numbers]) | |
74 | ||
75 | AT_DATA([input.y], | |
76 | [[%% | |
77 | expr: | |
78 | 'a' | |
79 | ||
80 | { | |
81 | ||
82 | } | |
83 | ||
84 | 'b' | |
85 | ||
86 | { | |
87 | ||
88 | } | |
89 | ||
90 | | | |
91 | ||
92 | ||
93 | { | |
94 | ||
95 | ||
96 | } | |
97 | ||
98 | 'c' | |
99 | ||
100 | { | |
101 | ||
102 | }; | |
103 | ]]) | |
104 | ||
105 | AT_CHECK([bison input.y -o input.c -v], 0, [], []) | |
106 | ||
107 | # Check the contents of the report. | |
108 | AT_CHECK([cat input.output], [], | |
109 | [[Grammar | |
110 | ||
111 | Number, Line, Rule | |
112 | 0 2 $axiom -> expr $ | |
113 | 1 2 @1 -> /* empty */ | |
114 | 2 2 expr -> 'a' @1 'b' | |
115 | 3 15 @2 -> /* empty */ | |
116 | 4 15 expr -> @2 'c' | |
117 | ||
118 | ||
119 | Terminals, with rules where they appear | |
120 | ||
121 | $ (0) 0 | |
122 | 'a' (97) 2 | |
123 | 'b' (98) 2 | |
124 | 'c' (99) 4 | |
125 | error (256) | |
126 | ||
127 | ||
128 | Nonterminals, with rules where they appear | |
129 | ||
130 | $axiom (6) | |
131 | on left: 0 | |
132 | expr (7) | |
133 | on left: 2 4, on right: 0 | |
134 | @1 (8) | |
135 | on left: 1, on right: 2 | |
136 | @2 (9) | |
137 | on left: 3, on right: 4 | |
138 | ||
139 | ||
140 | state 0 | |
141 | ||
142 | $axiom -> . expr $ (rule 0) | |
143 | ||
144 | 'a' shift, and go to state 1 | |
145 | ||
146 | $default reduce using rule 3 (@2) | |
147 | ||
148 | expr go to state 2 | |
149 | @2 go to state 3 | |
150 | ||
151 | ||
152 | ||
153 | state 1 | |
154 | ||
155 | expr -> 'a' . @1 'b' (rule 2) | |
156 | ||
157 | $default reduce using rule 1 (@1) | |
158 | ||
159 | @1 go to state 4 | |
160 | ||
161 | ||
162 | ||
163 | state 2 | |
164 | ||
165 | $axiom -> expr . $ (rule 0) | |
166 | ||
167 | $ shift, and go to state 5 | |
168 | ||
169 | ||
170 | ||
171 | state 3 | |
172 | ||
173 | expr -> @2 . 'c' (rule 4) | |
174 | ||
175 | 'c' shift, and go to state 6 | |
176 | ||
177 | ||
178 | ||
179 | state 4 | |
180 | ||
181 | expr -> 'a' @1 . 'b' (rule 2) | |
182 | ||
183 | 'b' shift, and go to state 7 | |
184 | ||
185 | ||
186 | ||
187 | state 5 | |
188 | ||
189 | $axiom -> expr $ . (rule 0) | |
190 | ||
191 | $default accept | |
192 | ||
193 | ||
194 | state 6 | |
195 | ||
196 | expr -> @2 'c' . (rule 4) | |
197 | ||
198 | $default reduce using rule 4 (expr) | |
199 | ||
200 | ||
201 | ||
202 | state 7 | |
203 | ||
204 | expr -> 'a' @1 'b' . (rule 2) | |
205 | ||
206 | $default reduce using rule 2 (expr) | |
207 | ||
208 | ||
209 | ||
210 | ]]) | |
211 | ||
212 | AT_CLEANUP | |
213 | ||
214 | ||
215 | ||
216 | ## ---------------------- ## | |
217 | ## Mixing %token styles. ## | |
218 | ## ---------------------- ## | |
219 | ||
220 | ||
221 | AT_SETUP([Mixing %token styles]) | |
222 | ||
223 | # Taken from the documentation. | |
224 | AT_DATA([input.y], | |
225 | [[%token <operator> OR "||" | |
226 | %token <operator> LE 134 "<=" | |
227 | %left OR "<=" | |
228 | %% | |
229 | exp: ; | |
230 | %% | |
231 | ]]) | |
232 | ||
233 | AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore) | |
234 | ||
235 | AT_CLEANUP | |
236 | ||
237 | ||
238 | ||
239 | ## ---------------- ## | |
240 | ## Invalid inputs. ## | |
241 | ## ---------------- ## | |
242 | ||
243 | ||
244 | AT_SETUP([Invalid inputs]) | |
245 | ||
246 | AT_DATA([input.y], | |
247 | [[%% | |
248 | ? | |
249 | default: 'a' } | |
250 | %{ | |
251 | %& | |
252 | %a | |
253 | %- | |
254 | ]]) | |
255 | ||
256 | AT_CHECK([bison input.y], [1], [], | |
257 | [[input.y:2: invalid input: `?' | |
258 | input.y:3: invalid input: `}' | |
259 | input.y:4: invalid input: `%{' | |
260 | input.y:5: invalid input: `%&' | |
261 | input.y:6: invalid input: `%a' | |
262 | input.y:7: invalid input: `%-' | |
263 | ]]) | |
264 | ||
265 | AT_CLEANUP | |
266 | ||
267 | ||
268 | ||
269 | ## -------------------- ## | |
270 | ## Invalid %directive. ## | |
271 | ## -------------------- ## | |
272 | ||
273 | ||
274 | AT_SETUP([Invalid %directive]) | |
275 | ||
276 | AT_DATA([input.y], | |
277 | [[%invalid | |
278 | ]]) | |
279 | ||
280 | AT_CHECK([bison input.y], [1], [], | |
281 | [[input.y:1: unrecognized: %invalid | |
282 | input.y:1: Skipping to next % | |
283 | input.y:2: fatal error: no input grammar | |
284 | ]]) | |
285 | ||
286 | AT_CLEANUP | |
287 | ||
288 | ||
289 | ||
290 | ## -------------- ## | |
291 | ## Web2c Report. ## | |
292 | ## -------------- ## | |
293 | ||
294 | # The generation of the reduction was once wrong in Bison, and made it | |
295 | # miss some reductions. In the following test case, the reduction on | |
296 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
297 | # the actual web2c.y. | |
298 | ||
299 | AT_SETUP([Web2c Report]) | |
300 | ||
301 | AT_DATA([input.y], | |
302 | [[%token undef_id_tok const_id_tok | |
303 | ||
304 | %start CONST_DEC_PART | |
305 | \f | |
306 | %% | |
307 | CONST_DEC_PART: | |
308 | CONST_DEC_LIST | |
309 | ; | |
310 | ||
311 | CONST_DEC_LIST: | |
312 | CONST_DEC | |
313 | | CONST_DEC_LIST CONST_DEC | |
314 | ; | |
315 | ||
316 | CONST_DEC: | |
317 | { } undef_id_tok '=' const_id_tok ';' | |
318 | ; | |
319 | %% | |
320 | ||
321 | ]]) | |
322 | ||
323 | AT_CHECK([bison -v input.y]) | |
324 | ||
325 | AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0, | |
326 | [[Grammar | |
327 | Number, Line, Rule | |
328 | 0 6 $axiom -> CONST_DEC_PART $ | |
329 | 1 6 CONST_DEC_PART -> CONST_DEC_LIST | |
330 | 2 10 CONST_DEC_LIST -> CONST_DEC | |
331 | 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC | |
332 | 4 15 @1 -> /* empty */ | |
333 | 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' | |
334 | Terminals, with rules where they appear | |
335 | $ (0) 0 | |
336 | ';' (59) 5 | |
337 | '=' (61) 5 | |
338 | error (256) | |
339 | undef_id_tok (258) 5 | |
340 | const_id_tok (259) 5 | |
341 | Nonterminals, with rules where they appear | |
342 | $axiom (7) | |
343 | on left: 0 | |
344 | CONST_DEC_PART (8) | |
345 | on left: 1, on right: 0 | |
346 | CONST_DEC_LIST (9) | |
347 | on left: 2 3, on right: 1 3 | |
348 | CONST_DEC (10) | |
349 | on left: 5, on right: 2 3 | |
350 | @1 (11) | |
351 | on left: 4, on right: 5 | |
352 | state 0 | |
353 | $axiom -> . CONST_DEC_PART $ (rule 0) | |
354 | $default reduce using rule 4 (@1) | |
355 | CONST_DEC_PART go to state 1 | |
356 | CONST_DEC_LIST go to state 2 | |
357 | CONST_DEC go to state 3 | |
358 | @1 go to state 4 | |
359 | state 1 | |
360 | $axiom -> CONST_DEC_PART . $ (rule 0) | |
361 | $ shift, and go to state 5 | |
362 | state 2 | |
363 | CONST_DEC_PART -> CONST_DEC_LIST . (rule 1) | |
364 | CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3) | |
365 | undef_id_tok reduce using rule 4 (@1) | |
366 | $default reduce using rule 1 (CONST_DEC_PART) | |
367 | CONST_DEC go to state 6 | |
368 | @1 go to state 4 | |
369 | state 3 | |
370 | CONST_DEC_LIST -> CONST_DEC . (rule 2) | |
371 | $default reduce using rule 2 (CONST_DEC_LIST) | |
372 | state 4 | |
373 | CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5) | |
374 | undef_id_tok shift, and go to state 7 | |
375 | state 5 | |
376 | $axiom -> CONST_DEC_PART $ . (rule 0) | |
377 | $default accept | |
378 | state 6 | |
379 | CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3) | |
380 | $default reduce using rule 3 (CONST_DEC_LIST) | |
381 | state 7 | |
382 | CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5) | |
383 | '=' shift, and go to state 8 | |
384 | state 8 | |
385 | CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5) | |
386 | const_id_tok shift, and go to state 9 | |
387 | state 9 | |
388 | CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5) | |
389 | ';' shift, and go to state 10 | |
390 | state 10 | |
391 | CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5) | |
392 | $default reduce using rule 5 (CONST_DEC) | |
393 | ]]) | |
394 | ||
395 | AT_CLEANUP | |
396 | ||
397 | ||
398 | ## --------------- ## | |
399 | ## Web2c Actions. ## | |
400 | ## --------------- ## | |
401 | ||
402 | # The generation of the mapping `state -> action' was once wrong in | |
403 | # extremely specific situations. web2c.y exhibits this situation. | |
404 | # Below is a stripped version of the grammar. It looks like one can | |
405 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
406 | # which disapears when applying sane grammar transformations. | |
407 | # | |
408 | # It used to be wrong on yydefact only: | |
409 | # | |
410 | # static const short yydefact[] = | |
411 | # { | |
412 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
413 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
414 | # 0, 0 | |
415 | # }; | |
416 | # | |
417 | # but let's check all the tables. | |
418 | ||
419 | ||
420 | AT_SETUP([Web2c Actions]) | |
421 | ||
422 | AT_DATA([input.y], | |
423 | [[%% | |
424 | statement: struct_stat; | |
425 | struct_stat: /* empty. */ | if else; | |
426 | if: "if" "const" "then" statement; | |
427 | else: "else" statement; | |
428 | %% | |
429 | ]]) | |
430 | ||
431 | AT_CHECK([bison -v input.y -o input.c]) | |
432 | ||
433 | # Check only the tables. We don't use --no-parser, because it is | |
434 | # still to be implemented in the experimental branch of Bison. | |
435 | AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0, | |
436 | [[static const yy_token_number_type yytranslate[] = | |
437 | { | |
438 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
439 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
440 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
441 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
442 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
443 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
444 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
445 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
446 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
447 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
448 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
449 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
450 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
451 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
452 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
453 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
454 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
455 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
456 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
457 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
458 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
459 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
460 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
461 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
462 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
463 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, | |
464 | 5, 6 | |
465 | }; | |
466 | static const short yyprhs[] = | |
467 | { | |
468 | 0, 0, 3, 5, 6, 9, 14 | |
469 | }; | |
470 | static const yyrhs_t yyrhs[] = | |
471 | { | |
472 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, | |
473 | 4, 5, 8, -1, 6, 8, -1 | |
474 | }; | |
475 | static const short yyrline[] = | |
476 | { | |
477 | 0, 2, 2, 3, 3, 4, 5 | |
478 | }; | |
479 | static const char *const yytname[] = | |
480 | { | |
481 | "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"", | |
482 | "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0 | |
483 | }; | |
484 | static const short yytoknum[] = | |
485 | { | |
486 | 0, 256, 257, 258, 259, 260, 261, -1 | |
487 | }; | |
488 | static const yy_token_number_type yyr1[] = | |
489 | { | |
490 | 0, 7, 8, 9, 9, 10, 11 | |
491 | }; | |
492 | static const short yyr2[] = | |
493 | { | |
494 | 0, 2, 1, 0, 2, 4, 2 | |
495 | }; | |
496 | static const short yydefact[] = | |
497 | { | |
498 | 3, 0, 0, 2, 0, 0, 0, 3, 4, 3, | |
499 | 6, 5 | |
500 | }; | |
501 | static const short yydefgoto[] = | |
502 | { | |
503 | -1, 2, 3, 4, 8 | |
504 | }; | |
505 | static const short yypact[] = | |
506 | { | |
507 | -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2, | |
508 | -32768,-32768 | |
509 | }; | |
510 | static const short yypgoto[] = | |
511 | { | |
512 | -32768, -7,-32768,-32768,-32768 | |
513 | }; | |
514 | static const short yytable[] = | |
515 | { | |
516 | 10, 1, 11, 5, 6, 0, 7, 9 | |
517 | }; | |
518 | static const short yycheck[] = | |
519 | { | |
520 | 7, 3, 9, 4, 0, -1, 6, 5 | |
521 | }; | |
522 | ]]) | |
523 | ||
524 | AT_CLEANUP |