1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001, 2002 Free Software Foundation, Inc.
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)
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.
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
19 AT_BANNER([[Regression tests.]])
22 ## ---------------- ##
24 ## ---------------- ##
27 AT_SETUP([braces parsing])
30 [[/* Bison used to swallow the character after `}'. */
33 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
37 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
39 AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
44 ## ------------------ ##
45 ## Duplicate string. ##
46 ## ------------------ ##
49 AT_SETUP([Duplicate string])
52 [[/* `Bison -v' used to dump core when two tokens are defined with the same
53 string, as LE and GE below. */
60 exp: '(' exp ')' | NUM ;
64 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
69 ## ------------------- ##
70 ## Rule Line Numbers. ##
71 ## ------------------- ##
73 AT_SETUP([Rule Line Numbers])
105 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
107 # Check the contents of the report.
108 AT_CHECK([cat input.output], [],
113 1 2 @1 -> /* empty */
114 2 2 expr -> 'a' @1 'b'
115 3 15 @2 -> /* empty */
119 Terminals, with rules where they appear
128 Nonterminals, with rules where they appear
133 on left: 2 4, on right: 0
135 on left: 1, on right: 2
137 on left: 3, on right: 4
142 'a' shift, and go to state 1
144 $default reduce using rule 3 (@2)
153 expr -> 'a' . @1 'b' (rule 2)
155 $default reduce using rule 1 (@1)
163 $axiom -> expr . $ (rule 0)
165 $ shift, and go to state 5
171 expr -> @2 . 'c' (rule 4)
173 'c' shift, and go to state 6
179 expr -> 'a' @1 . 'b' (rule 2)
181 'b' shift, and go to state 7
187 $axiom -> expr $ . (rule 0)
194 expr -> @2 'c' . (rule 4)
196 $default reduce using rule 4 (expr)
202 expr -> 'a' @1 'b' . (rule 2)
204 $default reduce using rule 2 (expr)
214 ## ---------------------- ##
215 ## Mixing %token styles. ##
216 ## ---------------------- ##
219 AT_SETUP([Mixing %token styles])
221 # Taken from the documentation.
223 [[%token <operator> OR "||"
224 %token <operator> LE 134 "<="
231 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
237 ## ---------------- ##
238 ## Invalid inputs. ##
239 ## ---------------- ##
242 AT_SETUP([Invalid inputs])
254 AT_CHECK([bison input.y], [1], [],
255 [[input.y:2: invalid input: `?'
256 input.y:3: invalid input: `}'
257 input.y:4: invalid input: `%{'
258 input.y:5: invalid input: `%&'
259 input.y:6: invalid input: `%a'
260 input.y:7: invalid input: `%-'
267 ## -------------------- ##
268 ## Invalid %directive. ##
269 ## -------------------- ##
272 AT_SETUP([Invalid %directive])
278 AT_CHECK([bison input.y], [1], [],
279 [[input.y:1: unrecognized: %invalid
280 input.y:1: Skipping to next %
281 input.y:2: fatal error: no input grammar
292 # The generation of the reduction was once wrong in Bison, and made it
293 # miss some reductions. In the following test case, the reduction on
294 # `undef_id_tok' in state 1 was missing. This is stripped down from
295 # the actual web2c.y.
297 AT_SETUP([Web2c Report])
300 [[%token undef_id_tok const_id_tok
302 %start CONST_DEC_PART
311 | CONST_DEC_LIST CONST_DEC
315 { } undef_id_tok '=' const_id_tok ';'
321 AT_CHECK([bison -v input.y])
323 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
326 0 6 $axiom -> CONST_DEC_PART $
327 1 6 CONST_DEC_PART -> CONST_DEC_LIST
328 2 10 CONST_DEC_LIST -> CONST_DEC
329 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
330 4 15 @1 -> /* empty */
331 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
332 Terminals, with rules where they appear
339 Nonterminals, with rules where they appear
343 on left: 1, on right: 0
345 on left: 2 3, on right: 1 3
347 on left: 5, on right: 2 3
349 on left: 4, on right: 5
351 $default reduce using rule 4 (@1)
352 CONST_DEC_PART go to state 1
353 CONST_DEC_LIST go to state 2
354 CONST_DEC go to state 3
357 $axiom -> CONST_DEC_PART . $ (rule 0)
358 $ shift, and go to state 5
360 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
361 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
362 undef_id_tok reduce using rule 4 (@1)
363 $default reduce using rule 1 (CONST_DEC_PART)
364 CONST_DEC go to state 6
367 CONST_DEC_LIST -> CONST_DEC . (rule 2)
368 $default reduce using rule 2 (CONST_DEC_LIST)
370 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
371 undef_id_tok shift, and go to state 7
373 $axiom -> CONST_DEC_PART $ . (rule 0)
376 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
377 $default reduce using rule 3 (CONST_DEC_LIST)
379 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
380 '=' shift, and go to state 8
382 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
383 const_id_tok shift, and go to state 9
385 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
386 ';' shift, and go to state 10
388 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
389 $default reduce using rule 5 (CONST_DEC)
395 ## --------------- ##
397 ## --------------- ##
399 # The generation of the mapping `state -> action' was once wrong in
400 # extremely specific situations. web2c.y exhibits this situation.
401 # Below is a stripped version of the grammar. It looks like one can
402 # simplify it further, but just don't: it is tuned to exhibit a bug,
403 # which disapears when applying sane grammar transformations.
405 # It used to be wrong on yydefact only:
407 # static const short yydefact[] =
409 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
410 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
414 # but let's check all the tables.
417 AT_SETUP([Web2c Actions])
421 statement: struct_stat;
422 struct_stat: /* empty. */ | if else;
423 if: "if" "const" "then" statement;
424 else: "else" statement;
428 AT_CHECK([bison -v input.y -o input.c])
430 # Check only the tables. We don't use --no-parser, because it is
431 # still to be implemented in the experimental branch of Bison.
432 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
433 [[static const char yytranslate[] =
435 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
436 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
437 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
438 2, 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, 1, 3, 4, 5,
463 static const short yyprhs[] =
467 static const short yyrhs[] =
469 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
470 4, 5, 8, -1, 6, 8, -1
472 static const short yyrline[] =
476 static const char *const yytname[] =
478 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
479 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
481 static const short yytoknum[] =
483 0, 256, 2, 257, 258, 259, 260, -1
485 static const short yyr1[] =
487 0, 7, 8, 9, 9, 10, 11
489 static const short yyr2[] =
493 static const short yydefact[] =
495 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
498 static const short yydefgoto[] =
502 static const short yypact[] =
504 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
507 static const short yypgoto[] =
509 -32768, -7,-32768,-32768,-32768
511 static const short yytable[] =
513 10, 1, 11, 5, 6, 0, 7, 9
515 static const short yycheck[] =
517 7, 3, 9, 4, 0, -1, 6, 5