1 e# Executing Actions. -*- Autotest -*-
3 # Copyright (C) 2001-2013 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 AT_BANNER([[User Actions.]])
20 ## ------------------ ##
21 ## Mid-rule actions. ##
22 ## ------------------ ##
24 AT_SETUP([Mid-rule actions])
26 # Bison once forgot the mid-rule actions. It was because the action
27 # was attached to the host rule (the one with the mid-rule action),
28 # instead of being attached to the empty rule dedicated to this
31 AT_BISON_OPTION_PUSHDEFS
32 AT_DATA_GRAMMAR([[input.y]],
33 [[%define parse.error verbose
40 exp: { putchar ('0'); }
41 '1' { putchar ('1'); }
42 '2' { putchar ('2'); }
43 '3' { putchar ('3'); }
44 '4' { putchar ('4'); }
45 '5' { putchar ('5'); }
46 '6' { putchar ('6'); }
47 '7' { putchar ('7'); }
48 '8' { putchar ('8'); }
49 '9' { putchar ('9'); }
54 ]AT_YYLEX_DEFINE(["123456789"])[
57 AT_BISON_OPTION_POPDEFS
59 AT_BISON_CHECK([-d -v -o input.c input.y])
61 AT_PARSER_CHECK([./input], 0,
67 ## ----------------------- ##
68 ## Implicitly empty rule. ##
69 ## ----------------------- ##
71 AT_SETUP([Implicitly empty rule])
73 AT_DATA_GRAMMAR([[1.y]],
77 // A mid-rule action does not count as an empty rule.
81 AT_BISON_CHECK([-fcaret -Wempty-rule 1.y], [0], [],
82 [[1.y:11.17-18: warning: empty rule without %empty [-Wempty-rule]
87 AT_DATA_GRAMMAR([[2.y]],
95 AT_BISON_CHECK([-fcaret 2.y], [0], [],
96 [[2.y:11.17-18: warning: empty rule without %empty [-Wempty-rule]
99 2.y:13.17-18: warning: empty rule without %empty [-Wempty-rule]
104 AT_BISON_CHECK([-fcaret -Wno-empty-rule 2.y], [0])
108 ## ------------------------ ##
109 ## Invalid uses of %empty. ##
110 ## ------------------------ ##
112 AT_SETUP([Invalid uses of %empty])
114 AT_DATA_GRAMMAR([[one.y]],
121 AT_BISON_CHECK([-fcaret one.y], [1], [],
122 [[one.y:11.10-15: error: only one %empty allowed per rule
127 AT_DATA_GRAMMAR([[two.y]],
136 AT_BISON_CHECK([-fcaret two.y], [1], [],
137 [[two.y:11.7-12: error: %empty on non-empty rule
140 two.y:12.3-8: error: %empty on non-empty rule
143 two.y:13.3-8: error: %empty on non-empty rule
150 ## ---------------------- ##
151 ## Valid uses of %empty. ##
152 ## ---------------------- ##
154 AT_SETUP([Valid uses of %empty])
156 AT_BISON_OPTION_PUSHDEFS
157 AT_DATA_GRAMMAR([[input.y]],
173 AT_FULL_COMPILE([input])
174 AT_PARSER_CHECK([./input])
175 AT_BISON_OPTION_POPDEFS
178 ## ------------------ ##
179 ## Initial location. ##
180 ## ------------------ ##
182 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
183 # -----------------------------------------------------------------------
184 # Check that the initial location is correct.
185 m4_pushdef([AT_TEST],
186 [AT_SETUP([Initial location: $1 $2])
188 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
189 AT_DATA_GRAMMAR([[input.y]],
198 # include <stdlib.h> /* getenv */
203 exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << std::endl]],
204 [[LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
211 YYUSE(llocp);], [AT_SKEL_CC_IF([
221 p.set_debug_level (!!getenv("YYDEBUG"));
222 return p.parse ();]], [[
223 yydebug = !!getenv("YYDEBUG");
224 return !!yyparse (]AT_PARAM_IF([0])[);]])[
228 AT_FULL_COMPILE([input])
229 AT_PARSER_CHECK([./input], 1, [],
230 [m4_default([$4], [1.1])
231 m4_default([$4], [1.1])[: syntax error
233 AT_BISON_OPTION_POPDEFS
237 ## FIXME: test Java, and iterate over skeletons.
239 AT_TEST([yacc.c], [%define api.pure full])
240 AT_TEST([yacc.c], [%define api.pure %parse-param { int x }])
241 AT_TEST([yacc.c], [%define api.push-pull both])
242 AT_TEST([yacc.c], [%define api.push-pull both %define api.pure full])
244 AT_TEST([glr.c], [%define api.pure])
248 ## A very different test, based on PostgreSQL's implementation of the
250 ## http://lists.gnu.org/archive/html/bug-bison/2012-11/msg00023.html
252 ## Weirdly enough, to trigger the warning with GCC 4.7, we must not
253 ## use fprintf, so run the test twice: once to check the warning
254 ## (absence thereof), and another time to check the value.
255 AT_TEST([yacc.c], [%define api.pure full],
258 # define LOCATION_PRINT(Stream, Loc) \
260 # define YYLLOC_DEFAULT(Current, Rhs, N) \
261 (Current) = ((Rhs)[N ? 1 : 0])
266 AT_TEST([yacc.c], [%define api.pure full],
269 # define LOCATION_PRINT(Stream, Loc) \
270 fprintf ((Stream), "%d", (Loc))
271 # define YYLLOC_DEFAULT(Current, Rhs, N) \
272 (Current) = ((Rhs)[N ? 1 : 0])
282 ## ---------------- ##
283 ## Location Print. ##
284 ## ---------------- ##
286 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
287 # -----------------------------------------------------------------------
288 # Check that the initial location is correct.
289 m4_pushdef([AT_TEST],
290 [AT_SETUP([Location print: $1 $2])
292 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
293 AT_DATA_GRAMMAR([[input.y]],
314 ]AT_GLR_CC_IF([loc.initialize();])[
315 #define TEST(L1, C1, L2, C2) \
316 loc.]AT_FIRST_LINE[ = L1; \
317 loc.]AT_FIRST_COLUMN[ = C1; \
318 loc.]AT_LAST_LINE[ = L2; \
319 loc.]AT_LAST_COLUMN[ = C2; \
320 ]AT_SKEL_CC_IF([std::cout << loc],
321 [LOCATION_PRINT(stdout, loc)])[;\
335 AT_FULL_COMPILE([input])
336 AT_PARSER_CHECK([./input], 0,
344 AT_BISON_OPTION_POPDEFS
348 ## FIXME: test Java, and iterate over skeletons.
358 ## ---------------- ##
359 ## Exotic Dollars. ##
360 ## ---------------- ##
362 AT_SETUP([Exotic Dollars])
364 AT_BISON_OPTION_PUSHDEFS
365 AT_DATA_GRAMMAR([[input.y]],
366 [[%define parse.error verbose
379 %type <val> a_1 a_2 a_5
380 sum_of_the_five_previous_values
383 exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
384 sum_of_the_five_previous_values
386 USE (($1, $2, $<foo>3, $<foo>4, $5));
394 sum_of_the_five_previous_values:
396 $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4;
406 AT_BISON_CHECK([-d -v -o input.c input.y], 0)
408 AT_PARSER_CHECK([./input], 0,
412 # Make sure that fields after $n or $-n are parsed correctly. At one
413 # point while implementing dashes in symbol names, we were dropping
415 AT_DATA_GRAMMAR([[input.y]],
420 typedef struct { int val; } stype;
421 # define YYSTYPE stype
425 start: one two { $$.val = $1.val + $2.val; } sum ;
426 one: { $$.val = 1; } ;
427 two: { $$.val = 2; } ;
428 sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ;
436 AT_FULL_COMPILE([input])
437 AT_PARSER_CHECK([[./input]], [[0]],
441 AT_BISON_OPTION_POPDEFS
446 ## -------------------------- ##
447 ## Printers and Destructors. ##
448 ## -------------------------- ##
450 # _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4,
451 # BISON-DIRECTIVE, UNION-FLAG)
452 # -------------------------------------------------------------
453 m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
454 [# Make sure complex $n work.
455 m4_if([$1$2$3$4], $[1]$[2]$[3]$[4], [],
456 [m4_fatal([$0: Invalid arguments: $@])])dnl
458 # Be sure to pass all the %directives to this macro to have correct
459 # helping macros. So don't put any directly in the Bison file.
460 AT_BISON_OPTION_PUSHDEFS([$5])
461 AT_DATA_GRAMMAR([[input.y]],
468 #define YYINITDEPTH 10
469 #define YYMAXDEPTH 10
470 #define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
471 [(Location).first_line, (Location).last_line])[
473 /* Display the symbol type Symbol. */
474 #define V(Symbol, Value, Location, Sep) \
475 fprintf (stderr, #Symbol " (%d@%d-%d)" Sep, Value, RANGE(Location))
479 ]m4_ifval([$6], [%union
483 AT_LALR1_CC_IF([%define global_tokens_and_yystype])
484 m4_ifval([$6], [[%code provides {]], [[%code {]])
485 AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
487 ]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
490 ]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input END])[
492 /* FIXME: This %printer isn't actually tested. */
495 ]AT_LALR1_CC_IF([debug_stream () << $$;],
496 [fprintf (yyoutput, "%d", $$)])[;
498 input line thing 'x' 'y'
501 { fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
505 { fprintf (stderr, "Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
509 { fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
513 { fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
517 { fprintf (stderr, "Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
522 { fprintf (stderr, "Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
527 This grammar is made to exercise error recovery.
528 "Lines" starting with '(' support error recovery, with
529 ')' as synchronizing token. Lines starting with 'x' can never
530 be recovered from if in error.
537 V(input, $$, @$, ": /* Nothing */\n");
539 | line input /* Right recursive to load the stack so that popping at
540 END can be exercised. */
543 V(input, $$, @$, ": ");
544 V(line, $1, @1, " ");
545 V(input, $2, @2, "\n");
550 thing thing thing ';'
553 V(line, $$, @$, ": ");
554 V(thing, $1, @1, " ");
555 V(thing, $2, @2, " ");
556 V(thing, $3, @3, " ");
559 | '(' thing thing ')'
562 V(line, $$, @$, ": ");
564 V(thing, $2, @2, " ");
565 V(thing, $3, @3, " ");
566 V(')', $4, @4, "\n");
571 V(line, $$, @$, ": ");
573 V(thing, $2, @2, " ");
574 V(')', $3, @3, "\n");
579 V(line, $$, @$, ": ");
581 fprintf (stderr, "error (@%d-%d) ", RANGE(@2));
582 V(')', $3, @3, "\n");
590 V(thing, $$, @$, ": ");
591 V('x', $1, @1, "\n");
595 /* Alias to ARGV[1]. */
596 const char *source = YY_NULL;
603 static unsigned int counter = 0;
605 int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
606 /* As in BASIC, line numbers go from 10 to 10. */
607 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
608 ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
609 assert (0 <= c && c <= strlen (source));
611 fprintf (stderr, "sending: '%c'", source[c]);
613 fprintf (stderr, "sending: END");
614 fprintf (stderr, " (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
618 [static bool yydebug;
623 parser.set_debug_level (yydebug);
624 return parser.parse ();
629 main (int argc, const char *argv[])
632 yydebug = !!getenv ("YYDEBUG");
638 case 0: fprintf (stderr, "Successful parse.\n"); break;
639 case 1: fprintf (stderr, "Parsing FAILED.\n"); break;
640 default: fprintf (stderr, "Parsing FAILED (status %d).\n", status); break;
646 AT_FULL_COMPILE([input])
649 # Check the location of "empty"
650 # -----------------------------
651 # I.e., epsilon-reductions, as in "(x)" which ends by reducing
652 # an empty "line" nterm.
653 # FIXME: This location is not satisfying. Depend on the lookahead?
654 AT_PARSER_CHECK([./input '(x)'], 0, [],
655 [[sending: '(' (0@0-9)
656 sending: 'x' (1@10-19)
657 thing (1@10-19): 'x' (1@10-19)
658 sending: ')' (2@20-29)
659 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
660 sending: END (3@30-39)
661 input (0@29-29): /* Nothing */
662 input (2@0-29): line (0@0-29) input (0@29-29)
663 Freeing token END (3@30-39)
664 Freeing nterm input (2@0-29)
669 # Check locations in error recovery
670 # ---------------------------------
671 # '(y)' is an error, but can be recovered from. But what's the location
672 # of the error itself ('y'), and of the resulting reduction ('(error)').
673 AT_PARSER_CHECK([./input '(y)'], 0, [],
674 [[sending: '(' (0@0-9)
675 sending: 'y' (1@10-19)
676 10.10-19.18: syntax error, unexpected 'y', expecting 'x'
677 Freeing token 'y' (1@10-19)
678 sending: ')' (2@20-29)
679 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
680 sending: END (3@30-39)
681 input (0@29-29): /* Nothing */
682 input (2@0-29): line (-1@0-29) input (0@29-29)
683 Freeing token END (3@30-39)
684 Freeing nterm input (2@0-29)
689 # Syntax errors caught by the parser
690 # ----------------------------------
691 # Exercise the discarding of stack top and input until 'error'
694 # '(', 'x', 'x', 'x', 'x', 'x', ')',
696 # Load the stack and provoke an error that cannot be caught by the
697 # grammar, to check that the stack is cleared. And make sure the
698 # lookahead is freed.
703 AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1, [],
704 [[sending: '(' (0@0-9)
705 sending: 'x' (1@10-19)
706 thing (1@10-19): 'x' (1@10-19)
707 sending: 'x' (2@20-29)
708 thing (2@20-29): 'x' (2@20-29)
709 sending: 'x' (3@30-39)
710 30.30-39.38: syntax error, unexpected 'x', expecting ')'
711 Freeing nterm thing (2@20-29)
712 Freeing nterm thing (1@10-19)
713 Freeing token 'x' (3@30-39)
714 sending: 'x' (4@40-49)
715 Freeing token 'x' (4@40-49)
716 sending: 'x' (5@50-59)
717 Freeing token 'x' (5@50-59)
718 sending: ')' (6@60-69)
719 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
720 sending: '(' (7@70-79)
721 sending: 'x' (8@80-89)
722 thing (8@80-89): 'x' (8@80-89)
723 sending: ')' (9@90-99)
724 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
725 sending: '(' (10@100-109)
726 sending: 'x' (11@110-119)
727 thing (11@110-119): 'x' (11@110-119)
728 sending: ')' (12@120-129)
729 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
730 sending: 'y' (13@130-139)
731 input (0@129-129): /* Nothing */
732 input (2@100-129): line (10@100-129) input (0@129-129)
733 input (2@70-129): line (7@70-99) input (2@100-129)
734 input (2@0-129): line (-1@0-69) input (2@70-129)
735 130.130-139.138: syntax error, unexpected 'y', expecting END
736 Freeing nterm input (2@0-129)
737 Freeing token 'y' (13@130-139)
742 # Syntax error caught by the parser where lookahead = END
743 # --------------------------------------------------------
744 # Load the stack and provoke an error that cannot be caught by the
745 # grammar, to check that the stack is cleared. And make sure the
746 # lookahead is freed.
751 AT_PARSER_CHECK([./input '(x)(x)x'], 1, [],
752 [[sending: '(' (0@0-9)
753 sending: 'x' (1@10-19)
754 thing (1@10-19): 'x' (1@10-19)
755 sending: ')' (2@20-29)
756 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
757 sending: '(' (3@30-39)
758 sending: 'x' (4@40-49)
759 thing (4@40-49): 'x' (4@40-49)
760 sending: ')' (5@50-59)
761 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
762 sending: 'x' (6@60-69)
763 thing (6@60-69): 'x' (6@60-69)
764 sending: END (7@70-79)
765 70.70-79.78: syntax error, unexpected END, expecting 'x'
766 Freeing nterm thing (6@60-69)
767 Freeing nterm line (3@30-59)
768 Freeing nterm line (0@0-29)
769 Freeing token END (7@70-79)
774 # Check destruction upon stack overflow
775 # -------------------------------------
776 # Upon stack overflow, all symbols on the stack should be destroyed.
777 # Only check for yacc.c.
779 AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2, [],
780 [[sending: '(' (0@0-9)
781 sending: 'x' (1@10-19)
782 thing (1@10-19): 'x' (1@10-19)
783 sending: ')' (2@20-29)
784 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
785 sending: '(' (3@30-39)
786 sending: 'x' (4@40-49)
787 thing (4@40-49): 'x' (4@40-49)
788 sending: ')' (5@50-59)
789 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
790 sending: '(' (6@60-69)
791 sending: 'x' (7@70-79)
792 thing (7@70-79): 'x' (7@70-79)
793 sending: ')' (8@80-89)
794 line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
795 sending: '(' (9@90-99)
796 sending: 'x' (10@100-109)
797 thing (10@100-109): 'x' (10@100-109)
798 sending: ')' (11@110-119)
799 line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
800 sending: '(' (12@120-129)
801 sending: 'x' (13@130-139)
802 thing (13@130-139): 'x' (13@130-139)
803 sending: ')' (14@140-149)
804 line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
805 sending: '(' (15@150-159)
806 sending: 'x' (16@160-169)
807 thing (16@160-169): 'x' (16@160-169)
808 sending: ')' (17@170-179)
809 line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
810 sending: '(' (18@180-189)
811 sending: 'x' (19@190-199)
812 thing (19@190-199): 'x' (19@190-199)
813 sending: ')' (20@200-209)
814 200.200-209.208: memory exhausted
815 Freeing nterm thing (19@190-199)
816 Freeing nterm line (15@150-179)
817 Freeing nterm line (12@120-149)
818 Freeing nterm line (9@90-119)
819 Freeing nterm line (6@60-89)
820 Freeing nterm line (3@30-59)
821 Freeing nterm line (0@0-29)
822 Parsing FAILED (status 2).
826 AT_BISON_OPTION_POPDEFS
827 ])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
830 # AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
831 # ---------------------------------------------------------------------------
832 m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR],
833 [AT_SETUP([Printers and Destructors$2]m4_ifval([$1], [[: $1]]))
836 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4],
837 [%define parse.error verbose
847 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
848 AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union])
850 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"])
851 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union])
853 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
854 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
858 ## ----------------------------------------- ##
859 ## Default tagless %printer and %destructor. ##
860 ## ----------------------------------------- ##
862 # Check that the right %printer and %destructor are called, that they're not
863 # called for $end, and that $$ and @$ work correctly.
865 AT_SETUP([Default tagless %printer and %destructor])
866 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
867 AT_DATA_GRAMMAR([[input.y]],
868 [[%define parse.error verbose
879 fprintf (yyoutput, "<*> printer should not be called.\n");
883 fprintf (yyoutput, "<> printer for '%c' @ %d", $$, @$.first_column);
886 fprintf (stdout, "<> destructor for '%c' @ %d.\n", $$, @$.first_column);
890 fprintf (yyoutput, "'b'/'c' printer for '%c' @ %d", $$, @$.first_column);
893 fprintf (stdout, "'b'/'c' destructor for '%c' @ %d.\n", $$, @$.first_column);
897 fprintf (yyoutput, "<*> destructor should not be called.\n");
902 start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
906 ]AT_YYLEX_DEFINE(["abcd"], [[yylval = res]])[
910 AT_BISON_CHECK([-o input.c input.y], [], [],
911 [[input.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
912 input.y:30.3-5: warning: useless %printer for type <*> [-Wother]
915 AT_PARSER_CHECK([./input --debug], 1,
916 [[<> destructor for 'd' @ 4.
917 'b'/'c' destructor for 'c' @ 3.
918 'b'/'c' destructor for 'b' @ 2.
919 <> destructor for 'a' @ 1.
923 Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1)
924 Shifting token 'a' (1.1: <> printer for 'a' @ 1)
926 Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
927 Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
929 Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
930 Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
932 Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4)
933 Shifting token 'd' (1.4: <> printer for 'd' @ 4)
935 Reading a token: Now at end of input.
936 1.5: syntax error, unexpected $end, expecting 'e'
937 Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
939 Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
941 Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
943 Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
945 Cleanup: discarding lookahead token $end (1.5: )
949 AT_BISON_OPTION_POPDEFS
954 ## ------------------------------------------------------ ##
955 ## Default tagged and per-type %printer and %destructor. ##
956 ## ------------------------------------------------------ ##
958 AT_SETUP([Default tagged and per-type %printer and %destructor])
959 AT_BISON_OPTION_PUSHDEFS([%debug])
960 AT_DATA_GRAMMAR([[input.y]],
961 [[%define parse.error verbose
971 fprintf (yyoutput, "<> printer should not be called.\n");
974 %union { int field0; int field1; int field2; }
975 %type <field0> start 'a' 'g'
979 fprintf (yyoutput, "<*>/<field2>/e printer");
982 fprintf (stdout, "<*>/<field2>/e destructor.\n");
986 %printer { fprintf (yyoutput, "<field1> printer"); } <field1>
987 %destructor { fprintf (stdout, "<field1> destructor.\n"); } <field1>
990 %printer { fprintf (yyoutput, "'c' printer"); } 'c'
991 %destructor { fprintf (stdout, "'c' destructor.\n"); } 'c'
994 %printer { fprintf (yyoutput, "'d' printer"); } 'd'
995 %destructor { fprintf (stdout, "'d' destructor.\n"); } 'd'
998 fprintf (yyoutput, "<> destructor should not be called.\n");
1004 'a' 'b' 'c' 'd' 'e' 'f' 'g'
1006 USE(($1, $2, $3, $4, $5, $6, $7));
1013 ]AT_YYLEX_DEFINE(["abcdef"])[
1017 AT_BISON_CHECK([-o input.c input.y], [], [],
1018 [[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
1019 input.y:22.3-4: warning: useless %printer for type <> [-Wother]
1022 AT_PARSER_CHECK([./input --debug], 1,
1023 [[<*>/<field2>/e destructor.
1024 <*>/<field2>/e destructor.
1027 <field1> destructor.
1028 <*>/<field2>/e destructor.
1032 Reading a token: Next token is token 'a' (<*>/<field2>/e printer)
1033 Shifting token 'a' (<*>/<field2>/e printer)
1035 Reading a token: Next token is token 'b' (<field1> printer)
1036 Shifting token 'b' (<field1> printer)
1038 Reading a token: Next token is token 'c' ('c' printer)
1039 Shifting token 'c' ('c' printer)
1041 Reading a token: Next token is token 'd' ('d' printer)
1042 Shifting token 'd' ('d' printer)
1044 Reading a token: Next token is token 'e' (<*>/<field2>/e printer)
1045 Shifting token 'e' (<*>/<field2>/e printer)
1047 Reading a token: Next token is token 'f' (<*>/<field2>/e printer)
1048 Shifting token 'f' (<*>/<field2>/e printer)
1050 Reading a token: Now at end of input.
1051 syntax error, unexpected $end, expecting 'g'
1052 Error: popping token 'f' (<*>/<field2>/e printer)
1053 Stack now 0 1 3 5 6 7
1054 Error: popping token 'e' (<*>/<field2>/e printer)
1056 Error: popping token 'd' ('d' printer)
1058 Error: popping token 'c' ('c' printer)
1060 Error: popping token 'b' (<field1> printer)
1062 Error: popping token 'a' (<*>/<field2>/e printer)
1064 Cleanup: discarding lookahead token $end ()
1068 AT_BISON_OPTION_POPDEFS
1073 ## ------------------------------------------------------------- ##
1074 ## Default %printer and %destructor for user-defined end token. ##
1075 ## ------------------------------------------------------------- ##
1077 AT_SETUP([Default %printer and %destructor for user-defined end token])
1081 m4_pushdef([AT_TEST],
1083 [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
1084 [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
1086 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
1087 AT_DATA_GRAMMAR([[input]]$1[[.y]],
1088 [[%define parse.error verbose
1093 ]AT_YYERROR_DECLARE[
1099 fprintf (yyoutput, "<]]not_kind[[> destructor should not be called.\n");
1104 fprintf (yyoutput, "<]]kind[[> for '%c' @ %d", $$, @$.first_column);
1107 fprintf (stdout, "<]]kind[[> for '%c' @ %d.\n", $$, @$.first_column);
1111 fprintf (yyoutput, "<]]not_kind[[> printer should not be called.\n");
1116 [[[%union { char tag; }
1117 %type <tag> start END]]])[[
1121 start: { $$ = 'S'; } ;
1124 #include <stdlib.h> /* abort */
1131 yylval]]m4_if($1, 0,, [[[.tag]]])[[ = 'E';
1132 yylloc.first_line = yylloc.last_line = 1;
1133 yylloc.first_column = yylloc.last_column = 1;
1139 AT_BISON_OPTION_POPDEFS
1141 AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
1143 [[input0.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
1144 input0.y:30.3-5: warning: useless %printer for type <*> [-Wother]
1146 [[input1.y:30.3-4: warning: useless %destructor for type <> [-Wother]
1147 input1.y:30.3-4: warning: useless %printer for type <> [-Wother]
1150 AT_COMPILE([input$1])
1152 AT_PARSER_CHECK([./input$1 --debug], 0,
1153 [[<]]kind[[> for 'E' @ 1.
1154 <]]kind[[> for 'S' @ 1.
1158 Reducing stack by rule 1 (line 49):
1159 -> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
1162 Reading a token: Now at end of input.
1163 Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
1166 Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
1167 Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
1171 m4_popdef([not_kind])
1177 m4_popdef([AT_TEST])
1183 ## ------------------------------------------------------------------ ##
1184 ## Default %printer and %destructor are not for error or $undefined. ##
1185 ## ------------------------------------------------------------------ ##
1187 AT_SETUP([Default %printer and %destructor are not for error or $undefined])
1189 # If Bison were to apply the default %printer and %destructor to the error
1190 # token or to $undefined:
1191 # - For the error token:
1192 # - It would generate warnings for unused $n.
1193 # - It would invoke the %printer and %destructor on the error token's
1194 # semantic value, which would be initialized from the lookahead, which
1195 # would be destroyed separately.
1196 # - For $undefined, who knows what the semantic value would be.
1197 AT_BISON_OPTION_PUSHDEFS([%debug])
1198 AT_DATA_GRAMMAR([[input.y]],
1203 # include <stdlib.h>
1204 ]AT_YYERROR_DECLARE[
1210 fprintf (yyoutput, "'%c'", $$);
1213 fprintf (stderr, "DESTROY '%c'\n", $$);
1220 /* In order to reveal the problems that this bug caused during parsing, add
1222 | 'a' error 'b' 'c' { USE(($1, $3, $4)); $$ = 'S'; }
1227 ]AT_YYLEX_DEFINE(["abd"], [yylval = res])[
1230 AT_BISON_OPTION_POPDEFS
1232 AT_BISON_CHECK([-o input.c input.y], [], [],
1233 [[input.y:23.6-8: warning: useless %destructor for type <*> [-Wother]
1234 input.y:23.6-8: warning: useless %printer for type <*> [-Wother]
1237 AT_PARSER_CHECK([./input --debug], [1], [],
1240 Reading a token: Next token is token 'a' ('a')
1241 Shifting token 'a' ('a')
1243 Reading a token: Next token is token 'b' ('b')
1245 Shifting token error ()
1247 Next token is token 'b' ('b')
1248 Shifting token 'b' ('b')
1250 Reading a token: Next token is token $undefined ()
1251 Error: popping token 'b' ('b')
1254 Error: popping token error ()
1256 Shifting token error ()
1258 Next token is token $undefined ()
1259 Error: discarding token $undefined ()
1260 Error: popping token error ()
1262 Shifting token error ()
1264 Reading a token: Now at end of input.
1265 Cleanup: discarding lookahead token $end ()
1267 Cleanup: popping token error ()
1268 Cleanup: popping token 'a' ('a')
1276 ## ------------------------------------------------------ ##
1277 ## Default %printer and %destructor are not for $accept. ##
1278 ## ------------------------------------------------------ ##
1280 AT_SETUP([Default %printer and %destructor are not for $accept])
1282 # If YYSTYPE is a union and Bison were to apply the default %printer and
1283 # %destructor to $accept:
1284 # - The %printer and %destructor code generated for $accept would always be
1285 # dead code because $accept is currently never shifted onto the stack.
1286 # - $$ for $accept would always be of type YYSTYPE because it's not possible
1287 # to declare '%type <field> $accept'. (Also true for $undefined.)
1288 # - Thus, the compiler might complain that the user code assumes the wrong
1289 # type for $$ since the code might assume the type associated with a
1290 # specific union field, which is especially reasonable in C++ since that
1291 # type may be a base type. This test case checks for this problem. (Also
1292 # true for $undefined and the error token, so there are three warnings for
1293 # %printer and three for %destructor.)
1295 AT_BISON_OPTION_PUSHDEFS([%debug])
1296 AT_DATA_GRAMMAR([[input.y]],
1297 [[%debug /* So that %printer is actually compiled. */
1301 # include <stdlib.h>
1302 ]AT_YYERROR_DECLARE[
1309 fprintf (yyoutput, "'%c'", chr);
1313 fprintf (stderr, "DESTROY '%c'\n", chr);
1316 %union { char chr; }
1321 start: { USE($$); } ;
1328 AT_BISON_OPTION_POPDEFS
1330 AT_BISON_CHECK([-o input.c input.y], [], [],
1331 [[input.y:24.3-4: warning: useless %destructor for type <> [-Wother]
1332 input.y:24.3-4: warning: useless %printer for type <> [-Wother]
1340 ## ------------------------------------------------------ ##
1341 ## Default %printer and %destructor for mid-rule values. ##
1342 ## ------------------------------------------------------ ##
1344 AT_SETUP([Default %printer and %destructor for mid-rule values])
1346 AT_BISON_OPTION_PUSHDEFS([%debug])
1347 AT_DATA_GRAMMAR([[input.y]],
1348 [[%debug /* So that %printer is actually compiled. */
1351 ]AT_YYERROR_DECLARE[
1354 # define YYLTYPE int
1355 # define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
1356 # define LOCATION_PRINT(File, Loc)
1359 %printer { fprintf (yyoutput, "%d", @$); } <>
1360 %destructor { fprintf (stderr, "DESTROY %d\n", @$); } <>
1361 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1362 %destructor { fprintf (yyoutput, "<*> destructor should not be called"); } <*>
1367 { @$ = 1; } // Not set or used.
1368 { USE ($$); @$ = 2; } // Both set and used.
1369 { USE ($$); @$ = 3; } // Only set.
1370 { @$ = 4; } // Only used.
1372 { USE (($$, $2, $4, $5)); @$ = 0; }
1380 AT_BISON_OPTION_POPDEFS
1382 AT_BISON_CHECK([-o input.c input.y], 0,,
1383 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1384 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1385 input.y:33.3-23: warning: unset value: $$ [-Wother]
1386 input.y:32.3-23: warning: unused value: $3 [-Wother]
1389 AT_BISON_CHECK([-fcaret -o input.c input.y], 0,,
1390 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1391 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1393 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1394 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1396 input.y:33.3-23: warning: unset value: $$ [-Wother]
1397 { @$ = 4; } // Only used.
1398 ^^^^^^^^^^^^^^^^^^^^^
1399 input.y:32.3-23: warning: unused value: $3 [-Wother]
1400 { USE ($$); @$ = 3; } // Only set.
1401 ^^^^^^^^^^^^^^^^^^^^^
1405 AT_PARSER_CHECK([./input --debug], 1,,
1408 Reducing stack by rule 1 (line 30):
1409 -> $$ = nterm $@1 (: )
1412 Reducing stack by rule 2 (line 31):
1413 -> $$ = nterm @2 (: 2)
1416 Reducing stack by rule 3 (line 32):
1417 -> $$ = nterm @3 (: 3)
1420 Reducing stack by rule 4 (line 33):
1421 -> $$ = nterm @4 (: 4)
1424 Reading a token: Now at end of input.
1426 Error: popping nterm @4 (: 4)
1429 Error: popping nterm @3 (: 3)
1432 Error: popping nterm @2 (: 2)
1435 Error: popping nterm $@1 (: )
1437 Cleanup: discarding lookahead token $end (: )
1444 ## ----------------------- ##
1445 ## @$ implies %locations. ##
1446 ## ----------------------- ##
1448 # Bison once forgot to check for @$ in actions other than semantic actions.
1450 # AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE)
1451 # -------------------------------------------
1452 m4_define([AT_CHECK_ACTION_LOCATIONS],
1453 [AT_SETUP([[@$ in ]$1[ implies %locations]])
1454 AT_BISON_OPTION_PUSHDEFS([%debug])
1455 AT_DATA_GRAMMAR([[input.y]],
1458 ]AT_YYERROR_DECLARE[
1465 fprintf (stderr, "%d\n", @$.first_line);
1466 } ]m4_if($1, [%initial-action], [], [[start]])[
1484 AT_BISON_CHECK([[-o input.c input.y]])
1485 AT_COMPILE([[input]])
1486 AT_BISON_OPTION_POPDEFS
1489 AT_CHECK_ACTION_LOCATIONS([[%initial-action]])
1490 AT_CHECK_ACTION_LOCATIONS([[%destructor]])
1491 AT_CHECK_ACTION_LOCATIONS([[%printer]])
1494 ## ------------------------- ##
1495 ## Qualified $$ in actions. ##
1496 ## ------------------------- ##
1498 # Check that we can use qualified $$ (v.g., $<type>$) not only in rule
1499 # actions, but also where $$ is valid: %destructor/%printer and
1502 # FIXME: Not actually checking %destructor, but it's the same code as
1505 # To do that, use a semantic value that has two fields (sem_type),
1506 # declare symbols to have only one of these types (INT, float), and
1507 # use $<type>$ to get the other one. Including for symbols that are
1508 # not typed (UNTYPED).
1510 m4_pushdef([AT_TEST],
1511 [AT_SETUP([[Qualified $$ in actions: $1]])
1513 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %debug])
1515 AT_DATA_GRAMMAR([[input.y]],
1520 typedef struct sem_type
1526 # define YYSTYPE sem_type
1529 # include <iostream>
1531 report (std::ostream& yyo, int ival, float fval)
1533 yyo << "ival: " << ival << ", fval: " << fval;
1538 report (FILE* yyo, int ival, float fval)
1540 fprintf (yyo, "ival: %d, fval: %1.1f", ival, fval);
1547 ]AT_YYERROR_DECLARE[
1554 %printer { report (yyo, $$, $<fval>$); } <ival>;
1555 %printer { report (yyo, $<ival>$, $$ ); } <fval>;
1556 %printer { report (yyo, $<ival>$, $<fval>$); } <>;
1567 $$ = $<fval>1 + $<fval>2;
1568 $<ival>$ = $<ival>1 + $][2;
1572 ]AT_YYLEX_DEFINE(AT_SKEL_CC_IF([[{yy::parser::token::UNTYPED,
1573 yy::parser::token::INT,
1575 [[{UNTYPED, INT, EOF}]]),
1576 [AT_VAL.ival = toknum * 10; AT_VAL.fval = toknum / 10.0;])[
1580 AT_FULL_COMPILE([[input]])
1581 AT_PARSER_CHECK([./input --debug], 0, [], [stderr])
1582 # Don't be too picky on the traces, GLR is not exactly the same. Keep
1583 # only the lines from the printer.
1584 AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
1585 [[Reading a token: Next token is token UNTYPED (ival: 10, fval: 0.1)
1586 Shifting token UNTYPED (ival: 10, fval: 0.1)
1587 Reading a token: Next token is token INT (ival: 20, fval: 0.2)
1588 Shifting token INT (ival: 20, fval: 0.2)
1589 $][1 = token UNTYPED (ival: 10, fval: 0.1)
1590 $][2 = token INT (ival: 20, fval: 0.2)
1591 -> $$ = nterm float (ival: 30, fval: 0.3)
1592 Cleanup: popping nterm float (ival: 30, fval: 0.3)
1595 AT_BISON_OPTION_POPDEFS
1605 m4_popdef([AT_TEST])
1607 ## ----------------------------------------------- ##
1608 ## Fix user actions without a trailing semicolon. ##
1609 ## ----------------------------------------------- ##
1611 AT_SETUP([[Fix user actions without a trailing semicolon]])
1613 # This feature is undocumented, but we accidentally broke it in 2.3a,
1614 # and there was a complaint at:
1615 # <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
1616 AT_BISON_OPTION_PUSHDEFS
1619 start: test2 test1 test0 testc;
1622 : 'a' { semi; /* TEST:N:2 */ }
1623 | 'b' { if (0) {no_semi} /* TEST:N:2 */ }
1624 | 'c' { if (0) {semi;} /* TEST:N:2 */ }
1625 | 'd' { semi; no_semi /* TEST:Y:2 */ }
1626 | 'e' { semi(); no_semi() /* TEST:Y:2 */ }
1627 | 'f' { semi[]; no_semi[] /* TEST:Y:2 */ }
1628 | 'g' { semi++; no_semi++ /* TEST:Y:2 */ }
1629 | 'h' { {no_semi} no_semi /* TEST:Y:2 */ }
1630 | 'i' { {semi;} no_semi /* TEST:Y:2 */ }
1633 : 'a' { semi; // TEST:N:1 ;
1634 } | 'b' { if (0) {no_semi} // TEST:N:1 ;
1635 } | 'c' { if (0) {semi;} // TEST:N:1 ;
1636 } | 'd' { semi; no_semi // TEST:Y:1 ;
1637 } | 'e' { semi(); no_semi() // TEST:Y:1 ;
1638 } | 'f' { semi[]; no_semi[] // TEST:Y:1 ;
1639 } | 'g' { semi++; no_semi++ // TEST:Y:1 ;
1640 } | 'h' { {no_semi} no_semi // TEST:Y:1 ;
1641 } | 'i' { {semi;} no_semi // TEST:Y:1 ;
1644 : 'a' { semi; // TEST:N:1 {}
1645 } | 'b' { if (0) {no_semi} // TEST:N:1 {}
1646 } | 'c' { if (0) {semi;} // TEST:N:1 {}
1647 } | 'd' { semi; no_semi // TEST:Y:1 {}
1648 } | 'e' { semi(); no_semi() // TEST:Y:1 {}
1649 } | 'f' { semi[]; no_semi[] // TEST:Y:1 {}
1650 } | 'g' { semi++; no_semi++ // TEST:Y:1 {}
1651 } | 'h' { {no_semi} no_semi // TEST:Y:1 {}
1652 } | 'i' { {semi;} no_semi // TEST:Y:1 {}
1657 #define TEST_MACRO_N \
1658 []"broken\" $ @ $$ @$ [];\
1662 #define TEST_MACRO_N \
1663 []"broken\" $ @ $$ @$ [];\
1666 AT_BISON_OPTION_POPDEFS
1668 AT_BISON_CHECK([[-o input.c input.y]], [0], [],
1669 [[input.y:8.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1670 input.y:8.48: future versions of Bison will not add the ';'
1671 input.y:9.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1672 input.y:9.48: future versions of Bison will not add the ';'
1673 input.y:10.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1674 input.y:10.48: future versions of Bison will not add the ';'
1675 input.y:11.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1676 input.y:11.48: future versions of Bison will not add the ';'
1677 input.y:12.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1678 input.y:12.48: future versions of Bison will not add the ';'
1679 input.y:13.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1680 input.y:13.48: future versions of Bison will not add the ';'
1681 input.y:20.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1682 input.y:20.1: future versions of Bison will not add the ';'
1683 input.y:21.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1684 input.y:21.1: future versions of Bison will not add the ';'
1685 input.y:22.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1686 input.y:22.1: future versions of Bison will not add the ';'
1687 input.y:23.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1688 input.y:23.1: future versions of Bison will not add the ';'
1689 input.y:24.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1690 input.y:24.1: future versions of Bison will not add the ';'
1691 input.y:25.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1692 input.y:25.1: future versions of Bison will not add the ';'
1693 input.y:31.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1694 input.y:31.1: future versions of Bison will not add the ';'
1695 input.y:32.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1696 input.y:32.1: future versions of Bison will not add the ';'
1697 input.y:33.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1698 input.y:33.1: future versions of Bison will not add the ';'
1699 input.y:34.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1700 input.y:34.1: future versions of Bison will not add the ';'
1701 input.y:35.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1702 input.y:35.1: future versions of Bison will not add the ';'
1703 input.y:36.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1704 input.y:36.1: future versions of Bison will not add the ';'
1707 AT_MATCHES_CHECK([input.c], [[/\* TEST:N:2 \*/ \}$]], [[3]])
1708 AT_MATCHES_CHECK([input.c], [[/\* TEST:Y:2 \*/ ;\}$]], [[6]])
1709 AT_MATCHES_CHECK([input.c], [[// TEST:N:1 [;{}]*\n\}$]], [[6]])
1710 AT_MATCHES_CHECK([input.c], [[// TEST:Y:1 [;{}]*\n;\}$]], [[12]])
1711 AT_MATCHES_CHECK([input.c], [[#define TEST_MACRO_N \\\n\[\]"broken\\" \$ \@ \$\$ \@\$ \[\];\\\nstring;"\}]], [[2]])
1716 ## -------------------------------------------------- ##
1717 ## Destroying lookahead assigned by semantic action. ##
1718 ## -------------------------------------------------- ##
1720 AT_SETUP([[Destroying lookahead assigned by semantic action]])
1722 AT_BISON_OPTION_PUSHDEFS
1723 AT_DATA_GRAMMAR([input.y],
1728 ]AT_YYERROR_DECLARE[
1733 %destructor { fprintf (stderr, "'a' destructor\n"); } 'a'
1734 %destructor { fprintf (stderr, "'b' destructor\n"); } 'b'
1738 // In a previous version of Bison, yychar assigned by the semantic
1739 // action below was not translated into yytoken before the lookahead was
1740 // discarded and thus before its destructor (selected according to
1741 // yytoken) was called in order to return from yyparse. This would
1742 // happen even if YYACCEPT was performed in a later semantic action as
1743 // long as only consistent states with default reductions were visited
1744 // in between. However, we leave YYACCEPT in the same semantic action
1745 // for this test in order to show that skeletons cannot simply translate
1746 // immediately after every semantic action because a semantic action
1747 // that has set yychar might not always return normally. Instead,
1748 // skeletons must translate before every use of yytoken.
1749 start: 'a' accept { USE($1); } ;
1751 assert (yychar == YYEMPTY);
1758 ]AT_YYLEX_DEFINE(["a"])[
1761 AT_BISON_OPTION_POPDEFS
1762 AT_BISON_CHECK([[-o input.c input.y]])
1763 AT_COMPILE([[input]])
1764 AT_PARSER_CHECK([[./input]], [[0]], [],
1775 AT_SETUP([[YYBACKUP]])
1777 AT_BISON_OPTION_PUSHDEFS([%pure-parser %debug])
1779 AT_DATA_GRAMMAR([input.y],
1786 # include <stdlib.h>
1787 # include <assert.h>
1789 ]AT_YYERROR_DECLARE[
1798 'a' { printf ("a: %d\n", $1); }
1799 | 'b' { YYBACKUP('a', 123); }
1800 | 'c' 'd' { YYBACKUP('a', 456); }
1805 ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[
1808 AT_BISON_OPTION_POPDEFS
1810 AT_BISON_CHECK([[-o input.c input.y]])
1811 AT_COMPILE([[input]])
1812 AT_PARSER_CHECK([[./input]], [[0]],