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_COMPILE([input], [-c input.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.8-14: warning: symbol `"<="' used more than once as a literal string
109 ## ------------------- ##
110 ## Rule Line Numbers. ##
111 ## ------------------- ##
113 AT_SETUP([Rule Line Numbers])
115 AT_KEYWORDS([report])
147 AT_CHECK([bison input.y -o input.c -v])
149 # Check the contents of the report.
150 AT_CHECK([cat input.output], [],
164 Terminals, with rules where they appear
173 Nonterminals, with rules where they appear
178 on left: 2 4, on right: 0
180 on left: 1, on right: 2
182 on left: 3, on right: 4
189 'a' shift, and go to state 1
191 $default reduce using rule 3 (@2)
201 $default reduce using rule 1 (@1)
210 $ shift, and go to state 5
217 'c' shift, and go to state 6
224 'b' shift, and go to state 7
238 $default reduce using rule 4 (expr)
245 $default reduce using rule 2 (expr)
252 ## ---------------------- ##
253 ## Mixing %token styles. ##
254 ## ---------------------- ##
257 AT_SETUP([Mixing %token styles])
259 # Taken from the documentation.
261 [[%token <operator> OR "||"
262 %token <operator> LE 134 "<="
269 AT_CHECK([bison -v input.y -o input.c])
275 ## ---------------- ##
276 ## Invalid inputs. ##
277 ## ---------------- ##
280 AT_SETUP([Invalid inputs])
292 AT_CHECK([bison input.y], [1], [],
293 [[input.y:2.1: invalid character: `?'
294 input.y:3.14: invalid character: `}'
295 input.y:4.1: invalid character: `%'
296 input.y:4.2: invalid character: `&'
297 input.y:5.1: invalid character: `%'
298 input.y:6.1: invalid character: `%'
299 input.y:6.2: invalid character: `-'
300 input.y:7.1-8.0: unexpected end of file in a prologue
301 input.y:7.1-8.0: parse error, unexpected PROLOGUE, expecting ";" or "|"
308 ## ------------------- ##
309 ## Token definitions. ##
310 ## ------------------- ##
313 AT_SETUP([Token definitions])
315 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
318 void yyerror (const char *s);
321 [%token YYEOF 0 "end of file"
330 AT_CHECK([bison input.y -o input.c])
331 AT_COMPILE([input], [input.c -c])
340 # The generation of the reduction was once wrong in Bison, and made it
341 # miss some reductions. In the following test case, the reduction on
342 # `undef_id_tok' in state 1 was missing. This is stripped down from
343 # the actual web2c.y.
345 AT_SETUP([Web2c Report])
347 AT_KEYWORDS([report])
350 [[%token undef_id_tok const_id_tok
352 %start CONST_DEC_PART
361 | CONST_DEC_LIST CONST_DEC
365 { } undef_id_tok '=' const_id_tok ';'
370 AT_CHECK([bison -v input.y])
371 AT_CHECK([cat input.output], 0,
374 0 $axiom: CONST_DEC_PART $
376 1 CONST_DEC_PART: CONST_DEC_LIST
378 2 CONST_DEC_LIST: CONST_DEC
379 3 | CONST_DEC_LIST CONST_DEC
383 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
386 Terminals, with rules where they appear
396 Nonterminals, with rules where they appear
401 on left: 1, on right: 0
403 on left: 2 3, on right: 1 3
405 on left: 5, on right: 2 3
407 on left: 4, on right: 5
412 0 $axiom: . CONST_DEC_PART $
414 $default reduce using rule 4 (@1)
416 CONST_DEC_PART go to state 1
417 CONST_DEC_LIST go to state 2
418 CONST_DEC go to state 3
424 0 $axiom: CONST_DEC_PART . $
426 $ shift, and go to state 5
431 1 CONST_DEC_PART: CONST_DEC_LIST .
432 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
434 undef_id_tok reduce using rule 4 (@1)
435 $default reduce using rule 1 (CONST_DEC_PART)
437 CONST_DEC go to state 6
443 2 CONST_DEC_LIST: CONST_DEC .
445 $default reduce using rule 2 (CONST_DEC_LIST)
450 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
452 undef_id_tok shift, and go to state 7
457 0 $axiom: CONST_DEC_PART $ .
464 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
466 $default reduce using rule 3 (CONST_DEC_LIST)
471 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
473 '=' shift, and go to state 8
478 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
480 const_id_tok shift, and go to state 9
485 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
487 ';' shift, and go to state 10
492 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
494 $default reduce using rule 5 (CONST_DEC)
500 ## --------------- ##
502 ## --------------- ##
504 # The generation of the mapping `state -> action' was once wrong in
505 # extremely specific situations. web2c.y exhibits this situation.
506 # Below is a stripped version of the grammar. It looks like one can
507 # simplify it further, but just don't: it is tuned to exhibit a bug,
508 # which disapears when applying sane grammar transformations.
510 # It used to be wrong on yydefact only:
512 # static const short yydefact[] =
514 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
515 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
519 # but let's check all the tables.
522 AT_SETUP([Web2c Actions])
524 AT_KEYWORDS([report])
528 statement: struct_stat;
529 struct_stat: /* empty. */ | if else;
530 if: "if" "const" "then" statement;
531 else: "else" statement;
535 AT_CHECK([bison -v input.y -o input.c])
537 # Check only the tables. We don't use --no-parser, because it is
538 # still to be implemented in the experimental branch of Bison.
539 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
541 AT_CHECK([[cat tables.c]], 0,
542 [[static const unsigned char yytranslate[] =
544 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
545 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
546 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
547 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
548 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
549 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
550 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
551 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
552 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
553 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
554 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
555 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
556 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
557 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
558 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
559 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
560 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
561 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
566 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
567 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
569 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
572 static const unsigned char yyprhs[] =
576 static const signed char yyrhs[] =
578 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
579 4, 5, 8, -1, 6, 8, -1
581 static const unsigned char yyrline[] =
585 static const char *const yytname[] =
587 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
588 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
590 static const short yytoknum[] =
592 0, 256, 257, 258, 259, 260, 261, -1
594 static const unsigned char yyr1[] =
596 0, 7, 8, 9, 9, 10, 11
598 static const unsigned char yyr2[] =
602 static const unsigned char yydefact[] =
604 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
607 static const signed char yydefgoto[] =
611 static const signed char yypact[] =
613 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
616 static const signed char yypgoto[] =
620 static const unsigned char yytable[] =
622 10, 1, 11, 5, 6, 0, 7, 9
624 static const signed char yycheck[] =
626 7, 3, 9, 4, 0, -1, 6, 5
628 static const unsigned char yystos[] =
630 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,