1 e# Executing Actions. -*- Autotest -*-
3 # Copyright (C) 2001-2012 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"])[
61 AT_BISON_OPTION_POPDEFS
63 AT_BISON_CHECK([-d -v -o input.c input.y])
65 AT_PARSER_CHECK([./input], 0,
72 ## ------------------ ##
73 ## Initial location. ##
74 ## ------------------ ##
76 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
77 # -----------------------------------------------------------------------
78 # Check that the initial location is correct.
80 [AT_SETUP([Initial location: $1 $2])
82 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
83 AT_DATA_GRAMMAR([[input.y]],
84 [[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */
93 # include <stdlib.h> /* getenv */
98 exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << std::endl]],
99 [[YY_LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
106 YYUSE(llocp);], [AT_SKEL_CC_IF([
116 p.set_debug_level (!!getenv("YYDEBUG"));
117 return p.parse ();]], [[
118 yydebug = !!getenv("YYDEBUG");
119 return !!yyparse (]AT_PARAM_IF([0])[);]])[
123 AT_FULL_COMPILE([input])
124 AT_PARSER_CHECK([./input], 1, [],
125 [m4_default([$4], [1.1])
126 m4_default([$4], [1.1])[: syntax error
128 AT_BISON_OPTION_POPDEFS
132 ## FIXME: test Java, and iterate over skeletons.
134 AT_TEST([yacc.c], [%define api.pure full])
135 AT_TEST([yacc.c], [%define api.pure %parse-param { int x }])
136 AT_TEST([yacc.c], [%define api.push-pull both])
137 AT_TEST([yacc.c], [%define api.push-pull both %define api.pure full])
139 AT_TEST([glr.c], [%define api.pure])
143 ## A very different test, based on PostgreSQL's implementation of the
145 ## http://lists.gnu.org/archive/html/bug-bison/2012-11/msg00023.html
147 ## Weirdly enough, to trigger the warning with GCC 4.7, we must not
148 ## use fprintf, so run the test twice: once to check the warning
149 ## (absence thereof), and another time to check the value.
150 AT_TEST([yacc.c], [%define api.pure full],
153 # define YY_LOCATION_PRINT(Stream, Loc) \
155 # define YYLLOC_DEFAULT(Current, Rhs, N) \
156 (Current) = ((Rhs)[N ? 1 : 0])
161 AT_TEST([yacc.c], [%define api.pure full],
164 # define YY_LOCATION_PRINT(Stream, Loc) \
165 fprintf ((Stream), "%d", (Loc))
166 # define YYLLOC_DEFAULT(Current, Rhs, N) \
167 (Current) = ((Rhs)[N ? 1 : 0])
177 ## ---------------- ##
178 ## Location Print. ##
179 ## ---------------- ##
181 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
182 # -----------------------------------------------------------------------
183 # Check that the initial location is correct.
184 m4_pushdef([AT_TEST],
185 [AT_SETUP([Location print: $1 $2])
187 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
188 AT_DATA_GRAMMAR([[input.y]],
189 [[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */
198 # include <stdlib.h> /* getenv */
211 #define TEST(L1, C1, L2, C2) \
212 ]AT_LOC_FIRST_LINE[ = L1; \
213 ]AT_LOC_FIRST_COLUMN[ = C1; \
214 ]AT_LOC_LAST_LINE[ = L2; \
215 ]AT_LOC_LAST_COLUMN[ = C2; \
216 ]YY_LOCATION_PRINT(stdout, AT_LOC)[;\
230 AT_FULL_COMPILE([input])
231 AT_PARSER_CHECK([./input], 0,
239 AT_BISON_OPTION_POPDEFS
243 ## FIXME: test Java, and iterate over skeletons.
253 ## ---------------- ##
254 ## Exotic Dollars. ##
255 ## ---------------- ##
257 AT_SETUP([Exotic Dollars])
259 AT_BISON_OPTION_PUSHDEFS
260 AT_DATA_GRAMMAR([[input.y]],
261 [[%define parse.error verbose
274 %type <val> a_1 a_2 a_5
275 sum_of_the_five_previous_values
278 exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
279 sum_of_the_five_previous_values
281 USE (($1, $2, $<foo>3, $<foo>4, $5));
289 sum_of_the_five_previous_values:
291 $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4;
305 AT_BISON_CHECK([-d -v -o input.c input.y], 0)
307 AT_PARSER_CHECK([./input], 0,
311 # Make sure that fields after $n or $-n are parsed correctly. At one
312 # point while implementing dashes in symbol names, we were dropping
314 AT_DATA_GRAMMAR([[input.y]],
320 typedef struct { int val; } stype;
321 # define YYSTYPE stype
325 start: one two { $$.val = $1.val + $2.val; } sum ;
326 one: { $$.val = 1; } ;
327 two: { $$.val = 2; } ;
328 sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ;
340 AT_FULL_COMPILE([input])
341 AT_PARSER_CHECK([[./input]], [[0]],
345 AT_BISON_OPTION_POPDEFS
350 ## -------------------------- ##
351 ## Printers and Destructors. ##
352 ## -------------------------- ##
354 # _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4,
355 # BISON-DIRECTIVE, UNION-FLAG)
356 # -------------------------------------------------------------
357 m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
358 [# Make sure complex $n work.
359 m4_if([$1$2$3$4], $[1]$[2]$[3]$[4], [],
360 [m4_fatal([$0: Invalid arguments: $@])])dnl
362 # Be sure to pass all the %directives to this macro to have correct
363 # helping macros. So don't put any directly in the Bison file.
364 AT_BISON_OPTION_PUSHDEFS([$5])
365 AT_DATA_GRAMMAR([[input.y]],
372 #define YYINITDEPTH 10
373 #define YYMAXDEPTH 10
374 #define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
375 [(Location).first_line, (Location).last_line])[
377 /* Display the symbol type Symbol. */
378 #define V(Symbol, Value, Location, Sep) \
379 fprintf (stderr, #Symbol " (%d@%d-%d)" Sep, Value, RANGE(Location))
383 ]m4_ifval([$6], [%union
387 AT_LALR1_CC_IF([%define global_tokens_and_yystype])
388 m4_ifval([$6], [[%code provides {]], [[%code {]])
389 AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
391 ]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
394 ]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input END])[
396 /* FIXME: This %printer isn't actually tested. */
399 ]AT_LALR1_CC_IF([debug_stream () << $$;],
400 [fprintf (yyoutput, "%d", $$)])[;
402 input line thing 'x' 'y'
405 { fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
409 { fprintf (stderr, "Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
413 { fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
417 { fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
421 { fprintf (stderr, "Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
426 { fprintf (stderr, "Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
431 This grammar is made to exercise error recovery.
432 "Lines" starting with `(' support error recovery, with
433 ')' as synchronizing token. Lines starting with 'x' can never
434 be recovered from if in error.
441 V(input, $$, @$, ": /* Nothing */\n");
443 | line input /* Right recursive to load the stack so that popping at
444 END can be exercised. */
447 V(input, $$, @$, ": ");
448 V(line, $1, @1, " ");
449 V(input, $2, @2, "\n");
454 thing thing thing ';'
457 V(line, $$, @$, ": ");
458 V(thing, $1, @1, " ");
459 V(thing, $2, @2, " ");
460 V(thing, $3, @3, " ");
463 | '(' thing thing ')'
466 V(line, $$, @$, ": ");
468 V(thing, $2, @2, " ");
469 V(thing, $3, @3, " ");
470 V(')', $4, @4, "\n");
475 V(line, $$, @$, ": ");
477 V(thing, $2, @2, " ");
478 V(')', $3, @3, "\n");
483 V(line, $$, @$, ": ");
485 fprintf (stderr, "error (@%d-%d) ", RANGE(@2));
486 V(')', $3, @3, "\n");
494 V(thing, $$, @$, ": ");
495 V('x', $1, @1, "\n");
499 /* Alias to ARGV[1]. */
500 const char *source = YY_NULL;
507 static unsigned int counter = 0;
509 int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
510 /* As in BASIC, line numbers go from 10 to 10. */
511 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
512 ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
513 assert (0 <= c && c <= strlen (source));
515 fprintf (stderr, "sending: '%c'", source[c]);
517 fprintf (stderr, "sending: END");
518 fprintf (stderr, " (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
522 [static bool yydebug;
527 parser.set_debug_level (yydebug);
528 return parser.parse ();
533 main (int argc, const char *argv[])
536 yydebug = !!getenv ("YYDEBUG");
542 case 0: fprintf (stderr, "Successful parse.\n"); break;
543 case 1: fprintf (stderr, "Parsing FAILED.\n"); break;
544 default: fprintf (stderr, "Parsing FAILED (status %d).\n", status); break;
550 AT_FULL_COMPILE([input])
553 # Check the location of "empty"
554 # -----------------------------
555 # I.e., epsilon-reductions, as in "(x)" which ends by reducing
556 # an empty "line" nterm.
557 # FIXME: This location is not satisfying. Depend on the lookahead?
558 AT_PARSER_CHECK([./input '(x)'], 0, [],
559 [[sending: '(' (0@0-9)
560 sending: 'x' (1@10-19)
561 thing (1@10-19): 'x' (1@10-19)
562 sending: ')' (2@20-29)
563 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
564 sending: END (3@30-39)
565 input (0@29-29): /* Nothing */
566 input (2@0-29): line (0@0-29) input (0@29-29)
567 Freeing token END (3@30-39)
568 Freeing nterm input (2@0-29)
573 # Check locations in error recovery
574 # ---------------------------------
575 # '(y)' is an error, but can be recovered from. But what's the location
576 # of the error itself ('y'), and of the resulting reduction ('(error)').
577 AT_PARSER_CHECK([./input '(y)'], 0, [],
578 [[sending: '(' (0@0-9)
579 sending: 'y' (1@10-19)
580 10.10-19.18: syntax error, unexpected 'y', expecting 'x'
581 Freeing token 'y' (1@10-19)
582 sending: ')' (2@20-29)
583 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
584 sending: END (3@30-39)
585 input (0@29-29): /* Nothing */
586 input (2@0-29): line (-1@0-29) input (0@29-29)
587 Freeing token END (3@30-39)
588 Freeing nterm input (2@0-29)
593 # Syntax errors caught by the parser
594 # ----------------------------------
595 # Exercise the discarding of stack top and input until `error'
598 # '(', 'x', 'x', 'x', 'x', 'x', ')',
600 # Load the stack and provoke an error that cannot be caught by the
601 # grammar, to check that the stack is cleared. And make sure the
602 # lookahead is freed.
607 AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1, [],
608 [[sending: '(' (0@0-9)
609 sending: 'x' (1@10-19)
610 thing (1@10-19): 'x' (1@10-19)
611 sending: 'x' (2@20-29)
612 thing (2@20-29): 'x' (2@20-29)
613 sending: 'x' (3@30-39)
614 30.30-39.38: syntax error, unexpected 'x', expecting ')'
615 Freeing nterm thing (2@20-29)
616 Freeing nterm thing (1@10-19)
617 Freeing token 'x' (3@30-39)
618 sending: 'x' (4@40-49)
619 Freeing token 'x' (4@40-49)
620 sending: 'x' (5@50-59)
621 Freeing token 'x' (5@50-59)
622 sending: ')' (6@60-69)
623 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
624 sending: '(' (7@70-79)
625 sending: 'x' (8@80-89)
626 thing (8@80-89): 'x' (8@80-89)
627 sending: ')' (9@90-99)
628 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
629 sending: '(' (10@100-109)
630 sending: 'x' (11@110-119)
631 thing (11@110-119): 'x' (11@110-119)
632 sending: ')' (12@120-129)
633 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
634 sending: 'y' (13@130-139)
635 input (0@129-129): /* Nothing */
636 input (2@100-129): line (10@100-129) input (0@129-129)
637 input (2@70-129): line (7@70-99) input (2@100-129)
638 input (2@0-129): line (-1@0-69) input (2@70-129)
639 130.130-139.138: syntax error, unexpected 'y', expecting END
640 Freeing nterm input (2@0-129)
641 Freeing token 'y' (13@130-139)
646 # Syntax error caught by the parser where lookahead = END
647 # --------------------------------------------------------
648 # Load the stack and provoke an error that cannot be caught by the
649 # grammar, to check that the stack is cleared. And make sure the
650 # lookahead is freed.
655 AT_PARSER_CHECK([./input '(x)(x)x'], 1, [],
656 [[sending: '(' (0@0-9)
657 sending: 'x' (1@10-19)
658 thing (1@10-19): 'x' (1@10-19)
659 sending: ')' (2@20-29)
660 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
661 sending: '(' (3@30-39)
662 sending: 'x' (4@40-49)
663 thing (4@40-49): 'x' (4@40-49)
664 sending: ')' (5@50-59)
665 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
666 sending: 'x' (6@60-69)
667 thing (6@60-69): 'x' (6@60-69)
668 sending: END (7@70-79)
669 70.70-79.78: syntax error, unexpected END, expecting 'x'
670 Freeing nterm thing (6@60-69)
671 Freeing nterm line (3@30-59)
672 Freeing nterm line (0@0-29)
673 Freeing token END (7@70-79)
678 # Check destruction upon stack overflow
679 # -------------------------------------
680 # Upon stack overflow, all symbols on the stack should be destroyed.
681 # Only check for yacc.c.
683 AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2, [],
684 [[sending: '(' (0@0-9)
685 sending: 'x' (1@10-19)
686 thing (1@10-19): 'x' (1@10-19)
687 sending: ')' (2@20-29)
688 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
689 sending: '(' (3@30-39)
690 sending: 'x' (4@40-49)
691 thing (4@40-49): 'x' (4@40-49)
692 sending: ')' (5@50-59)
693 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
694 sending: '(' (6@60-69)
695 sending: 'x' (7@70-79)
696 thing (7@70-79): 'x' (7@70-79)
697 sending: ')' (8@80-89)
698 line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
699 sending: '(' (9@90-99)
700 sending: 'x' (10@100-109)
701 thing (10@100-109): 'x' (10@100-109)
702 sending: ')' (11@110-119)
703 line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
704 sending: '(' (12@120-129)
705 sending: 'x' (13@130-139)
706 thing (13@130-139): 'x' (13@130-139)
707 sending: ')' (14@140-149)
708 line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
709 sending: '(' (15@150-159)
710 sending: 'x' (16@160-169)
711 thing (16@160-169): 'x' (16@160-169)
712 sending: ')' (17@170-179)
713 line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
714 sending: '(' (18@180-189)
715 sending: 'x' (19@190-199)
716 thing (19@190-199): 'x' (19@190-199)
717 sending: ')' (20@200-209)
718 200.200-209.208: memory exhausted
719 Freeing nterm thing (19@190-199)
720 Freeing nterm line (15@150-179)
721 Freeing nterm line (12@120-149)
722 Freeing nterm line (9@90-119)
723 Freeing nterm line (6@60-89)
724 Freeing nterm line (3@30-59)
725 Freeing nterm line (0@0-29)
726 Parsing FAILED (status 2).
730 AT_BISON_OPTION_POPDEFS
731 ])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
734 # AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
735 # ---------------------------------------------------------------------------
736 m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR],
737 [AT_SETUP([Printers and Destructors$2]m4_ifval([$1], [[: $1]]))
740 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4],
741 [%define parse.error verbose
751 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
752 AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union])
754 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"])
755 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union])
757 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
758 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
762 ## ----------------------------------------- ##
763 ## Default tagless %printer and %destructor. ##
764 ## ----------------------------------------- ##
766 # Check that the right %printer and %destructor are called, that they're not
767 # called for $end, and that $$ and @$ work correctly.
769 AT_SETUP([Default tagless %printer and %destructor])
770 AT_BISON_OPTION_PUSHDEFS([%locations])
771 AT_DATA_GRAMMAR([[input.y]],
772 [[%define parse.error verbose
785 fprintf (yyoutput, "<*> printer should not be called.\n");
789 fprintf (yyoutput, "<> printer for '%c' @ %d", $$, @$.first_column);
792 fprintf (stdout, "<> destructor for '%c' @ %d.\n", $$, @$.first_column);
796 fprintf (yyoutput, "'b'/'c' printer for '%c' @ %d", $$, @$.first_column);
799 fprintf (stdout, "'b'/'c' destructor for '%c' @ %d.\n", $$, @$.first_column);
803 fprintf (yyoutput, "<*> destructor should not be called.\n");
808 start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
812 ]AT_YYLEX_DEFINE(["abcd"], [[yylval = res]])[
822 AT_BISON_CHECK([-o input.c input.y], [], [],
823 [[input.y:23.3-5: warning: useless %destructor for type <*> [-Wother]
824 input.y:23.3-5: warning: useless %printer for type <*> [-Wother]
827 AT_PARSER_CHECK([./input], 1,
828 [[<> destructor for 'd' @ 4.
829 'b'/'c' destructor for 'c' @ 3.
830 'b'/'c' destructor for 'b' @ 2.
831 <> destructor for 'a' @ 1.
835 Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1)
836 Shifting token 'a' (1.1: <> printer for 'a' @ 1)
838 Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
839 Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
841 Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
842 Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
844 Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4)
845 Shifting token 'd' (1.4: <> printer for 'd' @ 4)
847 Reading a token: Now at end of input.
848 1.5: syntax error, unexpected $end, expecting 'e'
849 Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
851 Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
853 Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
855 Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
857 Cleanup: discarding lookahead token $end (1.5: )
861 AT_BISON_OPTION_POPDEFS
866 ## ------------------------------------------------------ ##
867 ## Default tagged and per-type %printer and %destructor. ##
868 ## ------------------------------------------------------ ##
870 AT_SETUP([Default tagged and per-type %printer and %destructor])
871 AT_BISON_OPTION_PUSHDEFS
872 AT_DATA_GRAMMAR([[input.y]],
873 [[%define parse.error verbose
885 fprintf (yyoutput, "<> printer should not be called.\n");
888 %union { int field0; int field1; int field2; }
889 %type <field0> start 'a' 'g'
893 fprintf (yyoutput, "<*>/<field2>/e printer");
896 fprintf (stdout, "<*>/<field2>/e destructor.\n");
900 %printer { fprintf (yyoutput, "<field1> printer"); } <field1>
901 %destructor { fprintf (stdout, "<field1> destructor.\n"); } <field1>
904 %printer { fprintf (yyoutput, "'c' printer"); } 'c'
905 %destructor { fprintf (stdout, "'c' destructor.\n"); } 'c'
908 %printer { fprintf (yyoutput, "'d' printer"); } 'd'
909 %destructor { fprintf (stdout, "'d' destructor.\n"); } 'd'
912 fprintf (yyoutput, "<> destructor should not be called.\n");
918 'a' 'b' 'c' 'd' 'e' 'f' 'g'
920 USE(($1, $2, $3, $4, $5, $6, $7));
927 ]AT_YYLEX_DEFINE(["abcdef"])[
937 AT_BISON_CHECK([-o input.c input.y], [], [],
938 [[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
939 input.y:22.3-4: warning: useless %printer for type <> [-Wother]
942 AT_PARSER_CHECK([./input], 1,
943 [[<*>/<field2>/e destructor.
944 <*>/<field2>/e destructor.
948 <*>/<field2>/e destructor.
952 Reading a token: Next token is token 'a' (<*>/<field2>/e printer)
953 Shifting token 'a' (<*>/<field2>/e printer)
955 Reading a token: Next token is token 'b' (<field1> printer)
956 Shifting token 'b' (<field1> printer)
958 Reading a token: Next token is token 'c' ('c' printer)
959 Shifting token 'c' ('c' printer)
961 Reading a token: Next token is token 'd' ('d' printer)
962 Shifting token 'd' ('d' printer)
964 Reading a token: Next token is token 'e' (<*>/<field2>/e printer)
965 Shifting token 'e' (<*>/<field2>/e printer)
967 Reading a token: Next token is token 'f' (<*>/<field2>/e printer)
968 Shifting token 'f' (<*>/<field2>/e printer)
970 Reading a token: Now at end of input.
971 syntax error, unexpected $end, expecting 'g'
972 Error: popping token 'f' (<*>/<field2>/e printer)
973 Stack now 0 1 3 5 6 7
974 Error: popping token 'e' (<*>/<field2>/e printer)
976 Error: popping token 'd' ('d' printer)
978 Error: popping token 'c' ('c' printer)
980 Error: popping token 'b' (<field1> printer)
982 Error: popping token 'a' (<*>/<field2>/e printer)
984 Cleanup: discarding lookahead token $end ()
988 AT_BISON_OPTION_POPDEFS
993 ## ------------------------------------------------------------- ##
994 ## Default %printer and %destructor for user-defined end token. ##
995 ## ------------------------------------------------------------- ##
997 AT_SETUP([Default %printer and %destructor for user-defined end token])
1001 m4_pushdef([AT_TEST],
1003 [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
1004 [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
1006 AT_BISON_OPTION_PUSHDEFS([%locations])
1007 AT_DATA_GRAMMAR([[input]]$1[[.y]],
1008 [[%define parse.error verbose
1014 # include <stdlib.h>
1015 ]AT_YYERROR_DECLARE[
1021 fprintf (yyoutput, "<]]not_kind[[> destructor should not be called.\n");
1026 fprintf (yyoutput, "<]]kind[[> for '%c' @ %d", $$, @$.first_column);
1029 fprintf (stdout, "<]]kind[[> for '%c' @ %d.\n", $$, @$.first_column);
1033 fprintf (yyoutput, "<]]not_kind[[> printer should not be called.\n");
1038 [[[%union { char tag; }
1039 %type <tag> start END]]])[[
1043 start: { $$ = 'S'; } ;
1053 yylval]]m4_if($1, 0,, [[[.tag]]])[[ = 'E';
1054 yylloc.first_line = yylloc.last_line = 1;
1055 yylloc.first_column = yylloc.last_column = 1;
1067 AT_BISON_OPTION_POPDEFS
1069 AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
1071 [[input0.y:23.3-5: warning: useless %destructor for type <*> [-Wother]
1072 input0.y:23.3-5: warning: useless %printer for type <*> [-Wother]
1074 [[input1.y:23.3-4: warning: useless %destructor for type <> [-Wother]
1075 input1.y:23.3-4: warning: useless %printer for type <> [-Wother]
1078 AT_COMPILE([input$1])
1080 AT_PARSER_CHECK([./input$1], 0,
1081 [[<]]kind[[> for 'E' @ 1.
1082 <]]kind[[> for 'S' @ 1.
1086 Reducing stack by rule 1 (line 42):
1087 -> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
1090 Reading a token: Now at end of input.
1091 Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
1094 Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
1095 Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
1099 m4_popdef([not_kind])
1105 m4_popdef([AT_TEST])
1111 ## ------------------------------------------------------------------ ##
1112 ## Default %printer and %destructor are not for error or $undefined. ##
1113 ## ------------------------------------------------------------------ ##
1115 AT_SETUP([Default %printer and %destructor are not for error or $undefined])
1117 # If Bison were to apply the default %printer and %destructor to the error
1118 # token or to $undefined:
1119 # - For the error token:
1120 # - It would generate warnings for unused $n.
1121 # - It would invoke the %printer and %destructor on the error token's
1122 # semantic value, which would be initialized from the lookahead, which
1123 # would be destroyed separately.
1124 # - For $undefined, who knows what the semantic value would be.
1125 AT_BISON_OPTION_PUSHDEFS
1126 AT_DATA_GRAMMAR([[input.y]],
1131 # include <stdlib.h>
1132 ]AT_YYERROR_DECLARE[
1138 fprintf (yyoutput, "'%c'", $$);
1141 fprintf (stderr, "DESTROY '%c'\n", $$);
1148 /* In order to reveal the problems that this bug caused during parsing, add
1150 | 'a' error 'b' 'c' { USE(($1, $3, $4)); $$ = 'S'; }
1155 ]AT_YYLEX_DEFINE(["abd"], [yylval = res])[
1163 AT_BISON_OPTION_POPDEFS
1165 AT_BISON_CHECK([-o input.c input.y], [], [],
1166 [[input.y:21.6-8: warning: useless %destructor for type <*> [-Wother]
1167 input.y:21.6-8: warning: useless %printer for type <*> [-Wother]
1170 AT_PARSER_CHECK([./input], [1], [],
1173 Reading a token: Next token is token 'a' ('a')
1174 Shifting token 'a' ('a')
1176 Reading a token: Next token is token 'b' ('b')
1178 Shifting token error ()
1180 Next token is token 'b' ('b')
1181 Shifting token 'b' ('b')
1183 Reading a token: Next token is token $undefined ()
1184 Error: popping token 'b' ('b')
1187 Error: popping token error ()
1189 Shifting token error ()
1191 Next token is token $undefined ()
1192 Error: discarding token $undefined ()
1193 Error: popping token error ()
1195 Shifting token error ()
1197 Reading a token: Now at end of input.
1198 Cleanup: discarding lookahead token $end ()
1200 Cleanup: popping token error ()
1201 Cleanup: popping token 'a' ('a')
1209 ## ------------------------------------------------------ ##
1210 ## Default %printer and %destructor are not for $accept. ##
1211 ## ------------------------------------------------------ ##
1213 AT_SETUP([Default %printer and %destructor are not for $accept])
1215 # If YYSTYPE is a union and Bison were to apply the default %printer and
1216 # %destructor to $accept:
1217 # - The %printer and %destructor code generated for $accept would always be
1218 # dead code because $accept is currently never shifted onto the stack.
1219 # - $$ for $accept would always be of type YYSTYPE because it's not possible
1220 # to declare `%type <field> $accept'. (Also true for $undefined.)
1221 # - Thus, the compiler might complain that the user code assumes the wrong
1222 # type for $$ since the code might assume the type associated with a
1223 # specific union field, which is especially reasonable in C++ since that
1224 # type may be a base type. This test case checks for this problem. (Also
1225 # true for $undefined and the error token, so there are three warnings for
1226 # %printer and three for %destructor.)
1228 AT_BISON_OPTION_PUSHDEFS
1229 AT_DATA_GRAMMAR([[input.y]],
1230 [[%debug /* So that %printer is actually compiled. */
1234 # include <stdlib.h>
1235 ]AT_YYERROR_DECLARE[
1242 fprintf (yyoutput, "'%c'", chr);
1246 fprintf (stderr, "DESTROY '%c'\n", chr);
1249 %union { char chr; }
1254 start: { USE($$); } ;
1265 AT_BISON_OPTION_POPDEFS
1267 AT_BISON_CHECK([-o input.c input.y], [], [],
1268 [[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
1269 input.y:22.3-4: warning: useless %printer for type <> [-Wother]
1277 ## ------------------------------------------------------ ##
1278 ## Default %printer and %destructor for mid-rule values. ##
1279 ## ------------------------------------------------------ ##
1281 AT_SETUP([Default %printer and %destructor for mid-rule values])
1283 AT_BISON_OPTION_PUSHDEFS
1284 AT_DATA_GRAMMAR([[input.y]],
1285 [[%debug /* So that %printer is actually compiled. */
1289 # include <stdlib.h>
1290 ]AT_YYERROR_DECLARE[
1293 # define YYLTYPE int
1294 # define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
1295 # define YY_LOCATION_PRINT(File, Loc)
1298 %printer { fprintf (yyoutput, "%d", @$); } <>
1299 %destructor { fprintf (stderr, "DESTROY %d\n", @$); } <>
1300 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1301 %destructor { fprintf (yyoutput, "<*> destructor should not be called"); } <*>
1306 { @$ = 1; } // Not set or used.
1307 { USE ($$); @$ = 2; } // Both set and used.
1308 { USE ($$); @$ = 3; } // Only set.
1309 { @$ = 4; } // Only used.
1311 { USE (($$, $2, $4, $5)); @$ = 0; }
1324 AT_BISON_OPTION_POPDEFS
1326 AT_BISON_CHECK([-o input.c input.y], 0,,
1327 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1328 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1329 input.y:33.3-23: warning: unset value: $$ [-Wother]
1330 input.y:32.3-23: warning: unused value: $3 [-Wother]
1333 AT_BISON_CHECK([-fcaret -o input.c input.y], 0,,
1334 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1335 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1337 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1338 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1340 input.y:33.3-23: warning: unset value: $$ [-Wother]
1341 { @$ = 4; } // Only used.
1342 ^^^^^^^^^^^^^^^^^^^^^
1343 input.y:32.3-23: warning: unused value: $3 [-Wother]
1344 { USE ($$); @$ = 3; } // Only set.
1345 ^^^^^^^^^^^^^^^^^^^^^
1349 AT_PARSER_CHECK([./input], 1,,
1352 Reducing stack by rule 1 (line 30):
1353 -> $$ = nterm $@1 (: )
1356 Reducing stack by rule 2 (line 31):
1357 -> $$ = nterm @2 (: 2)
1360 Reducing stack by rule 3 (line 32):
1361 -> $$ = nterm @3 (: 3)
1364 Reducing stack by rule 4 (line 33):
1365 -> $$ = nterm @4 (: 4)
1368 Reading a token: Now at end of input.
1370 Error: popping nterm @4 (: 4)
1373 Error: popping nterm @3 (: 3)
1376 Error: popping nterm @2 (: 2)
1379 Error: popping nterm $@1 (: )
1381 Cleanup: discarding lookahead token $end (: )
1388 ## ----------------------- ##
1389 ## @$ implies %locations. ##
1390 ## ----------------------- ##
1392 # Bison once forgot to check for @$ in actions other than semantic actions.
1394 # AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE)
1395 # -------------------------------------------
1396 m4_define([AT_CHECK_ACTION_LOCATIONS],
1397 [AT_SETUP([[@$ in ]$1[ implies %locations]])
1398 AT_BISON_OPTION_PUSHDEFS
1399 AT_DATA_GRAMMAR([[input.y]],
1402 ]AT_YYERROR_DECLARE[
1409 fprintf (stderr, "%d\n", @$.first_line);
1410 } ]m4_if($1, [%initial-action], [], [[start]])[
1432 AT_BISON_CHECK([[-o input.c input.y]])
1433 AT_COMPILE([[input]])
1434 AT_BISON_OPTION_POPDEFS
1437 AT_CHECK_ACTION_LOCATIONS([[%initial-action]])
1438 AT_CHECK_ACTION_LOCATIONS([[%destructor]])
1439 AT_CHECK_ACTION_LOCATIONS([[%printer]])
1442 ## ------------------------- ##
1443 ## Qualified $$ in actions. ##
1444 ## ------------------------- ##
1446 # Check that we can use qualified $$ (v.g., $<type>$) not only in rule
1447 # actions, but also where $$ is valid: %destructor/%printer and
1450 # FIXME: Not actually checking %destructor, but it's the same code as
1453 # To do that, use a semantic value that has two fields (sem_type),
1454 # declare symbols to have only one of these types (INT, float), and
1455 # use $<type>$ to get the other one. Including for symbols that are
1456 # not typed (UNTYPED).
1458 m4_pushdef([AT_TEST],
1459 [AT_SETUP([[Qualified $$ in actions: $1]])
1461 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1"])
1463 AT_DATA_GRAMMAR([[input.y]],
1468 typedef struct sem_type
1474 # define YYSTYPE sem_type
1477 # include <iostream>
1479 report (std::ostream& yyo, int ival, float fval)
1481 yyo << "ival: " << ival << ", fval: " << fval;
1486 report (FILE* yyo, int ival, float fval)
1488 fprintf (yyo, "ival: %d, fval: %1.1f", ival, fval);
1495 ]AT_YYERROR_DECLARE[
1502 %printer { report (yyo, $$, $<fval>$); } <ival>;
1503 %printer { report (yyo, $<ival>$, $$ ); } <fval>;
1504 %printer { report (yyo, $<ival>$, $<fval>$); } <>;
1515 $$ = $<fval>1 + $<fval>2;
1516 $<ival>$ = $<ival>1 + $][2;
1520 ]AT_YYLEX_DEFINE(AT_SKEL_CC_IF([[{yy::parser::token::UNTYPED,
1521 yy::parser::token::INT,
1523 [[{UNTYPED, INT, EOF}]]),
1524 [AT_VAL.ival = toknum * 10; AT_VAL.fval = toknum / 10.0;])[
1529 p.set_debug_level(1);
1530 return p.parse ();]], [[
1532 return yyparse ();]])[
1536 AT_FULL_COMPILE([[input]])
1537 AT_PARSER_CHECK([./input], 0, [], [stderr])
1538 # Don't be too picky on the traces, GLR is not exactly the same. Keep
1539 # only the lines from the printer.
1540 AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
1541 [[Reading a token: Next token is token UNTYPED (ival: 10, fval: 0.1)
1542 Shifting token UNTYPED (ival: 10, fval: 0.1)
1543 Reading a token: Next token is token INT (ival: 20, fval: 0.2)
1544 Shifting token INT (ival: 20, fval: 0.2)
1545 $][1 = token UNTYPED (ival: 10, fval: 0.1)
1546 $][2 = token INT (ival: 20, fval: 0.2)
1547 -> $$ = nterm float (ival: 30, fval: 0.3)
1548 Cleanup: popping nterm float (ival: 30, fval: 0.3)
1551 AT_BISON_OPTION_POPDEFS
1561 m4_popdef([AT_TEST])
1563 ## ----------------------------------------------- ##
1564 ## Fix user actions without a trailing semicolon. ##
1565 ## ----------------------------------------------- ##
1567 AT_SETUP([[Fix user actions without a trailing semicolon]])
1569 # This feature is undocumented, but we accidentally broke it in 2.3a,
1570 # and there was a complaint at:
1571 # <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
1572 AT_BISON_OPTION_PUSHDEFS
1575 start: test2 test1 test0 testc;
1578 : 'a' { semi; /* TEST:N:2 */ }
1579 | 'b' { if (0) {no_semi} /* TEST:N:2 */ }
1580 | 'c' { if (0) {semi;} /* TEST:N:2 */ }
1581 | 'd' { semi; no_semi /* TEST:Y:2 */ }
1582 | 'e' { semi(); no_semi() /* TEST:Y:2 */ }
1583 | 'f' { semi[]; no_semi[] /* TEST:Y:2 */ }
1584 | 'g' { semi++; no_semi++ /* TEST:Y:2 */ }
1585 | 'h' { {no_semi} no_semi /* TEST:Y:2 */ }
1586 | 'i' { {semi;} no_semi /* TEST:Y:2 */ }
1589 : 'a' { semi; // TEST:N:1 ;
1590 } | 'b' { if (0) {no_semi} // TEST:N:1 ;
1591 } | 'c' { if (0) {semi;} // TEST:N:1 ;
1592 } | 'd' { semi; no_semi // TEST:Y:1 ;
1593 } | 'e' { semi(); no_semi() // TEST:Y:1 ;
1594 } | 'f' { semi[]; no_semi[] // TEST:Y:1 ;
1595 } | 'g' { semi++; no_semi++ // TEST:Y:1 ;
1596 } | 'h' { {no_semi} no_semi // TEST:Y:1 ;
1597 } | 'i' { {semi;} no_semi // TEST:Y:1 ;
1600 : 'a' { semi; // TEST:N:1 {}
1601 } | 'b' { if (0) {no_semi} // TEST:N:1 {}
1602 } | 'c' { if (0) {semi;} // TEST:N:1 {}
1603 } | 'd' { semi; no_semi // TEST:Y:1 {}
1604 } | 'e' { semi(); no_semi() // TEST:Y:1 {}
1605 } | 'f' { semi[]; no_semi[] // TEST:Y:1 {}
1606 } | 'g' { semi++; no_semi++ // TEST:Y:1 {}
1607 } | 'h' { {no_semi} no_semi // TEST:Y:1 {}
1608 } | 'i' { {semi;} no_semi // TEST:Y:1 {}
1613 #define TEST_MACRO_N \
1614 []"broken\" $ @ $$ @$ [];\
1618 #define TEST_MACRO_N \
1619 []"broken\" $ @ $$ @$ [];\
1622 AT_BISON_OPTION_POPDEFS
1624 AT_BISON_CHECK([[-o input.c input.y]], [0], [],
1625 [[input.y:8.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1626 input.y:8.48: future versions of Bison will not add the ';'
1627 input.y:9.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1628 input.y:9.48: future versions of Bison will not add the ';'
1629 input.y:10.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1630 input.y:10.48: future versions of Bison will not add the ';'
1631 input.y:11.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1632 input.y:11.48: future versions of Bison will not add the ';'
1633 input.y:12.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1634 input.y:12.48: future versions of Bison will not add the ';'
1635 input.y:13.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1636 input.y:13.48: future versions of Bison will not add the ';'
1637 input.y:20.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1638 input.y:20.1: future versions of Bison will not add the ';'
1639 input.y:21.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1640 input.y:21.1: future versions of Bison will not add the ';'
1641 input.y:22.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1642 input.y:22.1: future versions of Bison will not add the ';'
1643 input.y:23.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1644 input.y:23.1: future versions of Bison will not add the ';'
1645 input.y:24.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1646 input.y:24.1: future versions of Bison will not add the ';'
1647 input.y:25.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1648 input.y:25.1: future versions of Bison will not add the ';'
1649 input.y:31.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1650 input.y:31.1: future versions of Bison will not add the ';'
1651 input.y:32.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1652 input.y:32.1: future versions of Bison will not add the ';'
1653 input.y:33.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1654 input.y:33.1: future versions of Bison will not add the ';'
1655 input.y:34.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1656 input.y:34.1: future versions of Bison will not add the ';'
1657 input.y:35.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1658 input.y:35.1: future versions of Bison will not add the ';'
1659 input.y:36.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1660 input.y:36.1: future versions of Bison will not add the ';'
1663 AT_MATCHES_CHECK([input.c], [[/\* TEST:N:2 \*/ \}$]], [[3]])
1664 AT_MATCHES_CHECK([input.c], [[/\* TEST:Y:2 \*/ ;\}$]], [[6]])
1665 AT_MATCHES_CHECK([input.c], [[// TEST:N:1 [;{}]*\n\}$]], [[6]])
1666 AT_MATCHES_CHECK([input.c], [[// TEST:Y:1 [;{}]*\n;\}$]], [[12]])
1667 AT_MATCHES_CHECK([input.c], [[#define TEST_MACRO_N \\\n\[\]"broken\\" \$ \@ \$\$ \@\$ \[\];\\\nstring;"\}]], [[2]])
1672 ## -------------------------------------------------- ##
1673 ## Destroying lookahead assigned by semantic action. ##
1674 ## -------------------------------------------------- ##
1676 AT_SETUP([[Destroying lookahead assigned by semantic action]])
1678 AT_BISON_OPTION_PUSHDEFS
1679 AT_DATA_GRAMMAR([input.y],
1684 ]AT_YYERROR_DECLARE[
1689 %destructor { fprintf (stderr, "'a' destructor\n"); } 'a'
1690 %destructor { fprintf (stderr, "'b' destructor\n"); } 'b'
1694 // In a previous version of Bison, yychar assigned by the semantic
1695 // action below was not translated into yytoken before the lookahead was
1696 // discarded and thus before its destructor (selected according to
1697 // yytoken) was called in order to return from yyparse. This would
1698 // happen even if YYACCEPT was performed in a later semantic action as
1699 // long as only consistent states with default reductions were visited
1700 // in between. However, we leave YYACCEPT in the same semantic action
1701 // for this test in order to show that skeletons cannot simply translate
1702 // immediately after every semantic action because a semantic action
1703 // that has set yychar might not always return normally. Instead,
1704 // skeletons must translate before every use of yytoken.
1705 start: 'a' accept { USE($1); } ;
1707 assert (yychar == YYEMPTY);
1714 ]AT_YYLEX_DEFINE(["a"])[
1721 AT_BISON_OPTION_POPDEFS
1722 AT_BISON_CHECK([[-o input.c input.y]])
1723 AT_COMPILE([[input]])
1724 AT_PARSER_CHECK([[./input]], [[0]], [],
1735 AT_SETUP([[YYBACKUP]])
1737 AT_BISON_OPTION_PUSHDEFS([%pure-parser])
1739 AT_DATA_GRAMMAR([input.y],
1746 # include <stdlib.h>
1747 # include <assert.h>
1749 ]AT_YYERROR_DECLARE[
1758 'a' { printf ("a: %d\n", $1); }
1759 | 'b' { YYBACKUP('a', 123); }
1760 | 'c' 'd' { YYBACKUP('a', 456); }
1765 ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[
1770 yydebug = !!getenv("YYDEBUG");
1774 AT_BISON_OPTION_POPDEFS
1776 AT_BISON_CHECK([[-o input.c input.y]])
1777 AT_COMPILE([[input]])
1778 AT_PARSER_CHECK([[./input]], [[0]],