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.1: invalid character: `?'
298 input.y:3.14: invalid character: `}'
299 input.y:4.1: invalid character: `%'
300 input.y:4.2: invalid character: `&'
301 input.y:5.1: invalid character: `%'
302 input.y:6.1: invalid character: `%'
303 input.y:6.2: invalid character: `-'
304 input.y:7.1-8.0: unexpected end of file in a prologue
305 input.y:7.1-8.0: parse error, unexpected PROLOGUE, expecting ";" or "|"
306 input.y:8: symbol a is used, but is not defined as a token and has no rules
313 ## ------------------- ##
314 ## Token definitions. ##
315 ## ------------------- ##
318 AT_SETUP([Token definitions])
320 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
323 void yyerror (const char *s);
326 [%token YYEOF 0 "end of file"
335 AT_CHECK([bison input.y -o input.c])
336 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
345 # The generation of the reduction was once wrong in Bison, and made it
346 # miss some reductions. In the following test case, the reduction on
347 # `undef_id_tok' in state 1 was missing. This is stripped down from
348 # the actual web2c.y.
350 AT_SETUP([Web2c Report])
353 [[%token undef_id_tok const_id_tok
355 %start CONST_DEC_PART
364 | CONST_DEC_LIST CONST_DEC
368 { } undef_id_tok '=' const_id_tok ';'
374 AT_CHECK([bison -v input.y])
376 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
379 0 6 $axiom -> CONST_DEC_PART $
380 1 6 CONST_DEC_PART -> CONST_DEC_LIST
381 2 10 CONST_DEC_LIST -> CONST_DEC
382 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
383 4 15 @1 -> /* empty */
384 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
385 Terminals, with rules where they appear
392 Nonterminals, with rules where they appear
396 on left: 1, on right: 0
398 on left: 2 3, on right: 1 3
400 on left: 5, on right: 2 3
402 on left: 4, on right: 5
404 $axiom -> . CONST_DEC_PART $ (rule 0)
405 $default reduce using rule 4 (@1)
406 CONST_DEC_PART go to state 1
407 CONST_DEC_LIST go to state 2
408 CONST_DEC go to state 3
411 $axiom -> CONST_DEC_PART . $ (rule 0)
412 $ shift, and go to state 5
414 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
415 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
416 undef_id_tok reduce using rule 4 (@1)
417 $default reduce using rule 1 (CONST_DEC_PART)
418 CONST_DEC go to state 6
421 CONST_DEC_LIST -> CONST_DEC . (rule 2)
422 $default reduce using rule 2 (CONST_DEC_LIST)
424 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
425 undef_id_tok shift, and go to state 7
427 $axiom -> CONST_DEC_PART $ . (rule 0)
430 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
431 $default reduce using rule 3 (CONST_DEC_LIST)
433 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
434 '=' shift, and go to state 8
436 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
437 const_id_tok shift, and go to state 9
439 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
440 ';' shift, and go to state 10
442 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
443 $default reduce using rule 5 (CONST_DEC)
449 ## --------------- ##
451 ## --------------- ##
453 # The generation of the mapping `state -> action' was once wrong in
454 # extremely specific situations. web2c.y exhibits this situation.
455 # Below is a stripped version of the grammar. It looks like one can
456 # simplify it further, but just don't: it is tuned to exhibit a bug,
457 # which disapears when applying sane grammar transformations.
459 # It used to be wrong on yydefact only:
461 # static const short yydefact[] =
463 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
464 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
468 # but let's check all the tables.
471 AT_SETUP([Web2c Actions])
475 statement: struct_stat;
476 struct_stat: /* empty. */ | if else;
477 if: "if" "const" "then" statement;
478 else: "else" statement;
482 AT_CHECK([bison -v input.y -o input.c])
484 # Check only the tables. We don't use --no-parser, because it is
485 # still to be implemented in the experimental branch of Bison.
486 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
487 [[static const unsigned char yytranslate[] =
489 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
490 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
491 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
492 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
493 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
494 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
495 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
496 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
497 2, 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, 1, 2, 3, 4,
517 static const unsigned char yyprhs[] =
521 static const signed char yyrhs[] =
523 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
524 4, 5, 8, -1, 6, 8, -1
526 static const unsigned char yyrline[] =
530 static const char *const yytname[] =
532 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
533 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
535 static const short yytoknum[] =
537 0, 256, 257, 258, 259, 260, 261, -1
539 static const unsigned char yyr1[] =
541 0, 7, 8, 9, 9, 10, 11
543 static const unsigned char yyr2[] =
547 static const short yydefact[] =
549 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
552 static const short yydefgoto[] =
556 static const short yypact[] =
558 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
561 static const short yypgoto[] =
563 -32768, -7,-32768,-32768,-32768
565 static const short yytable[] =
567 10, 1, 11, 5, 6, 0, 7, 9
569 static const short yycheck[] =
571 7, 3, 9, 4, 0, -1, 6, 5
573 static const unsigned char yystos[] =
575 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,