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 ## Invalid uses of %empty. ##
69 ## ------------------------ ##
71 AT_SETUP([Invalid uses of %empty])
73 AT_DATA_GRAMMAR([[one.y]],
80 AT_BISON_CHECK([-fcaret one.y], [1], [],
81 [[one.y:11.10-15: error: only one %empty allowed per rule
86 AT_DATA_GRAMMAR([[two.y]],
95 AT_BISON_CHECK([-fcaret two.y], [1], [],
96 [[two.y:11.7-12: error: %empty on non-empty rule
99 two.y:12.3-8: error: %empty on non-empty rule
102 two.y:13.3-8: error: %empty on non-empty rule
109 ## ---------------------- ##
110 ## Valid uses of %empty. ##
111 ## ---------------------- ##
113 AT_SETUP([Valid uses of %empty])
115 AT_BISON_OPTION_PUSHDEFS
116 AT_DATA_GRAMMAR([[input.y]],
132 AT_FULL_COMPILE([input])
133 AT_PARSER_CHECK([./input])
134 AT_BISON_OPTION_POPDEFS
137 ## ------------------ ##
138 ## Initial location. ##
139 ## ------------------ ##
141 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
142 # -----------------------------------------------------------------------
143 # Check that the initial location is correct.
144 m4_pushdef([AT_TEST],
145 [AT_SETUP([Initial location: $1 $2])
147 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
148 AT_DATA_GRAMMAR([[input.y]],
157 # include <stdlib.h> /* getenv */
162 exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << std::endl]],
163 [[LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
170 YYUSE(llocp);], [AT_SKEL_CC_IF([
180 p.set_debug_level (!!getenv("YYDEBUG"));
181 return p.parse ();]], [[
182 yydebug = !!getenv("YYDEBUG");
183 return !!yyparse (]AT_PARAM_IF([0])[);]])[
187 AT_FULL_COMPILE([input])
188 AT_PARSER_CHECK([./input], 1, [],
189 [m4_default([$4], [1.1])
190 m4_default([$4], [1.1])[: syntax error
192 AT_BISON_OPTION_POPDEFS
196 ## FIXME: test Java, and iterate over skeletons.
198 AT_TEST([yacc.c], [%define api.pure full])
199 AT_TEST([yacc.c], [%define api.pure %parse-param { int x }])
200 AT_TEST([yacc.c], [%define api.push-pull both])
201 AT_TEST([yacc.c], [%define api.push-pull both %define api.pure full])
203 AT_TEST([glr.c], [%define api.pure])
207 ## A very different test, based on PostgreSQL's implementation of the
209 ## http://lists.gnu.org/archive/html/bug-bison/2012-11/msg00023.html
211 ## Weirdly enough, to trigger the warning with GCC 4.7, we must not
212 ## use fprintf, so run the test twice: once to check the warning
213 ## (absence thereof), and another time to check the value.
214 AT_TEST([yacc.c], [%define api.pure full],
217 # define LOCATION_PRINT(Stream, Loc) \
219 # define YYLLOC_DEFAULT(Current, Rhs, N) \
220 (Current) = ((Rhs)[N ? 1 : 0])
225 AT_TEST([yacc.c], [%define api.pure full],
228 # define LOCATION_PRINT(Stream, Loc) \
229 fprintf ((Stream), "%d", (Loc))
230 # define YYLLOC_DEFAULT(Current, Rhs, N) \
231 (Current) = ((Rhs)[N ? 1 : 0])
241 ## ---------------- ##
242 ## Location Print. ##
243 ## ---------------- ##
245 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
246 # -----------------------------------------------------------------------
247 # Check that the initial location is correct.
248 m4_pushdef([AT_TEST],
249 [AT_SETUP([Location print: $1 $2])
251 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
252 AT_DATA_GRAMMAR([[input.y]],
273 ]AT_GLR_CC_IF([loc.initialize();])[
274 #define TEST(L1, C1, L2, C2) \
275 loc.]AT_FIRST_LINE[ = L1; \
276 loc.]AT_FIRST_COLUMN[ = C1; \
277 loc.]AT_LAST_LINE[ = L2; \
278 loc.]AT_LAST_COLUMN[ = C2; \
279 ]AT_SKEL_CC_IF([std::cout << loc],
280 [LOCATION_PRINT(stdout, loc)])[;\
294 AT_FULL_COMPILE([input])
295 AT_PARSER_CHECK([./input], 0,
303 AT_BISON_OPTION_POPDEFS
307 ## FIXME: test Java, and iterate over skeletons.
317 ## ---------------- ##
318 ## Exotic Dollars. ##
319 ## ---------------- ##
321 AT_SETUP([Exotic Dollars])
323 AT_BISON_OPTION_PUSHDEFS
324 AT_DATA_GRAMMAR([[input.y]],
325 [[%define parse.error verbose
338 %type <val> a_1 a_2 a_5
339 sum_of_the_five_previous_values
342 exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
343 sum_of_the_five_previous_values
345 USE (($1, $2, $<foo>3, $<foo>4, $5));
353 sum_of_the_five_previous_values:
355 $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4;
365 AT_BISON_CHECK([-d -v -o input.c input.y], 0)
367 AT_PARSER_CHECK([./input], 0,
371 # Make sure that fields after $n or $-n are parsed correctly. At one
372 # point while implementing dashes in symbol names, we were dropping
374 AT_DATA_GRAMMAR([[input.y]],
379 typedef struct { int val; } stype;
380 # define YYSTYPE stype
384 start: one two { $$.val = $1.val + $2.val; } sum ;
385 one: { $$.val = 1; } ;
386 two: { $$.val = 2; } ;
387 sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ;
395 AT_FULL_COMPILE([input])
396 AT_PARSER_CHECK([[./input]], [[0]],
400 AT_BISON_OPTION_POPDEFS
405 ## -------------------------- ##
406 ## Printers and Destructors. ##
407 ## -------------------------- ##
409 # _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4,
410 # BISON-DIRECTIVE, UNION-FLAG)
411 # -------------------------------------------------------------
412 m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
413 [# Make sure complex $n work.
414 m4_if([$1$2$3$4], $[1]$[2]$[3]$[4], [],
415 [m4_fatal([$0: Invalid arguments: $@])])dnl
417 # Be sure to pass all the %directives to this macro to have correct
418 # helping macros. So don't put any directly in the Bison file.
419 AT_BISON_OPTION_PUSHDEFS([$5])
420 AT_DATA_GRAMMAR([[input.y]],
427 #define YYINITDEPTH 10
428 #define YYMAXDEPTH 10
429 #define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
430 [(Location).first_line, (Location).last_line])[
432 /* Display the symbol type Symbol. */
433 #define V(Symbol, Value, Location, Sep) \
434 fprintf (stderr, #Symbol " (%d@%d-%d)" Sep, Value, RANGE(Location))
438 ]m4_ifval([$6], [%union
442 AT_LALR1_CC_IF([%define global_tokens_and_yystype])
443 m4_ifval([$6], [[%code provides {]], [[%code {]])
444 AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
446 ]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
449 ]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input END])[
451 /* FIXME: This %printer isn't actually tested. */
454 ]AT_LALR1_CC_IF([debug_stream () << $$;],
455 [fprintf (yyoutput, "%d", $$)])[;
457 input line thing 'x' 'y'
460 { fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
464 { fprintf (stderr, "Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
468 { fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
472 { fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
476 { fprintf (stderr, "Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
481 { fprintf (stderr, "Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
486 This grammar is made to exercise error recovery.
487 "Lines" starting with `(' support error recovery, with
488 ')' as synchronizing token. Lines starting with 'x' can never
489 be recovered from if in error.
496 V(input, $$, @$, ": /* Nothing */\n");
498 | line input /* Right recursive to load the stack so that popping at
499 END can be exercised. */
502 V(input, $$, @$, ": ");
503 V(line, $1, @1, " ");
504 V(input, $2, @2, "\n");
509 thing thing thing ';'
512 V(line, $$, @$, ": ");
513 V(thing, $1, @1, " ");
514 V(thing, $2, @2, " ");
515 V(thing, $3, @3, " ");
518 | '(' thing thing ')'
521 V(line, $$, @$, ": ");
523 V(thing, $2, @2, " ");
524 V(thing, $3, @3, " ");
525 V(')', $4, @4, "\n");
530 V(line, $$, @$, ": ");
532 V(thing, $2, @2, " ");
533 V(')', $3, @3, "\n");
538 V(line, $$, @$, ": ");
540 fprintf (stderr, "error (@%d-%d) ", RANGE(@2));
541 V(')', $3, @3, "\n");
549 V(thing, $$, @$, ": ");
550 V('x', $1, @1, "\n");
554 /* Alias to ARGV[1]. */
555 const char *source = YY_NULL;
562 static unsigned int counter = 0;
564 int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
565 /* As in BASIC, line numbers go from 10 to 10. */
566 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
567 ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
568 assert (0 <= c && c <= strlen (source));
570 fprintf (stderr, "sending: '%c'", source[c]);
572 fprintf (stderr, "sending: END");
573 fprintf (stderr, " (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
577 [static bool yydebug;
582 parser.set_debug_level (yydebug);
583 return parser.parse ();
588 main (int argc, const char *argv[])
591 yydebug = !!getenv ("YYDEBUG");
597 case 0: fprintf (stderr, "Successful parse.\n"); break;
598 case 1: fprintf (stderr, "Parsing FAILED.\n"); break;
599 default: fprintf (stderr, "Parsing FAILED (status %d).\n", status); break;
605 AT_FULL_COMPILE([input])
608 # Check the location of "empty"
609 # -----------------------------
610 # I.e., epsilon-reductions, as in "(x)" which ends by reducing
611 # an empty "line" nterm.
612 # FIXME: This location is not satisfying. Depend on the lookahead?
613 AT_PARSER_CHECK([./input '(x)'], 0, [],
614 [[sending: '(' (0@0-9)
615 sending: 'x' (1@10-19)
616 thing (1@10-19): 'x' (1@10-19)
617 sending: ')' (2@20-29)
618 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
619 sending: END (3@30-39)
620 input (0@29-29): /* Nothing */
621 input (2@0-29): line (0@0-29) input (0@29-29)
622 Freeing token END (3@30-39)
623 Freeing nterm input (2@0-29)
628 # Check locations in error recovery
629 # ---------------------------------
630 # '(y)' is an error, but can be recovered from. But what's the location
631 # of the error itself ('y'), and of the resulting reduction ('(error)').
632 AT_PARSER_CHECK([./input '(y)'], 0, [],
633 [[sending: '(' (0@0-9)
634 sending: 'y' (1@10-19)
635 10.10-19.18: syntax error, unexpected 'y', expecting 'x'
636 Freeing token 'y' (1@10-19)
637 sending: ')' (2@20-29)
638 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
639 sending: END (3@30-39)
640 input (0@29-29): /* Nothing */
641 input (2@0-29): line (-1@0-29) input (0@29-29)
642 Freeing token END (3@30-39)
643 Freeing nterm input (2@0-29)
648 # Syntax errors caught by the parser
649 # ----------------------------------
650 # Exercise the discarding of stack top and input until `error'
653 # '(', 'x', 'x', 'x', 'x', 'x', ')',
655 # Load the stack and provoke an error that cannot be caught by the
656 # grammar, to check that the stack is cleared. And make sure the
657 # lookahead is freed.
662 AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1, [],
663 [[sending: '(' (0@0-9)
664 sending: 'x' (1@10-19)
665 thing (1@10-19): 'x' (1@10-19)
666 sending: 'x' (2@20-29)
667 thing (2@20-29): 'x' (2@20-29)
668 sending: 'x' (3@30-39)
669 30.30-39.38: syntax error, unexpected 'x', expecting ')'
670 Freeing nterm thing (2@20-29)
671 Freeing nterm thing (1@10-19)
672 Freeing token 'x' (3@30-39)
673 sending: 'x' (4@40-49)
674 Freeing token 'x' (4@40-49)
675 sending: 'x' (5@50-59)
676 Freeing token 'x' (5@50-59)
677 sending: ')' (6@60-69)
678 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
679 sending: '(' (7@70-79)
680 sending: 'x' (8@80-89)
681 thing (8@80-89): 'x' (8@80-89)
682 sending: ')' (9@90-99)
683 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
684 sending: '(' (10@100-109)
685 sending: 'x' (11@110-119)
686 thing (11@110-119): 'x' (11@110-119)
687 sending: ')' (12@120-129)
688 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
689 sending: 'y' (13@130-139)
690 input (0@129-129): /* Nothing */
691 input (2@100-129): line (10@100-129) input (0@129-129)
692 input (2@70-129): line (7@70-99) input (2@100-129)
693 input (2@0-129): line (-1@0-69) input (2@70-129)
694 130.130-139.138: syntax error, unexpected 'y', expecting END
695 Freeing nterm input (2@0-129)
696 Freeing token 'y' (13@130-139)
701 # Syntax error caught by the parser where lookahead = END
702 # --------------------------------------------------------
703 # Load the stack and provoke an error that cannot be caught by the
704 # grammar, to check that the stack is cleared. And make sure the
705 # lookahead is freed.
710 AT_PARSER_CHECK([./input '(x)(x)x'], 1, [],
711 [[sending: '(' (0@0-9)
712 sending: 'x' (1@10-19)
713 thing (1@10-19): 'x' (1@10-19)
714 sending: ')' (2@20-29)
715 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
716 sending: '(' (3@30-39)
717 sending: 'x' (4@40-49)
718 thing (4@40-49): 'x' (4@40-49)
719 sending: ')' (5@50-59)
720 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
721 sending: 'x' (6@60-69)
722 thing (6@60-69): 'x' (6@60-69)
723 sending: END (7@70-79)
724 70.70-79.78: syntax error, unexpected END, expecting 'x'
725 Freeing nterm thing (6@60-69)
726 Freeing nterm line (3@30-59)
727 Freeing nterm line (0@0-29)
728 Freeing token END (7@70-79)
733 # Check destruction upon stack overflow
734 # -------------------------------------
735 # Upon stack overflow, all symbols on the stack should be destroyed.
736 # Only check for yacc.c.
738 AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2, [],
739 [[sending: '(' (0@0-9)
740 sending: 'x' (1@10-19)
741 thing (1@10-19): 'x' (1@10-19)
742 sending: ')' (2@20-29)
743 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
744 sending: '(' (3@30-39)
745 sending: 'x' (4@40-49)
746 thing (4@40-49): 'x' (4@40-49)
747 sending: ')' (5@50-59)
748 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
749 sending: '(' (6@60-69)
750 sending: 'x' (7@70-79)
751 thing (7@70-79): 'x' (7@70-79)
752 sending: ')' (8@80-89)
753 line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
754 sending: '(' (9@90-99)
755 sending: 'x' (10@100-109)
756 thing (10@100-109): 'x' (10@100-109)
757 sending: ')' (11@110-119)
758 line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
759 sending: '(' (12@120-129)
760 sending: 'x' (13@130-139)
761 thing (13@130-139): 'x' (13@130-139)
762 sending: ')' (14@140-149)
763 line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
764 sending: '(' (15@150-159)
765 sending: 'x' (16@160-169)
766 thing (16@160-169): 'x' (16@160-169)
767 sending: ')' (17@170-179)
768 line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
769 sending: '(' (18@180-189)
770 sending: 'x' (19@190-199)
771 thing (19@190-199): 'x' (19@190-199)
772 sending: ')' (20@200-209)
773 200.200-209.208: memory exhausted
774 Freeing nterm thing (19@190-199)
775 Freeing nterm line (15@150-179)
776 Freeing nterm line (12@120-149)
777 Freeing nterm line (9@90-119)
778 Freeing nterm line (6@60-89)
779 Freeing nterm line (3@30-59)
780 Freeing nterm line (0@0-29)
781 Parsing FAILED (status 2).
785 AT_BISON_OPTION_POPDEFS
786 ])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
789 # AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
790 # ---------------------------------------------------------------------------
791 m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR],
792 [AT_SETUP([Printers and Destructors$2]m4_ifval([$1], [[: $1]]))
795 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4],
796 [%define parse.error verbose
806 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
807 AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union])
809 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"])
810 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union])
812 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
813 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
817 ## ----------------------------------------- ##
818 ## Default tagless %printer and %destructor. ##
819 ## ----------------------------------------- ##
821 # Check that the right %printer and %destructor are called, that they're not
822 # called for $end, and that $$ and @$ work correctly.
824 AT_SETUP([Default tagless %printer and %destructor])
825 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
826 AT_DATA_GRAMMAR([[input.y]],
827 [[%define parse.error verbose
838 fprintf (yyoutput, "<*> printer should not be called.\n");
842 fprintf (yyoutput, "<> printer for '%c' @ %d", $$, @$.first_column);
845 fprintf (stdout, "<> destructor for '%c' @ %d.\n", $$, @$.first_column);
849 fprintf (yyoutput, "'b'/'c' printer for '%c' @ %d", $$, @$.first_column);
852 fprintf (stdout, "'b'/'c' destructor for '%c' @ %d.\n", $$, @$.first_column);
856 fprintf (yyoutput, "<*> destructor should not be called.\n");
861 start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
865 ]AT_YYLEX_DEFINE(["abcd"], [[yylval = res]])[
869 AT_BISON_CHECK([-o input.c input.y], [], [],
870 [[input.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
871 input.y:30.3-5: warning: useless %printer for type <*> [-Wother]
874 AT_PARSER_CHECK([./input --debug], 1,
875 [[<> destructor for 'd' @ 4.
876 'b'/'c' destructor for 'c' @ 3.
877 'b'/'c' destructor for 'b' @ 2.
878 <> destructor for 'a' @ 1.
882 Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1)
883 Shifting token 'a' (1.1: <> printer for 'a' @ 1)
885 Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
886 Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
888 Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
889 Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
891 Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4)
892 Shifting token 'd' (1.4: <> printer for 'd' @ 4)
894 Reading a token: Now at end of input.
895 1.5: syntax error, unexpected $end, expecting 'e'
896 Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
898 Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
900 Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
902 Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
904 Cleanup: discarding lookahead token $end (1.5: )
908 AT_BISON_OPTION_POPDEFS
913 ## ------------------------------------------------------ ##
914 ## Default tagged and per-type %printer and %destructor. ##
915 ## ------------------------------------------------------ ##
917 AT_SETUP([Default tagged and per-type %printer and %destructor])
918 AT_BISON_OPTION_PUSHDEFS([%debug])
919 AT_DATA_GRAMMAR([[input.y]],
920 [[%define parse.error verbose
930 fprintf (yyoutput, "<> printer should not be called.\n");
933 %union { int field0; int field1; int field2; }
934 %type <field0> start 'a' 'g'
938 fprintf (yyoutput, "<*>/<field2>/e printer");
941 fprintf (stdout, "<*>/<field2>/e destructor.\n");
945 %printer { fprintf (yyoutput, "<field1> printer"); } <field1>
946 %destructor { fprintf (stdout, "<field1> destructor.\n"); } <field1>
949 %printer { fprintf (yyoutput, "'c' printer"); } 'c'
950 %destructor { fprintf (stdout, "'c' destructor.\n"); } 'c'
953 %printer { fprintf (yyoutput, "'d' printer"); } 'd'
954 %destructor { fprintf (stdout, "'d' destructor.\n"); } 'd'
957 fprintf (yyoutput, "<> destructor should not be called.\n");
963 'a' 'b' 'c' 'd' 'e' 'f' 'g'
965 USE(($1, $2, $3, $4, $5, $6, $7));
972 ]AT_YYLEX_DEFINE(["abcdef"])[
976 AT_BISON_CHECK([-o input.c input.y], [], [],
977 [[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
978 input.y:22.3-4: warning: useless %printer for type <> [-Wother]
981 AT_PARSER_CHECK([./input --debug], 1,
982 [[<*>/<field2>/e destructor.
983 <*>/<field2>/e destructor.
987 <*>/<field2>/e destructor.
991 Reading a token: Next token is token 'a' (<*>/<field2>/e printer)
992 Shifting token 'a' (<*>/<field2>/e printer)
994 Reading a token: Next token is token 'b' (<field1> printer)
995 Shifting token 'b' (<field1> printer)
997 Reading a token: Next token is token 'c' ('c' printer)
998 Shifting token 'c' ('c' printer)
1000 Reading a token: Next token is token 'd' ('d' printer)
1001 Shifting token 'd' ('d' printer)
1003 Reading a token: Next token is token 'e' (<*>/<field2>/e printer)
1004 Shifting token 'e' (<*>/<field2>/e printer)
1006 Reading a token: Next token is token 'f' (<*>/<field2>/e printer)
1007 Shifting token 'f' (<*>/<field2>/e printer)
1009 Reading a token: Now at end of input.
1010 syntax error, unexpected $end, expecting 'g'
1011 Error: popping token 'f' (<*>/<field2>/e printer)
1012 Stack now 0 1 3 5 6 7
1013 Error: popping token 'e' (<*>/<field2>/e printer)
1015 Error: popping token 'd' ('d' printer)
1017 Error: popping token 'c' ('c' printer)
1019 Error: popping token 'b' (<field1> printer)
1021 Error: popping token 'a' (<*>/<field2>/e printer)
1023 Cleanup: discarding lookahead token $end ()
1027 AT_BISON_OPTION_POPDEFS
1032 ## ------------------------------------------------------------- ##
1033 ## Default %printer and %destructor for user-defined end token. ##
1034 ## ------------------------------------------------------------- ##
1036 AT_SETUP([Default %printer and %destructor for user-defined end token])
1040 m4_pushdef([AT_TEST],
1042 [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
1043 [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
1045 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
1046 AT_DATA_GRAMMAR([[input]]$1[[.y]],
1047 [[%define parse.error verbose
1052 ]AT_YYERROR_DECLARE[
1058 fprintf (yyoutput, "<]]not_kind[[> destructor should not be called.\n");
1063 fprintf (yyoutput, "<]]kind[[> for '%c' @ %d", $$, @$.first_column);
1066 fprintf (stdout, "<]]kind[[> for '%c' @ %d.\n", $$, @$.first_column);
1070 fprintf (yyoutput, "<]]not_kind[[> printer should not be called.\n");
1075 [[[%union { char tag; }
1076 %type <tag> start END]]])[[
1080 start: { $$ = 'S'; } ;
1083 #include <stdlib.h> /* abort */
1090 yylval]]m4_if($1, 0,, [[[.tag]]])[[ = 'E';
1091 yylloc.first_line = yylloc.last_line = 1;
1092 yylloc.first_column = yylloc.last_column = 1;
1098 AT_BISON_OPTION_POPDEFS
1100 AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
1102 [[input0.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
1103 input0.y:30.3-5: warning: useless %printer for type <*> [-Wother]
1105 [[input1.y:30.3-4: warning: useless %destructor for type <> [-Wother]
1106 input1.y:30.3-4: warning: useless %printer for type <> [-Wother]
1109 AT_COMPILE([input$1])
1111 AT_PARSER_CHECK([./input$1 --debug], 0,
1112 [[<]]kind[[> for 'E' @ 1.
1113 <]]kind[[> for 'S' @ 1.
1117 Reducing stack by rule 1 (line 49):
1118 -> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
1121 Reading a token: Now at end of input.
1122 Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
1125 Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
1126 Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
1130 m4_popdef([not_kind])
1136 m4_popdef([AT_TEST])
1142 ## ------------------------------------------------------------------ ##
1143 ## Default %printer and %destructor are not for error or $undefined. ##
1144 ## ------------------------------------------------------------------ ##
1146 AT_SETUP([Default %printer and %destructor are not for error or $undefined])
1148 # If Bison were to apply the default %printer and %destructor to the error
1149 # token or to $undefined:
1150 # - For the error token:
1151 # - It would generate warnings for unused $n.
1152 # - It would invoke the %printer and %destructor on the error token's
1153 # semantic value, which would be initialized from the lookahead, which
1154 # would be destroyed separately.
1155 # - For $undefined, who knows what the semantic value would be.
1156 AT_BISON_OPTION_PUSHDEFS([%debug])
1157 AT_DATA_GRAMMAR([[input.y]],
1162 # include <stdlib.h>
1163 ]AT_YYERROR_DECLARE[
1169 fprintf (yyoutput, "'%c'", $$);
1172 fprintf (stderr, "DESTROY '%c'\n", $$);
1179 /* In order to reveal the problems that this bug caused during parsing, add
1181 | 'a' error 'b' 'c' { USE(($1, $3, $4)); $$ = 'S'; }
1186 ]AT_YYLEX_DEFINE(["abd"], [yylval = res])[
1189 AT_BISON_OPTION_POPDEFS
1191 AT_BISON_CHECK([-o input.c input.y], [], [],
1192 [[input.y:23.6-8: warning: useless %destructor for type <*> [-Wother]
1193 input.y:23.6-8: warning: useless %printer for type <*> [-Wother]
1196 AT_PARSER_CHECK([./input --debug], [1], [],
1199 Reading a token: Next token is token 'a' ('a')
1200 Shifting token 'a' ('a')
1202 Reading a token: Next token is token 'b' ('b')
1204 Shifting token error ()
1206 Next token is token 'b' ('b')
1207 Shifting token 'b' ('b')
1209 Reading a token: Next token is token $undefined ()
1210 Error: popping token 'b' ('b')
1213 Error: popping token error ()
1215 Shifting token error ()
1217 Next token is token $undefined ()
1218 Error: discarding token $undefined ()
1219 Error: popping token error ()
1221 Shifting token error ()
1223 Reading a token: Now at end of input.
1224 Cleanup: discarding lookahead token $end ()
1226 Cleanup: popping token error ()
1227 Cleanup: popping token 'a' ('a')
1235 ## ------------------------------------------------------ ##
1236 ## Default %printer and %destructor are not for $accept. ##
1237 ## ------------------------------------------------------ ##
1239 AT_SETUP([Default %printer and %destructor are not for $accept])
1241 # If YYSTYPE is a union and Bison were to apply the default %printer and
1242 # %destructor to $accept:
1243 # - The %printer and %destructor code generated for $accept would always be
1244 # dead code because $accept is currently never shifted onto the stack.
1245 # - $$ for $accept would always be of type YYSTYPE because it's not possible
1246 # to declare `%type <field> $accept'. (Also true for $undefined.)
1247 # - Thus, the compiler might complain that the user code assumes the wrong
1248 # type for $$ since the code might assume the type associated with a
1249 # specific union field, which is especially reasonable in C++ since that
1250 # type may be a base type. This test case checks for this problem. (Also
1251 # true for $undefined and the error token, so there are three warnings for
1252 # %printer and three for %destructor.)
1254 AT_BISON_OPTION_PUSHDEFS([%debug])
1255 AT_DATA_GRAMMAR([[input.y]],
1256 [[%debug /* So that %printer is actually compiled. */
1260 # include <stdlib.h>
1261 ]AT_YYERROR_DECLARE[
1268 fprintf (yyoutput, "'%c'", chr);
1272 fprintf (stderr, "DESTROY '%c'\n", chr);
1275 %union { char chr; }
1280 start: { USE($$); } ;
1287 AT_BISON_OPTION_POPDEFS
1289 AT_BISON_CHECK([-o input.c input.y], [], [],
1290 [[input.y:24.3-4: warning: useless %destructor for type <> [-Wother]
1291 input.y:24.3-4: warning: useless %printer for type <> [-Wother]
1299 ## ------------------------------------------------------ ##
1300 ## Default %printer and %destructor for mid-rule values. ##
1301 ## ------------------------------------------------------ ##
1303 AT_SETUP([Default %printer and %destructor for mid-rule values])
1305 AT_BISON_OPTION_PUSHDEFS([%debug])
1306 AT_DATA_GRAMMAR([[input.y]],
1307 [[%debug /* So that %printer is actually compiled. */
1310 ]AT_YYERROR_DECLARE[
1313 # define YYLTYPE int
1314 # define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
1315 # define LOCATION_PRINT(File, Loc)
1318 %printer { fprintf (yyoutput, "%d", @$); } <>
1319 %destructor { fprintf (stderr, "DESTROY %d\n", @$); } <>
1320 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1321 %destructor { fprintf (yyoutput, "<*> destructor should not be called"); } <*>
1326 { @$ = 1; } // Not set or used.
1327 { USE ($$); @$ = 2; } // Both set and used.
1328 { USE ($$); @$ = 3; } // Only set.
1329 { @$ = 4; } // Only used.
1331 { USE (($$, $2, $4, $5)); @$ = 0; }
1339 AT_BISON_OPTION_POPDEFS
1341 AT_BISON_CHECK([-o input.c input.y], 0,,
1342 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1343 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1344 input.y:33.3-23: warning: unset value: $$ [-Wother]
1345 input.y:32.3-23: warning: unused value: $3 [-Wother]
1348 AT_BISON_CHECK([-fcaret -o input.c input.y], 0,,
1349 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1350 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1352 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1353 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1355 input.y:33.3-23: warning: unset value: $$ [-Wother]
1356 { @$ = 4; } // Only used.
1357 ^^^^^^^^^^^^^^^^^^^^^
1358 input.y:32.3-23: warning: unused value: $3 [-Wother]
1359 { USE ($$); @$ = 3; } // Only set.
1360 ^^^^^^^^^^^^^^^^^^^^^
1364 AT_PARSER_CHECK([./input --debug], 1,,
1367 Reducing stack by rule 1 (line 30):
1368 -> $$ = nterm $@1 (: )
1371 Reducing stack by rule 2 (line 31):
1372 -> $$ = nterm @2 (: 2)
1375 Reducing stack by rule 3 (line 32):
1376 -> $$ = nterm @3 (: 3)
1379 Reducing stack by rule 4 (line 33):
1380 -> $$ = nterm @4 (: 4)
1383 Reading a token: Now at end of input.
1385 Error: popping nterm @4 (: 4)
1388 Error: popping nterm @3 (: 3)
1391 Error: popping nterm @2 (: 2)
1394 Error: popping nterm $@1 (: )
1396 Cleanup: discarding lookahead token $end (: )
1403 ## ----------------------- ##
1404 ## @$ implies %locations. ##
1405 ## ----------------------- ##
1407 # Bison once forgot to check for @$ in actions other than semantic actions.
1409 # AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE)
1410 # -------------------------------------------
1411 m4_define([AT_CHECK_ACTION_LOCATIONS],
1412 [AT_SETUP([[@$ in ]$1[ implies %locations]])
1413 AT_BISON_OPTION_PUSHDEFS([%debug])
1414 AT_DATA_GRAMMAR([[input.y]],
1417 ]AT_YYERROR_DECLARE[
1424 fprintf (stderr, "%d\n", @$.first_line);
1425 } ]m4_if($1, [%initial-action], [], [[start]])[
1443 AT_BISON_CHECK([[-o input.c input.y]])
1444 AT_COMPILE([[input]])
1445 AT_BISON_OPTION_POPDEFS
1448 AT_CHECK_ACTION_LOCATIONS([[%initial-action]])
1449 AT_CHECK_ACTION_LOCATIONS([[%destructor]])
1450 AT_CHECK_ACTION_LOCATIONS([[%printer]])
1453 ## ------------------------- ##
1454 ## Qualified $$ in actions. ##
1455 ## ------------------------- ##
1457 # Check that we can use qualified $$ (v.g., $<type>$) not only in rule
1458 # actions, but also where $$ is valid: %destructor/%printer and
1461 # FIXME: Not actually checking %destructor, but it's the same code as
1464 # To do that, use a semantic value that has two fields (sem_type),
1465 # declare symbols to have only one of these types (INT, float), and
1466 # use $<type>$ to get the other one. Including for symbols that are
1467 # not typed (UNTYPED).
1469 m4_pushdef([AT_TEST],
1470 [AT_SETUP([[Qualified $$ in actions: $1]])
1472 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %debug])
1474 AT_DATA_GRAMMAR([[input.y]],
1479 typedef struct sem_type
1485 # define YYSTYPE sem_type
1488 # include <iostream>
1490 report (std::ostream& yyo, int ival, float fval)
1492 yyo << "ival: " << ival << ", fval: " << fval;
1497 report (FILE* yyo, int ival, float fval)
1499 fprintf (yyo, "ival: %d, fval: %1.1f", ival, fval);
1506 ]AT_YYERROR_DECLARE[
1513 %printer { report (yyo, $$, $<fval>$); } <ival>;
1514 %printer { report (yyo, $<ival>$, $$ ); } <fval>;
1515 %printer { report (yyo, $<ival>$, $<fval>$); } <>;
1526 $$ = $<fval>1 + $<fval>2;
1527 $<ival>$ = $<ival>1 + $][2;
1531 ]AT_YYLEX_DEFINE(AT_SKEL_CC_IF([[{yy::parser::token::UNTYPED,
1532 yy::parser::token::INT,
1534 [[{UNTYPED, INT, EOF}]]),
1535 [AT_VAL.ival = toknum * 10; AT_VAL.fval = toknum / 10.0;])[
1539 AT_FULL_COMPILE([[input]])
1540 AT_PARSER_CHECK([./input --debug], 0, [], [stderr])
1541 # Don't be too picky on the traces, GLR is not exactly the same. Keep
1542 # only the lines from the printer.
1543 AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
1544 [[Reading a token: Next token is token UNTYPED (ival: 10, fval: 0.1)
1545 Shifting token UNTYPED (ival: 10, fval: 0.1)
1546 Reading a token: Next token is token INT (ival: 20, fval: 0.2)
1547 Shifting token INT (ival: 20, fval: 0.2)
1548 $][1 = token UNTYPED (ival: 10, fval: 0.1)
1549 $][2 = token INT (ival: 20, fval: 0.2)
1550 -> $$ = nterm float (ival: 30, fval: 0.3)
1551 Cleanup: popping nterm float (ival: 30, fval: 0.3)
1554 AT_BISON_OPTION_POPDEFS
1564 m4_popdef([AT_TEST])
1566 ## ----------------------------------------------- ##
1567 ## Fix user actions without a trailing semicolon. ##
1568 ## ----------------------------------------------- ##
1570 AT_SETUP([[Fix user actions without a trailing semicolon]])
1572 # This feature is undocumented, but we accidentally broke it in 2.3a,
1573 # and there was a complaint at:
1574 # <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
1575 AT_BISON_OPTION_PUSHDEFS
1578 start: test2 test1 test0 testc;
1581 : 'a' { semi; /* TEST:N:2 */ }
1582 | 'b' { if (0) {no_semi} /* TEST:N:2 */ }
1583 | 'c' { if (0) {semi;} /* TEST:N:2 */ }
1584 | 'd' { semi; no_semi /* TEST:Y:2 */ }
1585 | 'e' { semi(); no_semi() /* TEST:Y:2 */ }
1586 | 'f' { semi[]; no_semi[] /* TEST:Y:2 */ }
1587 | 'g' { semi++; no_semi++ /* TEST:Y:2 */ }
1588 | 'h' { {no_semi} no_semi /* TEST:Y:2 */ }
1589 | 'i' { {semi;} no_semi /* TEST:Y:2 */ }
1592 : 'a' { semi; // TEST:N:1 ;
1593 } | 'b' { if (0) {no_semi} // TEST:N:1 ;
1594 } | 'c' { if (0) {semi;} // TEST:N:1 ;
1595 } | 'd' { semi; no_semi // TEST:Y:1 ;
1596 } | 'e' { semi(); no_semi() // TEST:Y:1 ;
1597 } | 'f' { semi[]; no_semi[] // TEST:Y:1 ;
1598 } | 'g' { semi++; no_semi++ // TEST:Y:1 ;
1599 } | 'h' { {no_semi} no_semi // TEST:Y:1 ;
1600 } | 'i' { {semi;} no_semi // TEST:Y:1 ;
1603 : 'a' { semi; // TEST:N:1 {}
1604 } | 'b' { if (0) {no_semi} // TEST:N:1 {}
1605 } | 'c' { if (0) {semi;} // TEST:N:1 {}
1606 } | 'd' { semi; no_semi // TEST:Y:1 {}
1607 } | 'e' { semi(); no_semi() // TEST:Y:1 {}
1608 } | 'f' { semi[]; no_semi[] // TEST:Y:1 {}
1609 } | 'g' { semi++; no_semi++ // TEST:Y:1 {}
1610 } | 'h' { {no_semi} no_semi // TEST:Y:1 {}
1611 } | 'i' { {semi;} no_semi // TEST:Y:1 {}
1616 #define TEST_MACRO_N \
1617 []"broken\" $ @ $$ @$ [];\
1621 #define TEST_MACRO_N \
1622 []"broken\" $ @ $$ @$ [];\
1625 AT_BISON_OPTION_POPDEFS
1627 AT_BISON_CHECK([[-o input.c input.y]], [0], [],
1628 [[input.y:8.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1629 input.y:8.48: future versions of Bison will not add the ';'
1630 input.y:9.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1631 input.y:9.48: future versions of Bison will not add the ';'
1632 input.y:10.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1633 input.y:10.48: future versions of Bison will not add the ';'
1634 input.y:11.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1635 input.y:11.48: future versions of Bison will not add the ';'
1636 input.y:12.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1637 input.y:12.48: future versions of Bison will not add the ';'
1638 input.y:13.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1639 input.y:13.48: future versions of Bison will not add the ';'
1640 input.y:20.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1641 input.y:20.1: future versions of Bison will not add the ';'
1642 input.y:21.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1643 input.y:21.1: future versions of Bison will not add the ';'
1644 input.y:22.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1645 input.y:22.1: future versions of Bison will not add the ';'
1646 input.y:23.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1647 input.y:23.1: future versions of Bison will not add the ';'
1648 input.y:24.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1649 input.y:24.1: future versions of Bison will not add the ';'
1650 input.y:25.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1651 input.y:25.1: future versions of Bison will not add the ';'
1652 input.y:31.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1653 input.y:31.1: future versions of Bison will not add the ';'
1654 input.y:32.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1655 input.y:32.1: future versions of Bison will not add the ';'
1656 input.y:33.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1657 input.y:33.1: future versions of Bison will not add the ';'
1658 input.y:34.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1659 input.y:34.1: future versions of Bison will not add the ';'
1660 input.y:35.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1661 input.y:35.1: future versions of Bison will not add the ';'
1662 input.y:36.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1663 input.y:36.1: future versions of Bison will not add the ';'
1666 AT_MATCHES_CHECK([input.c], [[/\* TEST:N:2 \*/ \}$]], [[3]])
1667 AT_MATCHES_CHECK([input.c], [[/\* TEST:Y:2 \*/ ;\}$]], [[6]])
1668 AT_MATCHES_CHECK([input.c], [[// TEST:N:1 [;{}]*\n\}$]], [[6]])
1669 AT_MATCHES_CHECK([input.c], [[// TEST:Y:1 [;{}]*\n;\}$]], [[12]])
1670 AT_MATCHES_CHECK([input.c], [[#define TEST_MACRO_N \\\n\[\]"broken\\" \$ \@ \$\$ \@\$ \[\];\\\nstring;"\}]], [[2]])
1675 ## -------------------------------------------------- ##
1676 ## Destroying lookahead assigned by semantic action. ##
1677 ## -------------------------------------------------- ##
1679 AT_SETUP([[Destroying lookahead assigned by semantic action]])
1681 AT_BISON_OPTION_PUSHDEFS
1682 AT_DATA_GRAMMAR([input.y],
1687 ]AT_YYERROR_DECLARE[
1692 %destructor { fprintf (stderr, "'a' destructor\n"); } 'a'
1693 %destructor { fprintf (stderr, "'b' destructor\n"); } 'b'
1697 // In a previous version of Bison, yychar assigned by the semantic
1698 // action below was not translated into yytoken before the lookahead was
1699 // discarded and thus before its destructor (selected according to
1700 // yytoken) was called in order to return from yyparse. This would
1701 // happen even if YYACCEPT was performed in a later semantic action as
1702 // long as only consistent states with default reductions were visited
1703 // in between. However, we leave YYACCEPT in the same semantic action
1704 // for this test in order to show that skeletons cannot simply translate
1705 // immediately after every semantic action because a semantic action
1706 // that has set yychar might not always return normally. Instead,
1707 // skeletons must translate before every use of yytoken.
1708 start: 'a' accept { USE($1); } ;
1710 assert (yychar == YYEMPTY);
1717 ]AT_YYLEX_DEFINE(["a"])[
1720 AT_BISON_OPTION_POPDEFS
1721 AT_BISON_CHECK([[-o input.c input.y]])
1722 AT_COMPILE([[input]])
1723 AT_PARSER_CHECK([[./input]], [[0]], [],
1734 AT_SETUP([[YYBACKUP]])
1736 AT_BISON_OPTION_PUSHDEFS([%pure-parser %debug])
1738 AT_DATA_GRAMMAR([input.y],
1745 # include <stdlib.h>
1746 # include <assert.h>
1748 ]AT_YYERROR_DECLARE[
1757 'a' { printf ("a: %d\n", $1); }
1758 | 'b' { YYBACKUP('a', 123); }
1759 | 'c' 'd' { YYBACKUP('a', 456); }
1764 ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[
1767 AT_BISON_OPTION_POPDEFS
1769 AT_BISON_CHECK([[-o input.c input.y]])
1770 AT_COMPILE([[input]])
1771 AT_PARSER_CHECK([[./input]], [[0]],