Formatting change.
[bison/ericb.git] / tests / regression.at
blob1845524238186751918918a6b02aa20052d7e8c1
1 # Bison Regressions.                               -*- Autotest -*-
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software
4 # Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 AT_BANNER([[Regression tests.]])
22 ## ------------------ ##
23 ## Trivial grammars.  ##
24 ## ------------------ ##
26 AT_SETUP([Trivial grammars])
28 AT_DATA_GRAMMAR([input.y],
29 [[%{
30 void yyerror (char const *);
31 int yylex (void);
32 #define YYSTYPE int *
35 %error-verbose
39 program: 'x';
40 ]])
42 AT_BISON_CHECK([-o input.c input.y])
43 AT_COMPILE([input.o], [-c input.c])
44 AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
46 AT_CLEANUP
50 ## ----------------- ##
51 ## YYSTYPE typedef.  ##
52 ## ----------------- ##
54 AT_SETUP([YYSTYPE typedef])
56 AT_DATA_GRAMMAR([input.y],
57 [[%{
58 void yyerror (char const *);
59 int yylex (void);
60 typedef union { char const *val; } YYSTYPE;
63 %type <val> program
67 program: { $$ = ""; };
68 ]])
70 AT_BISON_CHECK([-o input.c input.y])
71 AT_COMPILE([input.o], [-c input.c])
73 AT_CLEANUP
77 ## ------------------------------------- ##
78 ## Early token definitions with --yacc.  ##
79 ## ------------------------------------- ##
82 AT_SETUP([Early token definitions with --yacc])
84 # Found in GCJ: they expect the tokens to be defined before the user
85 # prologue, so that they can use the token definitions in it.
87 AT_DATA_GRAMMAR([input.y],
88 [[%{
89 void yyerror (const char *s);
90 int yylex (void);
93 %union
95   int val;
98 #ifndef MY_TOKEN
99 # error "MY_TOKEN not defined."
100 #endif
102 %token MY_TOKEN
104 exp: MY_TOKEN;
108 AT_BISON_CHECK([-y -o input.c input.y])
109 AT_COMPILE([input.o], [-c input.c])
111 AT_CLEANUP
115 ## ---------------------------------------- ##
116 ## Early token definitions without --yacc.  ##
117 ## ---------------------------------------- ##
120 AT_SETUP([Early token definitions without --yacc])
122 # Found in GCJ: they expect the tokens to be defined before the user
123 # prologue, so that they can use the token definitions in it.
125 AT_DATA_GRAMMAR([input.y],
126 [[%{
127 #include <stdio.h>
128 void yyerror (const char *s);
129 int yylex (void);
130 void print_my_token (void);
133 %union
135   int val;
138 void
139 print_my_token (void)
141   enum yytokentype my_token = MY_TOKEN;
142   printf ("%d\n", my_token);
145 %token MY_TOKEN
147 exp: MY_TOKEN;
151 AT_BISON_CHECK([-o input.c input.y])
152 AT_COMPILE([input.o], [-c input.c])
154 AT_CLEANUP
158 ## ---------------- ##
159 ## Braces parsing.  ##
160 ## ---------------- ##
163 AT_SETUP([Braces parsing])
165 AT_DATA([input.y],
166 [[/* Bison used to swallow the character after `}'. */
169 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
173 AT_BISON_CHECK([-v -o input.c input.y])
175 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
177 AT_CLEANUP
180 ## ------------------ ##
181 ## Duplicate string.  ##
182 ## ------------------ ##
185 AT_SETUP([Duplicate string])
187 AT_DATA([input.y],
188 [[/* `Bison -v' used to dump core when two tokens are defined with the same
189    string, as LE and GE below. */
191 %token NUM
192 %token LE "<="
193 %token GE "<="
196 exp: '(' exp ')' | NUM ;
200 AT_BISON_CHECK([-v -o input.c input.y], 0, [],
201 [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
204 AT_CLEANUP
207 ## ------------------- ##
208 ## Rule Line Numbers.  ##
209 ## ------------------- ##
211 AT_SETUP([Rule Line Numbers])
213 AT_KEYWORDS([report])
215 AT_DATA([input.y],
216 [[%%
217 expr:
245 AT_BISON_CHECK([-o input.c -v input.y])
247 # Check the contents of the report.
248 AT_CHECK([cat input.output], [],
249 [[Grammar
251     0 $accept: expr $end
253     1 $@1: /* empty */
255     2 expr: 'a' $@1 'b'
257     3 $@2: /* empty */
259     4 expr: $@2 'c'
262 Terminals, with rules where they appear
264 $end (0) 0
265 'a' (97) 2
266 'b' (98) 2
267 'c' (99) 4
268 error (256)
271 Nonterminals, with rules where they appear
273 $accept (6)
274     on left: 0
275 expr (7)
276     on left: 2 4, on right: 0
277 $@1 (8)
278     on left: 1, on right: 2
279 $@2 (9)
280     on left: 3, on right: 4
283 state 0
285     0 $accept: . expr $end
287     'a'  shift, and go to state 1
289     $default  reduce using rule 3 ($@2)
291     expr  go to state 2
292     $@2   go to state 3
295 state 1
297     2 expr: 'a' . $@1 'b'
299     $default  reduce using rule 1 ($@1)
301     $@1  go to state 4
304 state 2
306     0 $accept: expr . $end
308     $end  shift, and go to state 5
311 state 3
313     4 expr: $@2 . 'c'
315     'c'  shift, and go to state 6
318 state 4
320     2 expr: 'a' $@1 . 'b'
322     'b'  shift, and go to state 7
325 state 5
327     0 $accept: expr $end .
329     $default  accept
332 state 6
334     4 expr: $@2 'c' .
336     $default  reduce using rule 4 (expr)
339 state 7
341     2 expr: 'a' $@1 'b' .
343     $default  reduce using rule 2 (expr)
346 AT_CLEANUP
350 ## ---------------------- ##
351 ## Mixing %token styles.  ##
352 ## ---------------------- ##
355 AT_SETUP([Mixing %token styles])
357 # Taken from the documentation.
358 AT_DATA([input.y],
359 [[%token  <operator>  OR      "||"
360 %token  <operator>  LE 134  "<="
361 %left  OR  "<="
363 exp: ;
367 AT_BISON_CHECK([-v -o input.c input.y])
369 AT_CLEANUP
373 ## ---------------- ##
374 ## Invalid inputs.  ##
375 ## ---------------- ##
378 AT_SETUP([Invalid inputs])
380 AT_DATA([input.y],
381 [[%%
383 default: 'a' }
385 %a-does-not-exist
390 AT_BISON_CHECK([input.y], [1], [],
391 [[input.y:2.1: invalid character: `?'
392 input.y:3.14: invalid character: `}'
393 input.y:4.1: invalid character: `%'
394 input.y:4.2: invalid character: `&'
395 input.y:5.1-17: invalid directive: `%a-does-not-exist'
396 input.y:6.1: invalid character: `%'
397 input.y:6.2: invalid character: `-'
398 input.y:7.1-8.0: missing `%}' at end of file
399 input.y:7.1-8.0: syntax error, unexpected %{...%}
402 AT_CLEANUP
405 AT_SETUP([Invalid inputs with {}])
407 AT_DATA([input.y],
409 %destructor
410 %initial-action
411 %lex-param
412 %parse-param
413 %printer
414 %union
417 AT_BISON_CHECK([input.y], [1], [],
418 [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
421 AT_CLEANUP
425 ## ------------------- ##
426 ## Token definitions.  ##
427 ## ------------------- ##
430 AT_SETUP([Token definitions])
432 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
433 AT_DATA_GRAMMAR([input.y],
435 #include <stdlib.h>
436 #include <stdio.h>
437 void yyerror (const char *s);
438 int yylex (void);
440 [%error-verbose
441 %token MYEOF 0 "end of file"
442 %token 'a' "a"
443 %token B_TOKEN "b"
444 %token C_TOKEN 'c'
445 %token 'd' D_TOKEN
446 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
447 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
449 exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
451 void
452 yyerror (char const *s)
454   fprintf (stderr, "%s\n", s);
458 yylex (void)
460   static int called;
461   if (called++)
462     abort ();
463   return SPECIAL;
467 main (void)
469   return yyparse ();
473 # Checking the warning message guarantees that the trigraph "??!" isn't
474 # unnecessarily escaped here even though it would need to be if encoded in a
475 # C-string literal.  Also notice that unnecessary escaping, such as "\?", from
476 # the user specification is eliminated.
477 AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
478 [[input.y:22.8-14: warning: symbol SPECIAL redeclared
479 input.y:22.8-63: warning: symbol `"\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!"' used more than once as a literal string
481 AT_COMPILE([input])
483 # Checking the error message here guarantees that yytname, which does contain
484 # C-string literals, does have the trigraph escaped correctly.  Thus, the
485 # symbol name reported by the parser is exactly the same as that reported by
486 # Bison itself.
487 AT_DATA([experr],
488 [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a
490 AT_PARSER_CHECK([./input], 1, [], [experr])
491 AT_CLEANUP
495 ## -------------------- ##
496 ## Characters Escapes.  ##
497 ## -------------------- ##
500 AT_SETUP([Characters Escapes])
502 AT_DATA_GRAMMAR([input.y],
504 void yyerror (const char *s);
505 int yylex (void);
508 exp:
509   '\'' "\'"
510 | '\"' "\""
511 | '"'  "'"
514 # Pacify font-lock-mode: "
516 AT_BISON_CHECK([-o input.c input.y])
517 AT_COMPILE([input.o], [-c input.c])
518 AT_CLEANUP
522 ## -------------- ##
523 ## Web2c Report.  ##
524 ## -------------- ##
526 # The generation of the reduction was once wrong in Bison, and made it
527 # miss some reductions.  In the following test case, the reduction on
528 # `undef_id_tok' in state 1 was missing.  This is stripped down from
529 # the actual web2c.y.
531 AT_SETUP([Web2c Report])
533 AT_KEYWORDS([report])
535 AT_DATA([input.y],
536 [[%token        undef_id_tok const_id_tok
538 %start CONST_DEC_PART
541 CONST_DEC_PART:
542          CONST_DEC_LIST
543         ;
545 CONST_DEC_LIST:
546           CONST_DEC
547         | CONST_DEC_LIST CONST_DEC
548         ;
550 CONST_DEC:
551           { } undef_id_tok '=' const_id_tok ';'
552         ;
556 AT_BISON_CHECK([-v input.y])
557 AT_CHECK([cat input.output], 0,
558 [[Grammar
560     0 $accept: CONST_DEC_PART $end
562     1 CONST_DEC_PART: CONST_DEC_LIST
564     2 CONST_DEC_LIST: CONST_DEC
565     3               | CONST_DEC_LIST CONST_DEC
567     4 $@1: /* empty */
569     5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
572 Terminals, with rules where they appear
574 $end (0) 0
575 ';' (59) 5
576 '=' (61) 5
577 error (256)
578 undef_id_tok (258) 5
579 const_id_tok (259) 5
582 Nonterminals, with rules where they appear
584 $accept (7)
585     on left: 0
586 CONST_DEC_PART (8)
587     on left: 1, on right: 0
588 CONST_DEC_LIST (9)
589     on left: 2 3, on right: 1 3
590 CONST_DEC (10)
591     on left: 5, on right: 2 3
592 $@1 (11)
593     on left: 4, on right: 5
596 state 0
598     0 $accept: . CONST_DEC_PART $end
600     $default  reduce using rule 4 ($@1)
602     CONST_DEC_PART  go to state 1
603     CONST_DEC_LIST  go to state 2
604     CONST_DEC       go to state 3
605     $@1             go to state 4
608 state 1
610     0 $accept: CONST_DEC_PART . $end
612     $end  shift, and go to state 5
615 state 2
617     1 CONST_DEC_PART: CONST_DEC_LIST .
618     3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
620     undef_id_tok  reduce using rule 4 ($@1)
621     $default      reduce using rule 1 (CONST_DEC_PART)
623     CONST_DEC  go to state 6
624     $@1        go to state 4
627 state 3
629     2 CONST_DEC_LIST: CONST_DEC .
631     $default  reduce using rule 2 (CONST_DEC_LIST)
634 state 4
636     5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
638     undef_id_tok  shift, and go to state 7
641 state 5
643     0 $accept: CONST_DEC_PART $end .
645     $default  accept
648 state 6
650     3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
652     $default  reduce using rule 3 (CONST_DEC_LIST)
655 state 7
657     5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
659     '='  shift, and go to state 8
662 state 8
664     5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
666     const_id_tok  shift, and go to state 9
669 state 9
671     5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
673     ';'  shift, and go to state 10
676 state 10
678     5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
680     $default  reduce using rule 5 (CONST_DEC)
683 AT_CLEANUP
686 ## --------------- ##
687 ## Web2c Actions.  ##
688 ## --------------- ##
690 # The generation of the mapping `state -> action' was once wrong in
691 # extremely specific situations.  web2c.y exhibits this situation.
692 # Below is a stripped version of the grammar.  It looks like one can
693 # simplify it further, but just don't: it is tuned to exhibit a bug,
694 # which disapears when applying sane grammar transformations.
696 # It used to be wrong on yydefact only:
698 # static const yytype_uint8 yydefact[] =
699 #  {
700 # -       2,     0,     1,     0,     0,     2,     3,     2,     5,     4,
701 # +       2,     0,     1,     0,     0,     0,     3,     2,     5,     4,
702 #         0,     0
703 #  };
705 # but let's check all the tables.
708 AT_SETUP([Web2c Actions])
710 AT_KEYWORDS([report])
712 AT_DATA([input.y],
713 [[%%
714 statement:  struct_stat;
715 struct_stat:  /* empty. */ | if else;
716 if: "if" "const" "then" statement;
717 else: "else" statement;
721 AT_BISON_CHECK([-v -o input.c input.y])
723 # Check only the tables.
724 [sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
726 AT_CHECK([[cat tables.c]], 0,
727 [[static const yytype_uint8 yytranslate[] =
729        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
730        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
731        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
732        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
733        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
734        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
735        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
736        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
737        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
738        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
739        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
740        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
741        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
742        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
743        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
744        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
745        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
746        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
747        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
748        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
749        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
750        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
751        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
752        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
753        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
754        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
755        5,     6
757 static const yytype_uint8 yyprhs[] =
759        0,     0,     3,     5,     6,     9,    14
761 static const yytype_int8 yyrhs[] =
763        8,     0,    -1,     9,    -1,    -1,    10,    11,    -1,     3,
764        4,     5,     8,    -1,     6,     8,    -1
766 static const yytype_uint8 yyrline[] =
768        0,     2,     2,     3,     3,     4,     5
770 static const char *const yytname[] =
772   "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
773   "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
775 static const yytype_uint16 yytoknum[] =
777        0,   256,   257,   258,   259,   260,   261
779 static const yytype_uint8 yyr1[] =
781        0,     7,     8,     9,     9,    10,    11
783 static const yytype_uint8 yyr2[] =
785        0,     2,     1,     0,     2,     4,     2
787 static const yytype_uint8 yydefact[] =
789        3,     0,     0,     2,     0,     0,     1,     3,     4,     3,
790        6,     5
792 static const yytype_int8 yydefgoto[] =
794       -1,     2,     3,     4,     8
796 static const yytype_int8 yypact[] =
798       -2,    -1,     4,    -8,     0,     2,    -8,    -2,    -8,    -2,
799       -8,    -8
801 static const yytype_int8 yypgoto[] =
803       -8,    -7,    -8,    -8,    -8
805 static const yytype_uint8 yytable[] =
807       10,     1,    11,     5,     6,     0,     7,     9
809 static const yytype_int8 yycheck[] =
811        7,     3,     9,     4,     0,    -1,     6,     5
813 static const yytype_uint8 yystos[] =
815        0,     3,     8,     9,    10,     4,     0,     6,    11,     5,
816        8,     8
820 AT_CLEANUP
823 ## ------------------------- ##
824 ## yycheck Bound Violation.  ##
825 ## ------------------------- ##
828 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
829 # --------------------------------
830 # The following grammar, taken from Andrew Suffield's GPL'd implementation
831 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
832 # yycheck's bounds where issuing a verbose error message.  Keep this test
833 # so that possible bound checking compilers could check all the skeletons.
834 m4_define([_AT_DATA_DANCER_Y],
835 [AT_DATA_GRAMMAR([dancer.y],
837 static int yylex (AT_LALR1_CC_IF([int *], [void]));
838 AT_LALR1_CC_IF([],
839 [#include <stdlib.h>
840 #include <stdio.h>
841 static void yyerror (const char *);])
844 %token ARROW INVALID NUMBER STRING DATA
845 %defines
846 %verbose
847 %error-verbose
848 /* Grammar follows */
850 line: header body
851    ;
853 header: '<' from ARROW to '>' type ':'
854    | '<' ARROW to '>' type ':'
855    | ARROW to type ':'
856    | type ':'
857    | '<' '>'
858    ;
860 from: DATA
861    | STRING
862    | INVALID
863    ;
865 to: DATA
866    | STRING
867    | INVALID
868    ;
870 type: DATA
871    | STRING
872    | INVALID
873    ;
875 body: /* empty */
876    | body member
877    ;
879 member: STRING
880    | DATA
881    | '+' NUMBER
882    | '-' NUMBER
883    | NUMBER
884    | INVALID
885    ;
887 AT_LALR1_CC_IF(
888 [/* A C++ error reporting function. */
889 void
890 yy::parser::error (const std::string& m)
892   std::cerr << m << std::endl;
896 yyparse ()
898   yy::parser parser;
899 #if YYDEBUG
900   parser.set_debug_level (YYDEBUG);
901 #endif
902   return parser.parse ();
905 [static void
906 yyerror (const char *s)
908   fprintf (stderr, "%s\n", s);
911 static int
912 yylex (AT_LALR1_CC_IF([int *lval], [void]))
914   static int const tokens[] =
915     {
916       ':', -1
917     };
918   static size_t toknum;
919   ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC.  */])[
920   if (! (toknum < sizeof tokens / sizeof *tokens))
921     abort ();
922   return tokens[toknum++];
926 main (void)
928   return yyparse ();
931 ])# _AT_DATA_DANCER_Y
934 # AT_CHECK_DANCER(BISON-OPTIONS)
935 # ------------------------------
936 # Generate the grammar, compile it, run it.
937 m4_define([AT_CHECK_DANCER],
938 [AT_SETUP([Dancer $1])
939 AT_BISON_OPTION_PUSHDEFS([$1])
940 _AT_DATA_DANCER_Y([$1])
941 AT_BISON_CHECK([-o dancer.c dancer.y])
942 AT_FULL_COMPILE([dancer])
943 AT_PARSER_CHECK([./dancer], 1, [],
944 [syntax error, unexpected ':'
946 AT_BISON_OPTION_POPDEFS
947 AT_CLEANUP
950 AT_CHECK_DANCER()
951 AT_CHECK_DANCER([%glr-parser])
952 AT_CHECK_DANCER([%skeleton "lalr1.cc"])
955 ## ------------------------------------------ ##
956 ## Diagnostic that expects two alternatives.  ##
957 ## ------------------------------------------ ##
960 # _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
961 # --------------------------------
962 m4_define([_AT_DATA_EXPECT2_Y],
963 [AT_DATA_GRAMMAR([expect2.y],
965 static int yylex (AT_LALR1_CC_IF([int *], [void]));
966 AT_LALR1_CC_IF([],
967 [#include <stdio.h>
968 #include <stdlib.h>
969 static void yyerror (const char *);])
972 %defines
973 %error-verbose
974 %token A 1000
975 %token B
978 program: /* empty */
979  | program e ';'
980  | program error ';';
982 e: e '+' t | t;
983 t: A | B;
986 AT_LALR1_CC_IF(
987 [/* A C++ error reporting function. */
988 void
989 yy::parser::error (const std::string& m)
991   std::cerr << m << std::endl;
995 yyparse ()
997   yy::parser parser;
998   return parser.parse ();
1001 [static void
1002 yyerror (const char *s)
1004   fprintf (stderr, "%s\n", s);
1007 static int
1008 yylex (AT_LALR1_CC_IF([int *lval], [void]))
1010   static int const tokens[] =
1011     {
1012       1000, '+', '+', -1
1013     };
1014   static size_t toknum;
1015   ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC.  */])[
1016   if (! (toknum < sizeof tokens / sizeof *tokens))
1017     abort ();
1018   return tokens[toknum++];
1022 main (void)
1024   return yyparse ();
1027 ])# _AT_DATA_EXPECT2_Y
1030 # AT_CHECK_EXPECT2(BISON-OPTIONS)
1031 # ------------------------------
1032 # Generate the grammar, compile it, run it.
1033 m4_define([AT_CHECK_EXPECT2],
1034 [AT_SETUP([Expecting two tokens $1])
1035 AT_BISON_OPTION_PUSHDEFS([$1])
1036 _AT_DATA_EXPECT2_Y([$1])
1037 AT_BISON_CHECK([-o expect2.c expect2.y])
1038 AT_FULL_COMPILE([expect2])
1039 AT_PARSER_CHECK([./expect2], 1, [],
1040 [syntax error, unexpected '+', expecting A or B
1042 AT_BISON_OPTION_POPDEFS
1043 AT_CLEANUP
1046 AT_CHECK_EXPECT2()
1047 AT_CHECK_EXPECT2([%glr-parser])
1048 AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
1052 ## --------------------------------------------- ##
1053 ## Braced code in declaration in rules section.  ##
1054 ## --------------------------------------------- ##
1056 AT_SETUP([Braced code in declaration in rules section])
1058 # Bison once mistook braced code in a declaration in the rules section to be a
1059 # rule action.
1061 AT_DATA_GRAMMAR([input.y],
1062 [[%{
1063 #include <stdio.h>
1064 static void yyerror (char const *msg);
1065 static int yylex (void);
1068 %error-verbose
1072 start:
1073   {
1074     printf ("Bison would once convert this action to a midrule because of the"
1075             " subsequent braced code.\n");
1076   }
1077   ;
1079 %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1080 %printer { fprintf (yyoutput, "PRINTER"); } 'a';
1084 static void
1085 yyerror (char const *msg)
1087   fprintf (stderr, "%s\n", msg);
1090 static int
1091 yylex (void)
1093   return 'a';
1097 main (void)
1099   yydebug = 1;
1100   return !yyparse ();
1104 AT_BISON_CHECK([-t -o input.c input.y])
1105 AT_COMPILE([input])
1106 AT_PARSER_CHECK([./input], 0,
1107 [[Bison would once convert this action to a midrule because of the subsequent braced code.
1109 [[Starting parse
1110 Entering state 0
1111 Reducing stack by rule 1 (line 20):
1112 -> $$ = nterm start ()
1113 Stack now 0
1114 Entering state 1
1115 Reading a token: Next token is token 'a' (PRINTER)
1116 syntax error, unexpected 'a', expecting $end
1117 Error: popping nterm start ()
1118 Stack now 0
1119 Cleanup: discarding lookahead token 'a' (PRINTER)
1120 DESTRUCTOR
1121 Stack now 0
1124 AT_CLEANUP
1128 ## --------------------------------- ##
1129 ## String alias declared after use.  ##
1130 ## --------------------------------- ##
1132 AT_SETUP([String alias declared after use])
1134 # Bison once incorrectly asserted that the symbol number for either a token or
1135 # its alias was the highest symbol number so far at the point of the alias
1136 # declaration.  That was true unless the declaration appeared after their first
1137 # uses and other tokens appeared in between.
1139 AT_DATA([input.y],
1140 [[%%
1141 start: 'a' "A" 'b';
1142 %token 'a' "A";
1145 AT_BISON_CHECK([-t -o input.c input.y])
1147 AT_CLEANUP
1151 ## -------------------------------- ##
1152 ## Extra lookahead sets in report.  ##
1153 ## -------------------------------- ##
1155 AT_SETUP([[Extra lookahead sets in report]])
1157 # Bison prints each reduction's lookahead set only next to the associated
1158 # state's one item that (1) is associated with the same rule as the reduction
1159 # and (2) has its dot at the end of its RHS.  Previously, Bison also
1160 # erroneously printed the lookahead set next to all of the state's other items
1161 # associated with the same rule.  This bug affected only the `.output' file and
1162 # not the generated parser source code.
1164 AT_DATA([[input.y]],
1165 [[%%
1166 start: a | 'a' a 'a' ;
1167 a: 'a' ;
1170 AT_BISON_CHECK([[--report=all input.y]])
1171 AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]],
1172 [[state 1
1174     2 start: 'a' . a 'a'
1175     3 a: . 'a'
1176     3  | 'a' .  [$end]
1178     'a'  shift, and go to state 4
1180     $default  reduce using rule 3 (a)
1182     a  go to state 5
1185 state 2
1188 AT_CLEANUP
1192 ## ---------------------------------------- ##
1193 ## Token number in precedence declaration.  ##
1194 ## ---------------------------------------- ##
1196 AT_SETUP([[Token number in precedence declaration]])
1198 # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1199 # we lost this in Bison 1.50.
1201 AT_DATA_GRAMMAR([input.y],
1202 [[%{
1203   #include <stdio.h>
1204   void yyerror (char const *);
1205   int yylex (void);
1208 %error-verbose
1209 %left TK1 1 TK2 2 "tok alias" 3
1213 start: TK1 sr_conflict "tok alias" ;
1215 sr_conflict:
1216   TK2
1217   | TK2 "tok alias"
1218   ;
1222 void
1223 yyerror (char const *msg)
1225   fprintf (stderr, "%s\n", msg);
1229 yylex (void)
1231   static int const input[] = { 1, 2, 3, 0 };
1232   static int const *inputp = input;
1233   return *inputp++;
1237 main (void)
1239   return yyparse ();
1243 AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
1244 [[input.y:24.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
1246 AT_COMPILE([[input]])
1247 AT_PARSER_CHECK([[./input]])
1249 AT_CLEANUP
1253 ## ----------------------------------------------- ##
1254 ## Fix user actions without a trailing semicolon.  ##
1255 ## ----------------------------------------------- ##
1257 AT_SETUP([[Fix user actions without a trailing semicolon]])
1259 # This feature is undocumented, but we accidentally broke it in 2.3a, and there
1260 # was a complaint at:
1261 # <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
1263 AT_DATA([input.y],
1264 [[%%
1265 start: {asdffdsa} ;
1268 AT_BISON_CHECK([[-o input.c input.y]])
1269 AT_CHECK([[sed -n '/asdffdsa/s/^ *//p' input.c]], [[0]],
1270 [[{asdffdsa;}
1273 AT_CLEANUP