1 # Executing Actions. -*- Autotest -*-
3 # Copyright (C) 2001-2015, 2018-2021 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 <https://www.gnu.org/licenses/>.
18 AT_BANNER([[User Actions.]])
20 ## ----------------- ##
21 ## Midrule actions. ##
22 ## ----------------- ##
24 AT_SETUP([Midrule actions])
26 # Bison once forgot the midrule actions. It was because the action
27 # was attached to the host rule (the one with the midrule 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,
68 ## ----------------------- ##
69 ## Typed midrule actions. ##
70 ## ----------------------- ##
72 AT_SETUP([Typed midrule actions])
74 AT_BISON_OPTION_PUSHDEFS
75 AT_DATA_GRAMMAR([[input.y]],
76 [[%define parse.error verbose
87 exp: <ival>{ $$ = 0; }
96 '9' <ival>{ $$ = 9; } <ival>{ $$ = 10; } <ival>{ $$ = 11; }
98 $$ = $1 + $3 + $5 + $7 + $9 + $11 + $13 + $15 + $17 + $19 + $20 + $21;
104 ]AT_YYLEX_DEFINE(["123456789"])[
107 AT_BISON_OPTION_POPDEFS
109 AT_BISON_CHECK([-d -v -o input.c input.y])
111 AT_PARSER_CHECK([input], 0,
118 ## ----------------------- ##
119 ## Implicitly empty rule. ##
120 ## ----------------------- ##
122 AT_SETUP([Implicitly empty rule])
124 AT_BISON_OPTION_PUSHDEFS
125 AT_DATA_GRAMMAR([[1.y]],
129 // A midrule action does not count as an empty rule.
133 AT_BISON_CHECK([-fcaret -Wempty-rule 1.y], [0], [],
134 [[1.y:11.17-18: warning: empty rule without %empty [-Wempty-rule]
135 11 | a: /* empty. */ {};
138 1.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
141 AT_DATA_GRAMMAR([[2.y]],
149 AT_BISON_CHECK([-fcaret 2.y], [0], [],
150 [[2.y:11.17-18: warning: empty rule without %empty [-Wempty-rule]
151 11 | a: /* empty. */ {};
154 2.y:13.17-18: warning: empty rule without %empty [-Wempty-rule]
155 13 | c: /* empty. */ {};
158 2.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
161 AT_BISON_CHECK([-fcaret -Wno-empty-rule 2.y], [0])
163 AT_BISON_OPTION_POPDEFS
168 ## ------------------------ ##
169 ## Invalid uses of %empty. ##
170 ## ------------------------ ##
172 AT_SETUP([Invalid uses of %empty])
174 AT_BISON_OPTION_PUSHDEFS
175 AT_DATA_GRAMMAR([[one.y]],
182 AT_BISON_CHECK([-fcaret one.y], [1], [],
183 [[one.y:11.13-18: error: only one %empty allowed per rule
184 11 | %empty {} %empty
186 one.y:11.3-8: note: previous declaration
187 11 | %empty {} %empty
189 one.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
192 AT_BISON_CHECK([-fcaret -u one.y], [1], [],
193 [[one.y:11.13-18: error: only one %empty allowed per rule
194 11 | %empty {} %empty
196 one.y:11.3-8: note: previous declaration
197 11 | %empty {} %empty
199 bison: file 'one.y' was updated (backup: 'one.y~')
202 AT_CHECK([sed -e '1,8d' one.y], [],
210 AT_DATA_GRAMMAR([[two.y]],
219 AT_BISON_CHECK([-fcaret two.y], [1], [],
220 [[two.y:11.7-12: error: %empty on non-empty rule
223 two.y:12.3-8: error: %empty on non-empty rule
226 two.y:13.3-8: error: %empty on non-empty rule
229 two.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
232 AT_BISON_OPTION_POPDEFS
236 ## ---------------------- ##
237 ## Valid uses of %empty. ##
238 ## ---------------------- ##
240 AT_SETUP([Valid uses of %empty])
242 AT_BISON_OPTION_PUSHDEFS
243 AT_DATA_GRAMMAR([[input.y]],
259 AT_FULL_COMPILE([input])
260 AT_PARSER_CHECK([input])
261 AT_BISON_OPTION_POPDEFS
266 ## -------------------- ##
267 ## Add missing %empty. ##
268 ## -------------------- ##
270 AT_SETUP([Add missing %empty])
285 AT_BISON_CHECK([--update -Wall input.y], [], [], [ignore])
286 AT_CHECK([cat input.y], [],
300 AT_BISON_CHECK([-Wall input.y])
305 ## ------------------ ##
306 ## Initial location. ##
307 ## ------------------ ##
309 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
310 # -----------------------------------------------------------------------
311 # Check that the initial location is correct.
312 m4_pushdef([AT_TEST],
313 [AT_SETUP([Initial location: $1 $2])
315 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
316 AT_DATA_GRAMMAR([[input.y]],
325 # include <stdlib.h> /* getenv */
330 exp: { ]AT_CXX_IF([[std::cerr << @$ << '\n']],
331 [[LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
338 YY_USE (llocp);], [AT_CXX_IF([
348 p.set_debug_level (!!getenv ("YYDEBUG"));
349 return p.parse ();]], [[
350 yydebug = !!getenv ("YYDEBUG");
351 return !!yyparse (]AT_PARAM_IF([0])[);]])[
355 AT_FULL_COMPILE([input])
356 AT_PARSER_CHECK([input], 1, [],
357 [m4_default([$4], [1.1])
358 m4_default([$4], [1.1])[: syntax error
360 AT_BISON_OPTION_POPDEFS
364 ## FIXME: test Java, and iterate over skeletons.
366 AT_TEST([yacc.c], [%define api.pure full])
367 AT_TEST([yacc.c], [%define api.pure %parse-param { int x }])
368 AT_TEST([yacc.c], [%define api.push-pull both])
369 AT_TEST([yacc.c], [%define api.push-pull both %define api.pure full])
371 AT_TEST([glr.c], [%define api.pure])
376 ## A very different test, based on PostgreSQL's implementation of the
378 ## https://lists.gnu.org/r/bug-bison/2012-11/msg00023.html
380 ## Weirdly enough, to trigger the warning with GCC 4.7, we must not
381 ## use fprintf, so run the test twice: once to check the warning
382 ## (absence thereof), and another time to check the value.
383 AT_TEST([yacc.c], [%define api.pure full],
386 # define LOCATION_PRINT(Stream, Loc) \
388 # define YYLLOC_DEFAULT(Current, Rhs, N) \
389 (Current) = ((Rhs)[N ? 1 : 0])
394 AT_TEST([yacc.c], [%define api.pure full],
397 # define LOCATION_PRINT(Stream, Loc) \
398 fprintf ((Stream), "%d", (Loc))
399 # define YYLLOC_DEFAULT(Current, Rhs, N) \
400 (Current) = ((Rhs)[N ? 1 : 0])
410 ## ---------------- ##
411 ## Location Print. ##
412 ## ---------------- ##
414 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES])
415 # -----------------------------------------------------
416 # Check that the initial location is correct.
417 m4_pushdef([AT_TEST],
418 [AT_SETUP([Location print: $1 $2])
420 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
421 AT_DATA_GRAMMAR([[input.y]],
429 #include <stdio.h> /* putchar. */
443 ]AT_GLR_CC_IF([loc.initialize();])[
444 #define TEST(L1, C1, L2, C2) \
445 loc.]AT_FIRST_LINE[ = L1; \
446 loc.]AT_FIRST_COLUMN[ = C1; \
447 loc.]AT_LAST_LINE[ = L2; \
448 loc.]AT_LAST_COLUMN[ = C2; \
449 ]AT_CXX_IF([std::cout << loc],
450 [LOCATION_PRINT(stdout, loc)])[;\
464 AT_FULL_COMPILE([input])
465 AT_PARSER_CHECK([input], 0,
473 AT_BISON_OPTION_POPDEFS
477 ## FIXME: test Java and D.
478 m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc], [glr2.cc])
484 ## ---------------- ##
485 ## Exotic Dollars. ##
486 ## ---------------- ##
488 AT_SETUP([Exotic Dollars])
490 AT_BISON_OPTION_PUSHDEFS
491 AT_DATA_GRAMMAR([[input.y]],
492 [[%define parse.error verbose
505 %type <val> a_1 a_2 a_5
506 sum_of_the_five_previous_values
509 exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
510 sum_of_the_five_previous_values
512 USE (($1, $2, $<foo>3, $<foo>4, $5));
520 sum_of_the_five_previous_values:
522 $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4;
532 AT_BISON_CHECK([-d -v -o input.c input.y], 0)
534 AT_PARSER_CHECK([input], 0,
538 # Make sure that fields after $n or $-n are parsed correctly. At one
539 # point while implementing dashes in symbol names, we were dropping
541 AT_DATA_GRAMMAR([[input.y]],
546 typedef struct { int val; } stype;
547 # define YYSTYPE stype
551 start: one two { $$.val = $1.val + $2.val; } sum ;
552 one: { $$.val = 1; } ;
553 two: { $$.val = 2; } ;
554 sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ;
562 AT_FULL_COMPILE([input])
563 AT_PARSER_CHECK([[input]], [[0]],
567 AT_BISON_OPTION_POPDEFS
572 ## -------------------------- ##
573 ## Printers and Destructors. ##
574 ## -------------------------- ##
576 # _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4,
577 # BISON-DIRECTIVE, UNION-FLAG)
578 # -------------------------------------------------------------
579 m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
580 [# Make sure complex $n work.
581 m4_if([$1$2$3$4], $[1]$[2]$[3]$[4], [],
582 [m4_fatal([$0: Invalid arguments: $@])])dnl
584 # Be sure to pass all the %directives to this macro to have correct
585 # helping macros. So don't put any directly in the Bison file.
586 AT_BISON_OPTION_PUSHDEFS([$5])
587 AT_DATA_GRAMMAR([[input.y]],
594 #define YYINITDEPTH 10
595 #define YYMAXDEPTH 10
596 #define RANGE(Location) ]AT_CXX_IF([(Location).begin.line, (Location).end.line],
597 [(Location).first_line, (Location).last_line])[
601 /* Display the symbol type Symbol. */
602 #define V(Symbol, Value, Location, Sep) \
603 fprintf (stderr, #Symbol " (%d@%d-%d)%s", Value, RANGE(Location), Sep)
607 ]m4_ifval([$6], [%union
611 m4_ifval([$6], [[%code provides {]], [[%code {]])
612 AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
614 ]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
618 [%type <ival> '(' 'x' 'y' ')' ';' thing line input
619 '!' raise check-spontaneous-errors END])[
621 /* FIXME: This %printer isn't actually tested. */
624 ]AT_CXX_IF([yyo << $$;],
625 [fprintf (yyo, "%d", $$)])[;
627 '(' 'x' 'y' ')' ';' thing line input '!' raise check-spontaneous-errors END
630 { fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
634 { fprintf (stderr, "Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
638 { fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
642 { fprintf (stderr, "Freeing nterm raise (%d@%d-%d)\n", $$, RANGE (@$)); }
646 { fprintf (stderr, "Freeing nterm check-spontaneous-errors (%d@%d-%d)\n", $$, RANGE (@$)); }
647 check-spontaneous-errors
650 { fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
654 { fprintf (stderr, "Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
659 { fprintf (stderr, "Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
664 This grammar is made to exercise error recovery.
665 "Lines" starting with '(' support error recovery, with
666 ')' as synchronizing token. Lines starting with 'x' can never
667 be recovered from if in error.
674 V(input, $$, @$, ": /* Nothing */\n");
676 | line input /* Right recursive to load the stack so that popping at
677 END can be exercised. */
680 V(input, $$, @$, ": ");
681 V(line, $1, @1, " ");
682 V(input, $2, @2, "\n");
684 | '!' check-spontaneous-errors
690 check-spontaneous-errors:
691 raise { abort(); USE(($$, $1)); }
692 | '(' raise ')' { abort(); USE(($$, $2)); }
696 V(check-spontaneous-errors, $$, @$, ": ");
697 fprintf (stderr, "error (@%d-%d)\n", RANGE(@1));
705 V(raise, $$, @$, ": %empty\n");
711 V(raise, $$, @$, ": ");
719 thing thing thing ';'
722 V(line, $$, @$, ": ");
723 V(thing, $1, @1, " ");
724 V(thing, $2, @2, " ");
725 V(thing, $3, @3, " ");
728 | '(' thing thing ')'
731 V(line, $$, @$, ": ");
733 V(thing, $2, @2, " ");
734 V(thing, $3, @3, " ");
735 V(')', $4, @4, "\n");
740 V(line, $$, @$, ": ");
742 V(thing, $2, @2, " ");
743 V(')', $3, @3, "\n");
748 V(line, $$, @$, ": ");
750 fprintf (stderr, "error (@%d-%d) ", RANGE(@2));
751 V(')', $3, @3, "\n");
759 V(thing, $$, @$, ": ");
760 V('x', $1, @1, "\n");
764 /* Alias to ARGV[1]. */
765 const char *source = YY_NULLPTR;
772 static int counter = 0;
774 int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
775 assert (c <= YY_CAST (int, strlen (source)));
776 /* As in BASIC, line numbers go from 10 to 10. */
777 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = (10 * c);
778 ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
780 fprintf (stderr, "sending: '%c'", source[c]);
782 fprintf (stderr, "sending: END");
783 fprintf (stderr, " (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
786 ]AT_LALR1_CC_IF([static bool yydebug;])[
791 parser.set_debug_level (yydebug);
792 return parser.parse ();
797 main (int argc, const char *argv[])
800 yydebug = !!getenv ("YYDEBUG");
801 assert (argc == 2); (void) argc;
806 case 0: fprintf (stderr, "Successful parse.\n"); break;
807 case 1: fprintf (stderr, "Parsing FAILED.\n"); break;
808 default: fprintf (stderr, "Parsing FAILED (status %d).\n", status); break;
814 AT_FULL_COMPILE([input])
817 # Check the location of "empty"
818 # -----------------------------
819 # I.e., epsilon-reductions, as in "(x)" which ends by reducing
820 # an empty "line" nterm.
821 # FIXME: This location is not satisfying. Depend on the lookahead?
822 AT_PARSER_CHECK([input '(x)'], 0, [],
823 [[sending: '(' (0@0-9)
824 sending: 'x' (1@10-19)
825 thing (1@10-19): 'x' (1@10-19)
826 sending: ')' (2@20-29)
827 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
828 sending: END (3@30-39)
829 input (0@29-29): /* Nothing */
830 input (2@0-29): line (0@0-29) input (0@29-29)
831 Freeing token END (3@30-39)
832 Freeing nterm input (2@0-29)
836 # Check the location of empty reductions raising an error
837 # -------------------------------------------------------
838 # Here, the error is after token "!@0-9", so the error is raised from
839 # @9-9, and the error recovery detects that it starts from @9-9 and
840 # ends where starts the next token: END@10-19.
842 # So error recovery reports error@9-19.
843 AT_PARSER_CHECK([input '!'], 0, [],
844 [[sending: '!' (0@0-9)
845 sending: END (1@10-19)
846 raise (4@9-9): %empty
847 check-spontaneous-errors (5@9-19): error (@9-19)
848 Freeing token END (1@10-19)
849 Freeing nterm input (5@0-19)
853 # Check the location of not empty reductions raising an error
854 # -----------------------------------------------------------
855 # This time the error is raised from a rule with 2 rhs symbols: @10-29.
856 # It is recovered @10-29.
857 AT_PARSER_CHECK([[input '!!!']], 0, [],
858 [[sending: '!' (0@0-9)
859 sending: '!' (1@10-19)
860 sending: '!' (2@20-29)
861 raise (5@10-29): ! (1@20-29) ! (2@20-29)
862 check-spontaneous-errors (5@10-29): error (@10-29)
863 sending: END (3@30-39)
864 Freeing token END (3@30-39)
865 Freeing nterm input (5@0-29)
869 # Check locations in error recovery
870 # ---------------------------------
871 # '(y)' is an error, but can be recovered from. But what's the location
872 # of the error itself ('y'), and of the resulting reduction ('(error)').
873 AT_PARSER_CHECK([input '(y)'], 0, [],
874 [[sending: '(' (0@0-9)
875 sending: 'y' (1@10-19)
876 10.10-19.18: syntax error, unexpected 'y', expecting 'x'
877 Freeing token 'y' (1@10-19)
878 sending: ')' (2@20-29)
879 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
880 sending: END (3@30-39)
881 input (0@29-29): /* Nothing */
882 input (2@0-29): line (-1@0-29) input (0@29-29)
883 Freeing token END (3@30-39)
884 Freeing nterm input (2@0-29)
889 # Syntax errors caught by the parser
890 # ----------------------------------
891 # Exercise the discarding of stack top and input until 'error'
894 # '(', 'x', 'x', 'x', 'x', 'x', ')',
896 # Load the stack and provoke an error that cannot be caught by the
897 # grammar, to check that the stack is cleared. And make sure the
898 # lookahead is freed.
903 AT_PARSER_CHECK([input '(xxxxx)(x)(x)y'], 1, [],
904 [[sending: '(' (0@0-9)
905 sending: 'x' (1@10-19)
906 thing (1@10-19): 'x' (1@10-19)
907 sending: 'x' (2@20-29)
908 thing (2@20-29): 'x' (2@20-29)
909 sending: 'x' (3@30-39)
910 30.30-39.38: syntax error, unexpected 'x', expecting ')'
911 Freeing nterm thing (2@20-29)
912 Freeing nterm thing (1@10-19)
913 Freeing token 'x' (3@30-39)
914 sending: 'x' (4@40-49)
915 Freeing token 'x' (4@40-49)
916 sending: 'x' (5@50-59)
917 Freeing token 'x' (5@50-59)
918 sending: ')' (6@60-69)
919 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
920 sending: '(' (7@70-79)
921 sending: 'x' (8@80-89)
922 thing (8@80-89): 'x' (8@80-89)
923 sending: ')' (9@90-99)
924 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
925 sending: '(' (10@100-109)
926 sending: 'x' (11@110-119)
927 thing (11@110-119): 'x' (11@110-119)
928 sending: ')' (12@120-129)
929 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
930 sending: 'y' (13@130-139)
931 input (0@129-129): /* Nothing */
932 input (2@100-129): line (10@100-129) input (0@129-129)
933 input (2@70-129): line (7@70-99) input (2@100-129)
934 input (2@0-129): line (-1@0-69) input (2@70-129)
935 130.130-139.138: syntax error, unexpected 'y', expecting END
936 Freeing nterm input (2@0-129)
937 Freeing token 'y' (13@130-139)
942 # Syntax error caught by the parser where lookahead = END
943 # --------------------------------------------------------
944 # Load the stack and provoke an error that cannot be caught by the
945 # grammar, to check that the stack is cleared. And make sure the
946 # lookahead is freed.
951 AT_PARSER_CHECK([input '(x)(x)x'], 1, [],
952 [[sending: '(' (0@0-9)
953 sending: 'x' (1@10-19)
954 thing (1@10-19): 'x' (1@10-19)
955 sending: ')' (2@20-29)
956 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
957 sending: '(' (3@30-39)
958 sending: 'x' (4@40-49)
959 thing (4@40-49): 'x' (4@40-49)
960 sending: ')' (5@50-59)
961 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
962 sending: 'x' (6@60-69)
963 thing (6@60-69): 'x' (6@60-69)
964 sending: END (7@70-79)
965 70.70-79.78: syntax error, unexpected END, expecting 'x'
966 Freeing nterm thing (6@60-69)
967 Freeing nterm line (3@30-59)
968 Freeing nterm line (0@0-29)
969 Freeing token END (7@70-79)
974 # Check destruction upon stack overflow
975 # -------------------------------------
976 # Upon stack overflow, all symbols on the stack should be destroyed.
977 # Only check for yacc.c.
979 AT_PARSER_CHECK([input '(x)(x)(x)(x)(x)(x)(x)'], 2, [],
980 [[sending: '(' (0@0-9)
981 sending: 'x' (1@10-19)
982 thing (1@10-19): 'x' (1@10-19)
983 sending: ')' (2@20-29)
984 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
985 sending: '(' (3@30-39)
986 sending: 'x' (4@40-49)
987 thing (4@40-49): 'x' (4@40-49)
988 sending: ')' (5@50-59)
989 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
990 sending: '(' (6@60-69)
991 sending: 'x' (7@70-79)
992 thing (7@70-79): 'x' (7@70-79)
993 sending: ')' (8@80-89)
994 line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
995 sending: '(' (9@90-99)
996 sending: 'x' (10@100-109)
997 thing (10@100-109): 'x' (10@100-109)
998 sending: ')' (11@110-119)
999 line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
1000 sending: '(' (12@120-129)
1001 sending: 'x' (13@130-139)
1002 thing (13@130-139): 'x' (13@130-139)
1003 sending: ')' (14@140-149)
1004 line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
1005 sending: '(' (15@150-159)
1006 sending: 'x' (16@160-169)
1007 thing (16@160-169): 'x' (16@160-169)
1008 sending: ')' (17@170-179)
1009 line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
1010 sending: '(' (18@180-189)
1011 sending: 'x' (19@190-199)
1012 thing (19@190-199): 'x' (19@190-199)
1013 sending: ')' (20@200-209)
1014 200.200-209.208: memory exhausted
1015 Freeing nterm thing (19@190-199)
1016 Freeing nterm line (15@150-179)
1017 Freeing nterm line (12@120-149)
1018 Freeing nterm line (9@90-119)
1019 Freeing nterm line (6@60-89)
1020 Freeing nterm line (3@30-59)
1021 Freeing nterm line (0@0-29)
1022 Parsing FAILED (status 2).
1026 AT_BISON_OPTION_POPDEFS
1027 ])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
1030 # AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
1031 # ---------------------------------------------------------------------------
1032 m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR],
1033 [AT_SETUP([Printers and Destructors$2]m4_ifval([$1], [[: $1]]))
1036 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4],
1037 [%define parse.error verbose
1047 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
1048 AT_CHECK_PRINTER_AND_DESTRUCTOR([], [ with union])
1050 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
1051 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [ with union])
1053 AT_CHECK_PRINTER_AND_DESTRUCTOR([%header %skeleton "lalr1.cc"])
1054 AT_CHECK_PRINTER_AND_DESTRUCTOR([%header %skeleton "lalr1.cc"], [ with union])
1056 AT_CHECK_PRINTER_AND_DESTRUCTOR([%header %skeleton "glr.cc"])
1057 AT_CHECK_PRINTER_AND_DESTRUCTOR([%header %skeleton "glr.cc"], [ with union])
1059 AT_CHECK_PRINTER_AND_DESTRUCTOR([%header %skeleton "glr2.cc"])
1060 AT_CHECK_PRINTER_AND_DESTRUCTOR([%header %skeleton "glr2.cc"], [ with union])
1064 ## ----------------------------------------- ##
1065 ## Default tagless %printer and %destructor. ##
1066 ## ----------------------------------------- ##
1068 # Check that the right %printer and %destructor are called, that they're not
1069 # called for $end, and that $$ and @$ work correctly.
1071 AT_SETUP([Default tagless %printer and %destructor])
1072 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
1073 AT_DATA_GRAMMAR([[input.y]],
1074 [[%define parse.error verbose
1080 ]AT_YYERROR_DECLARE[
1085 #error "<*> printer should not be used."
1089 fprintf (yyo, "<> printer for '%c' @ %d", $$, @$.first_column);
1092 printf ("<> destructor for '%c' @ %d.\n", $$, @$.first_column);
1096 fprintf (yyo, "'b'/'c' printer for '%c' @ %d", $$, @$.first_column);
1099 printf ("'b'/'c' destructor for '%c' @ %d.\n", $$, @$.first_column);
1103 #error "<*> destructor should not be used."
1108 start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
1112 ]AT_YYLEX_DEFINE(["abcd"], [[yylval = res]])[
1116 AT_BISON_CHECK([-o input.c input.y], [], [],
1117 [[input.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
1118 input.y:30.3-5: warning: useless %printer for type <*> [-Wother]
1121 AT_PARSER_CHECK([input --debug], 1,
1122 [[<> destructor for 'd' @ 4.
1123 'b'/'c' destructor for 'c' @ 3.
1124 'b'/'c' destructor for 'b' @ 2.
1125 <> destructor for 'a' @ 1.
1131 Next token is token 'a' (1.1: <> printer for 'a' @ 1)
1132 Shifting token 'a' (1.1: <> printer for 'a' @ 1)
1136 Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
1137 Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
1141 Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
1142 Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
1146 Next token is token 'd' (1.4: <> printer for 'd' @ 4)
1147 Shifting token 'd' (1.4: <> printer for 'd' @ 4)
1151 Now at end of input.
1152 1.5: syntax error, unexpected end of file, expecting 'e'
1153 Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
1155 Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
1157 Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
1159 Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
1161 Cleanup: discarding lookahead token "end of file" (1.5: )
1165 AT_BISON_OPTION_POPDEFS
1170 ## ------------------------------------------------------ ##
1171 ## Default tagged and per-type %printer and %destructor. ##
1172 ## ------------------------------------------------------ ##
1174 AT_SETUP([Default tagged and per-type %printer and %destructor])
1175 AT_BISON_OPTION_PUSHDEFS([%debug])
1176 AT_DATA_GRAMMAR([[input.y]],
1177 [[%define parse.error verbose
1181 ]AT_YYERROR_DECLARE[
1187 #error "<> printer should not be used."
1190 %union { int field0; int field1; int field2; }
1191 %type <field0> start 'a' 'g'
1195 fprintf (yyo, "<*>/<field2>/e printer");
1198 printf ("<*>/<field2>/e destructor.\n");
1202 %printer { fprintf (yyo, "<field1> printer"); } <field1>
1203 %destructor { printf ("<field1> destructor.\n"); } <field1>
1206 %printer { fprintf (yyo, "'c' printer"); } 'c'
1207 %destructor { printf ("'c' destructor.\n"); } 'c'
1210 %printer { fprintf (yyo, "'d' printer"); } 'd'
1211 %destructor { printf ("'d' destructor.\n"); } 'd'
1214 #error "<> destructor should not be used."
1220 'a' 'b' 'c' 'd' 'e' 'f' 'g'
1222 USE(($1, $2, $3, $4, $5, $6, $7));
1229 ]AT_YYLEX_DEFINE(["abcdef"])[
1233 AT_BISON_CHECK([-o input.c input.y], [], [],
1234 [[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
1235 input.y:22.3-4: warning: useless %printer for type <> [-Wother]
1238 AT_PARSER_CHECK([input --debug], 1,
1239 [[<*>/<field2>/e destructor.
1240 <*>/<field2>/e destructor.
1243 <field1> destructor.
1244 <*>/<field2>/e destructor.
1250 Next token is token 'a' (<*>/<field2>/e printer)
1251 Shifting token 'a' (<*>/<field2>/e printer)
1255 Next token is token 'b' (<field1> printer)
1256 Shifting token 'b' (<field1> printer)
1260 Next token is token 'c' ('c' printer)
1261 Shifting token 'c' ('c' printer)
1265 Next token is token 'd' ('d' printer)
1266 Shifting token 'd' ('d' printer)
1270 Next token is token 'e' (<*>/<field2>/e printer)
1271 Shifting token 'e' (<*>/<field2>/e printer)
1273 Stack now 0 1 3 5 6 7
1275 Next token is token 'f' (<*>/<field2>/e printer)
1276 Shifting token 'f' (<*>/<field2>/e printer)
1278 Stack now 0 1 3 5 6 7 8
1280 Now at end of input.
1281 syntax error, unexpected end of file, expecting 'g'
1282 Error: popping token 'f' (<*>/<field2>/e printer)
1283 Stack now 0 1 3 5 6 7
1284 Error: popping token 'e' (<*>/<field2>/e printer)
1286 Error: popping token 'd' ('d' printer)
1288 Error: popping token 'c' ('c' printer)
1290 Error: popping token 'b' (<field1> printer)
1292 Error: popping token 'a' (<*>/<field2>/e printer)
1294 Cleanup: discarding lookahead token "end of file" ()
1298 AT_BISON_OPTION_POPDEFS
1303 ## ------------------------------------------------------------- ##
1304 ## Default %printer and %destructor for user-defined end token. ##
1305 ## ------------------------------------------------------------- ##
1307 AT_SETUP([Default %printer and %destructor for user-defined end token])
1309 # Enable declaration of default %printer/%destructor. Make the parser
1310 # use these for all user-declared grammar symbols for which the user
1311 # does not declare a specific %printer/%destructor. Thus, the parser
1312 # uses it for token 0 if the user declares it but not if Bison
1313 # generates it as $end. Discussed starting at
1314 # <https://lists.gnu.org/r/bison-patches/2006-02/msg00064.html>,
1315 # <https://lists.gnu.org/r/bison-patches/2006-06/msg00091.html>, and
1316 # <https://lists.gnu.org/r/bison-patches/2006-07/msg00019.html>.
1320 m4_pushdef([AT_TEST],
1322 [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
1323 [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
1325 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
1326 AT_DATA_GRAMMAR([[input]]$1[[.y]],
1327 [[%define parse.error verbose
1332 ]AT_YYERROR_DECLARE[
1338 #error "<]]not_kind[[> destructor should not be used."
1343 fprintf (yyo, "<]]kind[[> for '%c' @ %d", $$, @$.first_column);
1346 printf ("<]]kind[[> for '%c' @ %d.\n", $$, @$.first_column);
1350 #error "<]]not_kind[[> printer should not be used."
1355 [[[%union { char tag; }
1356 %type <tag> start END]]])[[
1360 start: { $$ = 'S'; } ;
1363 #include <stdlib.h> /* abort */
1370 yylval]]m4_if($1, 0,, [[[.tag]]])[[ = 'E';
1371 yylloc.first_line = yylloc.last_line = 1;
1372 yylloc.first_column = yylloc.last_column = 1;
1378 AT_BISON_OPTION_POPDEFS
1380 AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
1382 [[input0.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
1383 input0.y:30.3-5: warning: useless %printer for type <*> [-Wother]
1385 [[input1.y:30.3-4: warning: useless %destructor for type <> [-Wother]
1386 input1.y:30.3-4: warning: useless %printer for type <> [-Wother]
1389 AT_COMPILE([input$1])
1391 AT_PARSER_CHECK([input$1 --debug], 0,
1392 [[<]]kind[[> for 'E' @ 1.
1393 <]]kind[[> for 'S' @ 1.
1398 Reducing stack by rule 1 (line 49):
1399 -> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
1403 Now at end of input.
1404 Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
1408 Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
1409 Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
1413 m4_popdef([not_kind])
1419 m4_popdef([AT_TEST])
1425 ## ------------------------------------------------------------------ ##
1426 ## Default %printer and %destructor are not for error or $undefined. ##
1427 ## ------------------------------------------------------------------ ##
1429 AT_SETUP([Default %printer and %destructor are not for error or $undefined])
1431 # If Bison were to apply the default %printer and %destructor to the error
1432 # token or to $undefined:
1433 # - For the error token:
1434 # - It would generate warnings for unused $n.
1435 # - It would invoke the %printer and %destructor on the error token's
1436 # semantic value, which would be initialized from the lookahead, which
1437 # would be destroyed separately.
1438 # - For $undefined, who knows what the semantic value would be.
1439 AT_BISON_OPTION_PUSHDEFS([%debug])
1440 AT_DATA_GRAMMAR([[input.y]],
1445 # include <stdlib.h>
1446 ]AT_YYERROR_DECLARE[
1452 fprintf (yyo, "'%c'", $$);
1455 fprintf (stderr, "DESTROY '%c'\n", $$);
1462 /* In order to reveal the problems that this bug caused during parsing, add
1464 | 'a' error 'b' 'c' { USE(($1, $3, $4)); $$ = 'S'; }
1469 ]AT_YYLEX_DEFINE(["abd"], [yylval = res])[
1472 AT_BISON_OPTION_POPDEFS
1474 AT_BISON_CHECK([-o input.c input.y], [], [],
1475 [[input.y:23.6-8: warning: useless %destructor for type <*> [-Wother]
1476 input.y:23.6-8: warning: useless %printer for type <*> [-Wother]
1479 AT_PARSER_CHECK([input --debug], [1], [],
1484 Next token is token 'a' ('a')
1485 Shifting token 'a' ('a')
1489 Next token is token 'b' ('b')
1491 Shifting token error ()
1494 Next token is token 'b' ('b')
1495 Shifting token 'b' ('b')
1499 Next token is token "invalid token" ()
1500 Error: popping token 'b' ('b')
1503 Error: popping token error ()
1505 Shifting token error ()
1508 Next token is token "invalid token" ()
1509 Error: discarding token "invalid token" ()
1510 Error: popping token error ()
1512 Shifting token error ()
1516 Now at end of input.
1517 Cleanup: discarding lookahead token "end of file" ()
1519 Cleanup: popping token error ()
1520 Cleanup: popping token 'a' ('a')
1528 ## ------------------------------------------------------ ##
1529 ## Default %printer and %destructor are not for $accept. ##
1530 ## ------------------------------------------------------ ##
1532 AT_SETUP([Default %printer and %destructor are not for $accept])
1534 # If YYSTYPE is a union and Bison were to apply the default %printer and
1535 # %destructor to $accept:
1536 # - The %printer and %destructor code generated for $accept would always be
1537 # dead code because $accept is currently never shifted onto the stack.
1538 # - $$ for $accept would always be of type YYSTYPE because it's not possible
1539 # to declare '%type <field> $accept'. (Also true for $undefined.)
1540 # - Thus, the compiler might complain that the user code assumes the wrong
1541 # type for $$ since the code might assume the type associated with a
1542 # specific union field, which is especially reasonable in C++ since that
1543 # type may be a base type. This test case checks for this problem. (Also
1544 # true for $undefined and the error token, so there are three warnings for
1545 # %printer and three for %destructor.)
1547 AT_BISON_OPTION_PUSHDEFS([%debug])
1548 AT_DATA_GRAMMAR([[input.y]],
1549 [[%debug /* So that %printer is actually compiled. */
1553 # include <stdlib.h>
1554 ]AT_YYERROR_DECLARE[
1561 fprintf (yyo, "'%c'", chr);
1565 fprintf (stderr, "DESTROY '%c'\n", chr);
1568 %union { char chr; }
1573 start: { USE($$); } ;
1580 AT_BISON_OPTION_POPDEFS
1582 AT_BISON_CHECK([-o input.c input.y], [], [],
1583 [[input.y:24.3-4: warning: useless %destructor for type <> [-Wother]
1584 input.y:24.3-4: warning: useless %printer for type <> [-Wother]
1592 ## ----------------------------------------------------- ##
1593 ## Default %printer and %destructor for midrule values. ##
1594 ## ----------------------------------------------------- ##
1596 AT_SETUP([Default %printer and %destructor for midrule values])
1598 AT_BISON_OPTION_PUSHDEFS([%debug])
1599 AT_DATA_GRAMMAR([[input.y]],
1600 [[%debug /* So that %printer is actually compiled. */
1603 ]AT_YYERROR_DECLARE[
1606 # define YYLTYPE int
1607 # define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
1608 # define LOCATION_PRINT(File, Loc)
1611 %printer { fprintf (yyo, "%d", @$); } <>
1612 %destructor { fprintf (stderr, "DESTROY %d\n", @$); } <>
1613 %printer { #error "<*> printer should not be used" } <*>
1614 %destructor { #error "<*> destructor should not be used" } <*>
1619 { @$ = 1; } // Not set or used.
1620 { USE ($$); @$ = 2; } // Both set and used.
1621 { USE ($$); @$ = 3; } // Only set.
1622 { @$ = 4; } // Only used.
1624 { USE (($$, $2, $4, $5)); @$ = 0; }
1632 AT_BISON_OPTION_POPDEFS
1634 AT_BISON_CHECK([-o input.c input.y], 0,,
1635 [[input.y:24.57-59: warning: useless %destructor for type <*> [-Wother]
1636 input.y:24.57-59: warning: useless %printer for type <*> [-Wother]
1637 input.y:33.3-23: warning: unset value: $$ [-Wother]
1638 input.y:32.3-23: warning: unused value: $3 [-Wother]
1641 AT_BISON_CHECK([-fcaret -o input.c input.y], 0,,
1642 [[input.y:24.57-59: warning: useless %destructor for type <*> [-Wother]
1643 24 | %printer { #error "<*> printer should not be used" } <*>
1645 input.y:24.57-59: warning: useless %printer for type <*> [-Wother]
1646 24 | %printer { #error "<*> printer should not be used" } <*>
1648 input.y:33.3-23: warning: unset value: $$ [-Wother]
1649 33 | { @$ = 4; } // Only used.
1650 | ^~~~~~~~~~~~~~~~~~~~~
1651 input.y:32.3-23: warning: unused value: $3 [-Wother]
1652 32 | { USE ($$); @$ = 3; } // Only set.
1653 | ^~~~~~~~~~~~~~~~~~~~~
1657 AT_PARSER_CHECK([input --debug], 1,,
1661 Reducing stack by rule 1 (line 30):
1662 -> $$ = nterm $@1 (: )
1665 Reducing stack by rule 2 (line 31):
1666 -> $$ = nterm @2 (: 2)
1669 Reducing stack by rule 3 (line 32):
1670 -> $$ = nterm @3 (: 3)
1673 Reducing stack by rule 4 (line 33):
1674 -> $$ = nterm @4 (: 4)
1678 Now at end of input.
1680 Error: popping nterm @4 (: 4)
1683 Error: popping nterm @3 (: 3)
1686 Error: popping nterm @2 (: 2)
1689 Error: popping nterm $@1 (: )
1691 Cleanup: discarding lookahead token "end of file" (: )
1698 ## ----------------------- ##
1699 ## @$ implies %locations. ##
1700 ## ----------------------- ##
1702 # Bison once forgot to check for @$ in actions other than semantic actions.
1704 # AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE)
1705 # -------------------------------------------
1706 m4_define([AT_CHECK_ACTION_LOCATIONS],
1707 [AT_SETUP([[@$ in ]$1[ implies %locations]])
1708 AT_BISON_OPTION_PUSHDEFS([%debug])
1709 AT_DATA_GRAMMAR([[input.y]],
1712 ]AT_YYERROR_DECLARE[
1719 fprintf (stderr, "%d\n", @$.first_line);
1720 } ]m4_if($1, [%initial-action], [], [[start]])[
1738 AT_BISON_CHECK([[-o input.c input.y]])
1739 AT_COMPILE([[input]])
1740 AT_BISON_OPTION_POPDEFS
1743 AT_CHECK_ACTION_LOCATIONS([[%initial-action]])
1744 AT_CHECK_ACTION_LOCATIONS([[%destructor]])
1745 AT_CHECK_ACTION_LOCATIONS([[%printer]])
1748 ## ------------------------- ##
1749 ## Qualified $$ in actions. ##
1750 ## ------------------------- ##
1752 # Check that we can use qualified $$ (v.g., $<type>$) not only in rule
1753 # actions, but also where $$ is valid: %destructor/%printer and
1756 # FIXME: Not actually checking %destructor, but it's the same code as
1759 # To do that, use a semantic value that has two fields (sem_type),
1760 # declare symbols to have only one of these types (INT, float), and
1761 # use $<type>$ to get the other one. Including for symbols that are
1762 # not typed (UNTYPED).
1764 m4_pushdef([AT_TEST],
1765 [AT_SETUP([[Qualified $$ in actions: $1]])
1767 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %debug])
1769 AT_DATA_GRAMMAR([[input.y]],
1774 typedef struct sem_type
1781 # include <cstdio> // EOF.
1782 # include <iostream>
1786 report (std::ostream& yyo, int ival, float fval)
1788 yyo << "ival: " << ival << ", fval: " << fval;
1794 report (FILE* yyo, int ival, float fval)
1796 fprintf (yyo, "ival: %d, fval: %1.1f", ival, fval);
1801 %define api.value.type {sem_type}
1805 ]AT_YYERROR_DECLARE[
1812 %printer { report (yyo, $$, $<fval>$); } <ival>;
1813 %printer { report (yyo, $<ival>$, $$ ); } <fval>;
1814 %printer { report (yyo, $<ival>$, $<fval>$); } <>;
1825 $$ = $<fval>1 + $<fval>2;
1826 $<ival>$ = $<ival>1 + $][2;
1830 ]AT_YYLEX_DEFINE([[{]AT_TOKEN([UNTYPED])[, ]AT_TOKEN([INT])[, EOF}]],
1831 [AT_VAL.ival = toknum * 10;
1832 AT_VAL.fval = YY_CAST (float, toknum) / 10.0f;])[
1836 AT_FULL_COMPILE([[input]])
1837 AT_PARSER_CHECK([input --debug], 0, [], [stderr])
1838 # Don't be too picky on the traces, GLR is not exactly the same. Keep
1839 # only the lines from the printer.
1840 AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
1841 [[Next token is token UNTYPED (ival: 10, fval: 0.1)
1842 Shifting token UNTYPED (ival: 10, fval: 0.1)
1843 Next token is token INT (ival: 20, fval: 0.2)
1844 Shifting token INT (ival: 20, fval: 0.2)
1845 $][1 = token UNTYPED (ival: 10, fval: 0.1)
1846 $][2 = token INT (ival: 20, fval: 0.2)
1847 -> $$ = nterm float (ival: 30, fval: 0.3)
1848 Cleanup: popping nterm float (ival: 30, fval: 0.3)
1851 AT_BISON_OPTION_POPDEFS
1856 m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc], [glr2.cc])
1857 m4_popdef([AT_TEST])
1859 ## -------------------------------------------------- ##
1860 ## Destroying lookahead assigned by semantic action. ##
1861 ## -------------------------------------------------- ##
1863 AT_SETUP([[Destroying lookahead assigned by semantic action]])
1865 AT_BISON_OPTION_PUSHDEFS
1866 AT_DATA_GRAMMAR([input.y],
1871 ]AT_YYERROR_DECLARE[
1876 %destructor { fprintf (stderr, "'a' destructor\n"); } 'a'
1877 %destructor { fprintf (stderr, "'b' destructor\n"); } 'b'
1881 // In a previous version of Bison, yychar assigned by the semantic
1882 // action below was not translated into yytoken before the lookahead was
1883 // discarded and thus before its destructor (selected according to
1884 // yytoken) was called in order to return from yyparse. This would
1885 // happen even if YYACCEPT was performed in a later semantic action as
1886 // long as only consistent states with default reductions were visited
1887 // in between. However, we leave YYACCEPT in the same semantic action
1888 // for this test in order to show that skeletons cannot simply translate
1889 // immediately after every semantic action because a semantic action
1890 // that has set yychar might not always return normally. Instead,
1891 // skeletons must translate before every use of yytoken.
1892 start: 'a' accept { USE($1); } ;
1894 assert (yychar == YYEMPTY);
1901 ]AT_YYLEX_DEFINE(["a"])[
1904 AT_BISON_OPTION_POPDEFS
1905 AT_BISON_CHECK([[-o input.c input.y]])
1906 AT_COMPILE([[input]])
1907 AT_PARSER_CHECK([[input]], [[0]], [],
1918 AT_SETUP([[YYBACKUP]])
1920 AT_BISON_OPTION_PUSHDEFS([%pure-parser %debug])
1922 AT_DATA_GRAMMAR([input.y],
1924 %define parse.error verbose
1929 # include <stdlib.h>
1930 # include <assert.h>
1932 ]AT_YYERROR_DECLARE[
1941 'a' { printf ("a: %d\n", $1); }
1942 | 'b' { YYBACKUP('a', 123); }
1943 | 'c' 'd' { YYBACKUP('a', 456); }
1948 ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[
1951 AT_BISON_OPTION_POPDEFS
1953 AT_BISON_CHECK([[-o input.c input.y]])
1954 AT_COMPILE([[input]])
1955 AT_PARSER_CHECK([[input]], [[0]],