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 $axiom -> . expr $ (rule 0)
144 'a' shift, and go to state 1
146 $default reduce using rule 3 (@2)
155 expr -> 'a' . @1 'b' (rule 2)
157 $default reduce using rule 1 (@1)
165 $axiom -> expr . $ (rule 0)
167 $ shift, and go to state 5
173 expr -> @2 . 'c' (rule 4)
175 'c' shift, and go to state 6
181 expr -> 'a' @1 . 'b' (rule 2)
183 'b' shift, and go to state 7
189 $axiom -> expr $ . (rule 0)
196 expr -> @2 'c' . (rule 4)
198 $default reduce using rule 4 (expr)
204 expr -> 'a' @1 'b' . (rule 2)
206 $default reduce using rule 2 (expr)
216 ## ---------------------- ##
217 ## Mixing %token styles. ##
218 ## ---------------------- ##
221 AT_SETUP([Mixing %token styles])
223 # Taken from the documentation.
225 [[%token <operator> OR "||"
226 %token <operator> LE 134 "<="
233 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
239 ## ---------------- ##
240 ## Invalid inputs. ##
241 ## ---------------- ##
244 AT_SETUP([Invalid inputs])
256 AT_CHECK([bison input.y], [1], [],
257 [[input.y:2: invalid input: `?'
258 input.y:3: invalid input: `}'
259 input.y:4: invalid input: `%{'
260 input.y:5: invalid input: `%&'
261 input.y:6: invalid input: `%a'
262 input.y:7: invalid input: `%-'
269 ## -------------------- ##
270 ## Invalid %directive. ##
271 ## -------------------- ##
274 AT_SETUP([Invalid %directive])
280 AT_CHECK([bison input.y], [1], [],
281 [[input.y:1: unrecognized: %invalid
282 input.y:1: Skipping to next %
283 input.y:2: fatal error: no input grammar
290 ## ------------------- ##
291 ## Token definitions. ##
292 ## ------------------- ##
295 AT_SETUP([Token definitions])
297 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
299 [[%token "end of file"
310 AT_CHECK([bison input.y -o input.c])
311 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
320 # The generation of the reduction was once wrong in Bison, and made it
321 # miss some reductions. In the following test case, the reduction on
322 # `undef_id_tok' in state 1 was missing. This is stripped down from
323 # the actual web2c.y.
325 AT_SETUP([Web2c Report])
328 [[%token undef_id_tok const_id_tok
330 %start CONST_DEC_PART
339 | CONST_DEC_LIST CONST_DEC
343 { } undef_id_tok '=' const_id_tok ';'
349 AT_CHECK([bison -v input.y])
351 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
354 0 6 $axiom -> CONST_DEC_PART $
355 1 6 CONST_DEC_PART -> CONST_DEC_LIST
356 2 10 CONST_DEC_LIST -> CONST_DEC
357 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
358 4 15 @1 -> /* empty */
359 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
360 Terminals, with rules where they appear
367 Nonterminals, with rules where they appear
371 on left: 1, on right: 0
373 on left: 2 3, on right: 1 3
375 on left: 5, on right: 2 3
377 on left: 4, on right: 5
379 $axiom -> . CONST_DEC_PART $ (rule 0)
380 $default reduce using rule 4 (@1)
381 CONST_DEC_PART go to state 1
382 CONST_DEC_LIST go to state 2
383 CONST_DEC go to state 3
386 $axiom -> CONST_DEC_PART . $ (rule 0)
387 $ shift, and go to state 5
389 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
390 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
391 undef_id_tok reduce using rule 4 (@1)
392 $default reduce using rule 1 (CONST_DEC_PART)
393 CONST_DEC go to state 6
396 CONST_DEC_LIST -> CONST_DEC . (rule 2)
397 $default reduce using rule 2 (CONST_DEC_LIST)
399 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
400 undef_id_tok shift, and go to state 7
402 $axiom -> CONST_DEC_PART $ . (rule 0)
405 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
406 $default reduce using rule 3 (CONST_DEC_LIST)
408 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
409 '=' shift, and go to state 8
411 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
412 const_id_tok shift, and go to state 9
414 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
415 ';' shift, and go to state 10
417 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
418 $default reduce using rule 5 (CONST_DEC)
424 ## --------------- ##
426 ## --------------- ##
428 # The generation of the mapping `state -> action' was once wrong in
429 # extremely specific situations. web2c.y exhibits this situation.
430 # Below is a stripped version of the grammar. It looks like one can
431 # simplify it further, but just don't: it is tuned to exhibit a bug,
432 # which disapears when applying sane grammar transformations.
434 # It used to be wrong on yydefact only:
436 # static const short yydefact[] =
438 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
439 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
443 # but let's check all the tables.
446 AT_SETUP([Web2c Actions])
450 statement: struct_stat;
451 struct_stat: /* empty. */ | if else;
452 if: "if" "const" "then" statement;
453 else: "else" statement;
457 AT_CHECK([bison -v input.y -o input.c])
459 # Check only the tables. We don't use --no-parser, because it is
460 # still to be implemented in the experimental branch of Bison.
461 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
462 [[static const yy_token_number_type yytranslate[] =
464 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
465 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
466 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
467 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
468 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
469 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
470 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
471 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
472 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
474 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
475 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
476 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
477 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
478 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
479 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
480 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
481 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
482 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
483 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
484 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
485 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
486 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
487 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
488 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
489 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
492 static const unsigned char yyprhs[] =
496 static const signed char yyrhs[] =
498 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
499 4, 5, 8, -1, 6, 8, -1
501 static const unsigned char yyrline[] =
505 static const char *const yytname[] =
507 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
508 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
510 static const short yytoknum[] =
512 0, 256, 257, 258, 259, 260, 261, -1
514 static const yy_token_number_type yyr1[] =
516 0, 7, 8, 9, 9, 10, 11
518 static const unsigned char yyr2[] =
522 static const short yydefact[] =
524 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
527 static const short yydefgoto[] =
531 static const short yypact[] =
533 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
536 static const short yypgoto[] =
538 -32768, -7,-32768,-32768,-32768
540 static const short yytable[] =
542 10, 1, 11, 5, 6, 0, 7, 9
544 static const short yycheck[] =
546 7, 3, 9, 4, 0, -1, 6, 5