1 # Bison Regressions. -*- Autotest -*-
2 # Copyright (C) 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 ## ------------------------- ##
23 ## Early token definitions. ##
24 ## ------------------------- ##
27 AT_SETUP([Early token definitions])
29 # Found in GCJ: they expect the tokens to be defined before the user
30 # prologue, so that they can use the token definitions in it.
34 void yyerror (const char *s);
44 # error "MY_TOKEN not defined."
53 AT_CHECK([bison input.y -o input.c])
54 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
60 ## ---------------- ##
62 ## ---------------- ##
65 AT_SETUP([Braces parsing])
68 [[/* Bison used to swallow the character after `}'. */
71 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
75 AT_CHECK([bison -v input.y -o input.c])
77 AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
82 ## ------------------ ##
83 ## Duplicate string. ##
84 ## ------------------ ##
87 AT_SETUP([Duplicate string])
90 [[/* `Bison -v' used to dump core when two tokens are defined with the same
91 string, as LE and GE below. */
98 exp: '(' exp ')' | NUM ;
102 AT_CHECK([bison -v input.y -o input.c], 0, [],
103 [[input.y:6: warning: symbol `"<="' used more than once as a literal string
109 ## ------------------- ##
110 ## Rule Line Numbers. ##
111 ## ------------------- ##
113 AT_SETUP([Rule Line Numbers])
145 AT_CHECK([bison input.y -o input.c -v])
147 # Check the contents of the report.
148 AT_CHECK([cat input.output], [],
153 1 2 @1 -> /* empty */
154 2 2 expr -> 'a' @1 'b'
155 3 15 @2 -> /* empty */
159 Terminals, with rules where they appear
168 Nonterminals, with rules where they appear
173 on left: 2 4, on right: 0
175 on left: 1, on right: 2
177 on left: 3, on right: 4
182 $axiom -> . expr $ (rule 0)
184 'a' shift, and go to state 1
186 $default reduce using rule 3 (@2)
195 expr -> 'a' . @1 'b' (rule 2)
197 $default reduce using rule 1 (@1)
205 $axiom -> expr . $ (rule 0)
207 $ shift, and go to state 5
213 expr -> @2 . 'c' (rule 4)
215 'c' shift, and go to state 6
221 expr -> 'a' @1 . 'b' (rule 2)
223 'b' shift, and go to state 7
229 $axiom -> expr $ . (rule 0)
236 expr -> @2 'c' . (rule 4)
238 $default reduce using rule 4 (expr)
244 expr -> 'a' @1 'b' . (rule 2)
246 $default reduce using rule 2 (expr)
256 ## ---------------------- ##
257 ## Mixing %token styles. ##
258 ## ---------------------- ##
261 AT_SETUP([Mixing %token styles])
263 # Taken from the documentation.
265 [[%token <operator> OR "||"
266 %token <operator> LE 134 "<="
273 AT_CHECK([bison -v input.y -o input.c])
279 ## ---------------- ##
280 ## Invalid inputs. ##
281 ## ---------------- ##
284 AT_SETUP([Invalid inputs])
296 AT_CHECK([bison input.y], [1], [],
297 [[input.y:2: invalid input: `?'
298 input.y:3: invalid input: `}'
299 input.y:4: invalid input: `%{'
300 input.y:5: invalid input: `%&'
301 input.y:6: invalid input: `%a'
302 input.y:7: invalid input: `%-'
309 ## -------------------- ##
310 ## Invalid %directive. ##
311 ## -------------------- ##
314 AT_SETUP([Invalid %directive])
320 AT_CHECK([bison input.y], [1], [],
321 [[input.y:1: unrecognized: %invalid
322 input.y:1: Skipping to next %
323 input.y:2: fatal error: no input grammar
330 ## ------------------- ##
331 ## Token definitions. ##
332 ## ------------------- ##
335 AT_SETUP([Token definitions])
337 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
340 void yyerror (const char *s);
343 [%token "end of file"
354 AT_CHECK([bison input.y -o input.c])
355 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
364 # The generation of the reduction was once wrong in Bison, and made it
365 # miss some reductions. In the following test case, the reduction on
366 # `undef_id_tok' in state 1 was missing. This is stripped down from
367 # the actual web2c.y.
369 AT_SETUP([Web2c Report])
372 [[%token undef_id_tok const_id_tok
374 %start CONST_DEC_PART
383 | CONST_DEC_LIST CONST_DEC
387 { } undef_id_tok '=' const_id_tok ';'
393 AT_CHECK([bison -v input.y])
395 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
398 0 6 $axiom -> CONST_DEC_PART $
399 1 6 CONST_DEC_PART -> CONST_DEC_LIST
400 2 10 CONST_DEC_LIST -> CONST_DEC
401 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
402 4 15 @1 -> /* empty */
403 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
404 Terminals, with rules where they appear
411 Nonterminals, with rules where they appear
415 on left: 1, on right: 0
417 on left: 2 3, on right: 1 3
419 on left: 5, on right: 2 3
421 on left: 4, on right: 5
423 $axiom -> . CONST_DEC_PART $ (rule 0)
424 $default reduce using rule 4 (@1)
425 CONST_DEC_PART go to state 1
426 CONST_DEC_LIST go to state 2
427 CONST_DEC go to state 3
430 $axiom -> CONST_DEC_PART . $ (rule 0)
431 $ shift, and go to state 5
433 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
434 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
435 undef_id_tok reduce using rule 4 (@1)
436 $default reduce using rule 1 (CONST_DEC_PART)
437 CONST_DEC go to state 6
440 CONST_DEC_LIST -> CONST_DEC . (rule 2)
441 $default reduce using rule 2 (CONST_DEC_LIST)
443 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
444 undef_id_tok shift, and go to state 7
446 $axiom -> CONST_DEC_PART $ . (rule 0)
449 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
450 $default reduce using rule 3 (CONST_DEC_LIST)
452 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
453 '=' shift, and go to state 8
455 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
456 const_id_tok shift, and go to state 9
458 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
459 ';' shift, and go to state 10
461 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
462 $default reduce using rule 5 (CONST_DEC)
468 ## --------------- ##
470 ## --------------- ##
472 # The generation of the mapping `state -> action' was once wrong in
473 # extremely specific situations. web2c.y exhibits this situation.
474 # Below is a stripped version of the grammar. It looks like one can
475 # simplify it further, but just don't: it is tuned to exhibit a bug,
476 # which disapears when applying sane grammar transformations.
478 # It used to be wrong on yydefact only:
480 # static const short yydefact[] =
482 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
483 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
487 # but let's check all the tables.
490 AT_SETUP([Web2c Actions])
494 statement: struct_stat;
495 struct_stat: /* empty. */ | if else;
496 if: "if" "const" "then" statement;
497 else: "else" statement;
501 AT_CHECK([bison -v input.y -o input.c])
503 # Check only the tables. We don't use --no-parser, because it is
504 # still to be implemented in the experimental branch of Bison.
505 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
506 [[static const unsigned char yytranslate[] =
508 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
509 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
510 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
511 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
512 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
513 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
514 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
515 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
516 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
517 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
518 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
519 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
520 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
521 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
522 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
523 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
524 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
525 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
526 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
527 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
528 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
529 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
530 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
531 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
532 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
533 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
536 static const unsigned char yyprhs[] =
540 static const signed char yyrhs[] =
542 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
543 4, 5, 8, -1, 6, 8, -1
545 static const unsigned char yyrline[] =
549 static const char *const yytname[] =
551 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
552 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
554 static const short yytoknum[] =
556 0, 256, 257, 258, 259, 260, 261, -1
558 static const unsigned char yyr1[] =
560 0, 7, 8, 9, 9, 10, 11
562 static const unsigned char yyr2[] =
566 static const short yydefact[] =
568 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
571 static const short yydefgoto[] =
575 static const short yypact[] =
577 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
580 static const short yypgoto[] =
582 -32768, -7,-32768,-32768,-32768
584 static const short yytable[] =
586 10, 1, 11, 5, 6, 0, 7, 9
588 static const short yycheck[] =
590 7, 3, 9, 4, 0, -1, 6, 5
592 static const unsigned char yystos[] =
594 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,