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])
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
187 $axiom -> . expr $ (rule 0)
189 'a' shift, and go to state 1
191 $default reduce using rule 3 (@2)
200 expr -> 'a' . @1 'b' (rule 2)
202 $default reduce using rule 1 (@1)
210 $axiom -> expr . $ (rule 0)
212 $ shift, and go to state 5
218 expr -> @2 . 'c' (rule 4)
220 'c' shift, and go to state 6
226 expr -> 'a' @1 . 'b' (rule 2)
228 'b' shift, and go to state 7
234 $axiom -> expr $ . (rule 0)
241 expr -> @2 'c' . (rule 4)
243 $default reduce using rule 4 (expr)
249 expr -> 'a' @1 'b' . (rule 2)
251 $default reduce using rule 2 (expr)
261 ## ---------------------- ##
262 ## Mixing %token styles. ##
263 ## ---------------------- ##
266 AT_SETUP([Mixing %token styles])
268 # Taken from the documentation.
270 [[%token <operator> OR "||"
271 %token <operator> LE 134 "<="
278 AT_CHECK([bison -v input.y -o input.c])
284 ## ---------------- ##
285 ## Invalid inputs. ##
286 ## ---------------- ##
289 AT_SETUP([Invalid inputs])
301 AT_CHECK([bison input.y], [1], [],
302 [[input.y:2.1: invalid character: `?'
303 input.y:3.14: invalid character: `}'
304 input.y:4.1: invalid character: `%'
305 input.y:4.2: invalid character: `&'
306 input.y:5.1: invalid character: `%'
307 input.y:6.1: invalid character: `%'
308 input.y:6.2: invalid character: `-'
309 input.y:7.1-8.0: unexpected end of file in a prologue
310 input.y:7.1-8.0: parse error, unexpected PROLOGUE, expecting ";" or "|"
311 input.y:5.2: symbol a is used, but is not defined as a token and has no rules
318 ## ------------------- ##
319 ## Token definitions. ##
320 ## ------------------- ##
323 AT_SETUP([Token definitions])
325 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
328 void yyerror (const char *s);
331 [%token YYEOF 0 "end of file"
340 AT_CHECK([bison input.y -o input.c])
341 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
350 # The generation of the reduction was once wrong in Bison, and made it
351 # miss some reductions. In the following test case, the reduction on
352 # `undef_id_tok' in state 1 was missing. This is stripped down from
353 # the actual web2c.y.
355 AT_SETUP([Web2c Report])
357 AT_KEYWORDS([report])
360 [[%token undef_id_tok const_id_tok
362 %start CONST_DEC_PART
371 | CONST_DEC_LIST CONST_DEC
375 { } undef_id_tok '=' const_id_tok ';'
381 AT_CHECK([bison -v input.y])
383 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
385 0 $axiom: CONST_DEC_PART $
386 1 CONST_DEC_PART: CONST_DEC_LIST
387 2 CONST_DEC_LIST: CONST_DEC
388 3 | CONST_DEC_LIST CONST_DEC
390 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
391 Terminals, with rules where they appear
398 Nonterminals, with rules where they appear
402 on left: 1, on right: 0
404 on left: 2 3, on right: 1 3
406 on left: 5, on right: 2 3
408 on left: 4, on right: 5
410 $axiom -> . CONST_DEC_PART $ (rule 0)
411 $default reduce using rule 4 (@1)
412 CONST_DEC_PART go to state 1
413 CONST_DEC_LIST go to state 2
414 CONST_DEC go to state 3
417 $axiom -> CONST_DEC_PART . $ (rule 0)
418 $ shift, and go to state 5
420 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
421 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
422 undef_id_tok reduce using rule 4 (@1)
423 $default reduce using rule 1 (CONST_DEC_PART)
424 CONST_DEC go to state 6
427 CONST_DEC_LIST -> CONST_DEC . (rule 2)
428 $default reduce using rule 2 (CONST_DEC_LIST)
430 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
431 undef_id_tok shift, and go to state 7
433 $axiom -> CONST_DEC_PART $ . (rule 0)
436 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
437 $default reduce using rule 3 (CONST_DEC_LIST)
439 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
440 '=' shift, and go to state 8
442 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
443 const_id_tok shift, and go to state 9
445 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
446 ';' shift, and go to state 10
448 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
449 $default reduce using rule 5 (CONST_DEC)
455 ## --------------- ##
457 ## --------------- ##
459 # The generation of the mapping `state -> action' was once wrong in
460 # extremely specific situations. web2c.y exhibits this situation.
461 # Below is a stripped version of the grammar. It looks like one can
462 # simplify it further, but just don't: it is tuned to exhibit a bug,
463 # which disapears when applying sane grammar transformations.
465 # It used to be wrong on yydefact only:
467 # static const short yydefact[] =
469 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
470 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
474 # but let's check all the tables.
477 AT_SETUP([Web2c Actions])
479 AT_KEYWORDS([report])
483 statement: struct_stat;
484 struct_stat: /* empty. */ | if else;
485 if: "if" "const" "then" statement;
486 else: "else" statement;
490 AT_CHECK([bison -v input.y -o input.c])
492 # Check only the tables. We don't use --no-parser, because it is
493 # still to be implemented in the experimental branch of Bison.
494 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
495 [[static const unsigned char yytranslate[] =
497 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
498 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
499 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
500 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
501 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
502 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
503 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
504 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
505 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
506 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
507 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
508 2, 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, 1, 2, 3, 4,
525 static const unsigned char yyprhs[] =
529 static const signed char yyrhs[] =
531 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
532 4, 5, 8, -1, 6, 8, -1
534 static const unsigned char yyrline[] =
538 static const char *const yytname[] =
540 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
541 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
543 static const short yytoknum[] =
545 0, 256, 257, 258, 259, 260, 261, -1
547 static const unsigned char yyr1[] =
549 0, 7, 8, 9, 9, 10, 11
551 static const unsigned char yyr2[] =
555 static const short yydefact[] =
557 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
560 static const short yydefgoto[] =
564 static const short yypact[] =
566 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
569 static const short yypgoto[] =
571 -32768, -7,-32768,-32768,-32768
573 static const short yytable[] =
575 10, 1, 11, 5, 6, 0, 7, 9
577 static const short yycheck[] =
579 7, 3, 9, 4, 0, -1, 6, 5
581 static const unsigned char yystos[] =
583 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,