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,
68 ## ------------------ ##
69 ## Initial location. ##
70 ## ------------------ ##
72 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
73 # -----------------------------------------------------------------------
74 # Check that the initial location is correct.
76 [AT_SETUP([Initial location: $1 $2])
78 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
79 AT_DATA_GRAMMAR([[input.y]],
80 [[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */
89 # include <stdlib.h> /* getenv */
94 exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << std::endl]],
95 [[LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
102 YYUSE(llocp);], [AT_SKEL_CC_IF([
112 p.set_debug_level (!!getenv("YYDEBUG"));
113 return p.parse ();]], [[
114 yydebug = !!getenv("YYDEBUG");
115 return !!yyparse (]AT_PARAM_IF([0])[);]])[
119 AT_FULL_COMPILE([input])
120 AT_PARSER_CHECK([./input], 1, [],
121 [m4_default([$4], [1.1])
122 m4_default([$4], [1.1])[: syntax error
124 AT_BISON_OPTION_POPDEFS
128 ## FIXME: test Java, and iterate over skeletons.
130 AT_TEST([yacc.c], [%define api.pure full])
131 AT_TEST([yacc.c], [%define api.pure %parse-param { int x }])
132 AT_TEST([yacc.c], [%define api.push-pull both])
133 AT_TEST([yacc.c], [%define api.push-pull both %define api.pure full])
135 AT_TEST([glr.c], [%define api.pure])
139 ## A very different test, based on PostgreSQL's implementation of the
141 ## http://lists.gnu.org/archive/html/bug-bison/2012-11/msg00023.html
143 ## Weirdly enough, to trigger the warning with GCC 4.7, we must not
144 ## use fprintf, so run the test twice: once to check the warning
145 ## (absence thereof), and another time to check the value.
146 AT_TEST([yacc.c], [%define api.pure full],
149 # define LOCATION_PRINT(Stream, Loc) \
151 # define YYLLOC_DEFAULT(Current, Rhs, N) \
152 (Current) = ((Rhs)[N ? 1 : 0])
157 AT_TEST([yacc.c], [%define api.pure full],
160 # define LOCATION_PRINT(Stream, Loc) \
161 fprintf ((Stream), "%d", (Loc))
162 # define YYLLOC_DEFAULT(Current, Rhs, N) \
163 (Current) = ((Rhs)[N ? 1 : 0])
173 ## ---------------- ##
174 ## Location Print. ##
175 ## ---------------- ##
177 # AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
178 # -----------------------------------------------------------------------
179 # Check that the initial location is correct.
180 m4_pushdef([AT_TEST],
181 [AT_SETUP([Location print: $1 $2])
183 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
184 AT_DATA_GRAMMAR([[input.y]],
185 [[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */
206 ]AT_GLR_CC_IF([loc.initialize();])[
207 #define TEST(L1, C1, L2, C2) \
208 loc.]AT_FIRST_LINE[ = L1; \
209 loc.]AT_FIRST_COLUMN[ = C1; \
210 loc.]AT_LAST_LINE[ = L2; \
211 loc.]AT_LAST_COLUMN[ = C2; \
212 ]AT_SKEL_CC_IF([std::cout << loc],
213 [LOCATION_PRINT(stdout, loc)])[;\
227 AT_FULL_COMPILE([input])
228 AT_PARSER_CHECK([./input], 0,
236 AT_BISON_OPTION_POPDEFS
240 ## FIXME: test Java, and iterate over skeletons.
250 ## ---------------- ##
251 ## Exotic Dollars. ##
252 ## ---------------- ##
254 AT_SETUP([Exotic Dollars])
256 AT_BISON_OPTION_PUSHDEFS
257 AT_DATA_GRAMMAR([[input.y]],
258 [[%define parse.error verbose
271 %type <val> a_1 a_2 a_5
272 sum_of_the_five_previous_values
275 exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
276 sum_of_the_five_previous_values
278 USE (($1, $2, $<foo>3, $<foo>4, $5));
286 sum_of_the_five_previous_values:
288 $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4;
298 AT_BISON_CHECK([-d -v -o input.c input.y], 0)
300 AT_PARSER_CHECK([./input], 0,
304 # Make sure that fields after $n or $-n are parsed correctly. At one
305 # point while implementing dashes in symbol names, we were dropping
307 AT_DATA_GRAMMAR([[input.y]],
312 typedef struct { int val; } stype;
313 # define YYSTYPE stype
317 start: one two { $$.val = $1.val + $2.val; } sum ;
318 one: { $$.val = 1; } ;
319 two: { $$.val = 2; } ;
320 sum: { printf ("%d\n", $0.val + $-1.val + $-2.val); } ;
328 AT_FULL_COMPILE([input])
329 AT_PARSER_CHECK([[./input]], [[0]],
333 AT_BISON_OPTION_POPDEFS
338 ## -------------------------- ##
339 ## Printers and Destructors. ##
340 ## -------------------------- ##
342 # _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4,
343 # BISON-DIRECTIVE, UNION-FLAG)
344 # -------------------------------------------------------------
345 m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
346 [# Make sure complex $n work.
347 m4_if([$1$2$3$4], $[1]$[2]$[3]$[4], [],
348 [m4_fatal([$0: Invalid arguments: $@])])dnl
350 # Be sure to pass all the %directives to this macro to have correct
351 # helping macros. So don't put any directly in the Bison file.
352 AT_BISON_OPTION_PUSHDEFS([$5])
353 AT_DATA_GRAMMAR([[input.y]],
360 #define YYINITDEPTH 10
361 #define YYMAXDEPTH 10
362 #define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
363 [(Location).first_line, (Location).last_line])[
365 /* Display the symbol type Symbol. */
366 #define V(Symbol, Value, Location, Sep) \
367 fprintf (stderr, #Symbol " (%d@%d-%d)" Sep, Value, RANGE(Location))
371 ]m4_ifval([$6], [%union
375 AT_LALR1_CC_IF([%define global_tokens_and_yystype])
376 m4_ifval([$6], [[%code provides {]], [[%code {]])
377 AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
379 ]AT_LALR1_CC_IF([], [AT_YYERROR_DECLARE])
382 ]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input END])[
384 /* FIXME: This %printer isn't actually tested. */
387 ]AT_LALR1_CC_IF([debug_stream () << $$;],
388 [fprintf (yyoutput, "%d", $$)])[;
390 input line thing 'x' 'y'
393 { fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
397 { fprintf (stderr, "Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
401 { fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
405 { fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
409 { fprintf (stderr, "Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
414 { fprintf (stderr, "Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
419 This grammar is made to exercise error recovery.
420 "Lines" starting with `(' support error recovery, with
421 ')' as synchronizing token. Lines starting with 'x' can never
422 be recovered from if in error.
429 V(input, $$, @$, ": /* Nothing */\n");
431 | line input /* Right recursive to load the stack so that popping at
432 END can be exercised. */
435 V(input, $$, @$, ": ");
436 V(line, $1, @1, " ");
437 V(input, $2, @2, "\n");
442 thing thing thing ';'
445 V(line, $$, @$, ": ");
446 V(thing, $1, @1, " ");
447 V(thing, $2, @2, " ");
448 V(thing, $3, @3, " ");
451 | '(' thing thing ')'
454 V(line, $$, @$, ": ");
456 V(thing, $2, @2, " ");
457 V(thing, $3, @3, " ");
458 V(')', $4, @4, "\n");
463 V(line, $$, @$, ": ");
465 V(thing, $2, @2, " ");
466 V(')', $3, @3, "\n");
471 V(line, $$, @$, ": ");
473 fprintf (stderr, "error (@%d-%d) ", RANGE(@2));
474 V(')', $3, @3, "\n");
482 V(thing, $$, @$, ": ");
483 V('x', $1, @1, "\n");
487 /* Alias to ARGV[1]. */
488 const char *source = YY_NULL;
495 static unsigned int counter = 0;
497 int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
498 /* As in BASIC, line numbers go from 10 to 10. */
499 ]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
500 ]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
501 assert (0 <= c && c <= strlen (source));
503 fprintf (stderr, "sending: '%c'", source[c]);
505 fprintf (stderr, "sending: END");
506 fprintf (stderr, " (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
510 [static bool yydebug;
515 parser.set_debug_level (yydebug);
516 return parser.parse ();
521 main (int argc, const char *argv[])
524 yydebug = !!getenv ("YYDEBUG");
530 case 0: fprintf (stderr, "Successful parse.\n"); break;
531 case 1: fprintf (stderr, "Parsing FAILED.\n"); break;
532 default: fprintf (stderr, "Parsing FAILED (status %d).\n", status); break;
538 AT_FULL_COMPILE([input])
541 # Check the location of "empty"
542 # -----------------------------
543 # I.e., epsilon-reductions, as in "(x)" which ends by reducing
544 # an empty "line" nterm.
545 # FIXME: This location is not satisfying. Depend on the lookahead?
546 AT_PARSER_CHECK([./input '(x)'], 0, [],
547 [[sending: '(' (0@0-9)
548 sending: 'x' (1@10-19)
549 thing (1@10-19): 'x' (1@10-19)
550 sending: ')' (2@20-29)
551 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
552 sending: END (3@30-39)
553 input (0@29-29): /* Nothing */
554 input (2@0-29): line (0@0-29) input (0@29-29)
555 Freeing token END (3@30-39)
556 Freeing nterm input (2@0-29)
561 # Check locations in error recovery
562 # ---------------------------------
563 # '(y)' is an error, but can be recovered from. But what's the location
564 # of the error itself ('y'), and of the resulting reduction ('(error)').
565 AT_PARSER_CHECK([./input '(y)'], 0, [],
566 [[sending: '(' (0@0-9)
567 sending: 'y' (1@10-19)
568 10.10-19.18: syntax error, unexpected 'y', expecting 'x'
569 Freeing token 'y' (1@10-19)
570 sending: ')' (2@20-29)
571 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
572 sending: END (3@30-39)
573 input (0@29-29): /* Nothing */
574 input (2@0-29): line (-1@0-29) input (0@29-29)
575 Freeing token END (3@30-39)
576 Freeing nterm input (2@0-29)
581 # Syntax errors caught by the parser
582 # ----------------------------------
583 # Exercise the discarding of stack top and input until `error'
586 # '(', 'x', 'x', 'x', 'x', 'x', ')',
588 # Load the stack and provoke an error that cannot be caught by the
589 # grammar, to check that the stack is cleared. And make sure the
590 # lookahead is freed.
595 AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1, [],
596 [[sending: '(' (0@0-9)
597 sending: 'x' (1@10-19)
598 thing (1@10-19): 'x' (1@10-19)
599 sending: 'x' (2@20-29)
600 thing (2@20-29): 'x' (2@20-29)
601 sending: 'x' (3@30-39)
602 30.30-39.38: syntax error, unexpected 'x', expecting ')'
603 Freeing nterm thing (2@20-29)
604 Freeing nterm thing (1@10-19)
605 Freeing token 'x' (3@30-39)
606 sending: 'x' (4@40-49)
607 Freeing token 'x' (4@40-49)
608 sending: 'x' (5@50-59)
609 Freeing token 'x' (5@50-59)
610 sending: ')' (6@60-69)
611 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
612 sending: '(' (7@70-79)
613 sending: 'x' (8@80-89)
614 thing (8@80-89): 'x' (8@80-89)
615 sending: ')' (9@90-99)
616 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
617 sending: '(' (10@100-109)
618 sending: 'x' (11@110-119)
619 thing (11@110-119): 'x' (11@110-119)
620 sending: ')' (12@120-129)
621 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
622 sending: 'y' (13@130-139)
623 input (0@129-129): /* Nothing */
624 input (2@100-129): line (10@100-129) input (0@129-129)
625 input (2@70-129): line (7@70-99) input (2@100-129)
626 input (2@0-129): line (-1@0-69) input (2@70-129)
627 130.130-139.138: syntax error, unexpected 'y', expecting END
628 Freeing nterm input (2@0-129)
629 Freeing token 'y' (13@130-139)
634 # Syntax error caught by the parser where lookahead = END
635 # --------------------------------------------------------
636 # Load the stack and provoke an error that cannot be caught by the
637 # grammar, to check that the stack is cleared. And make sure the
638 # lookahead is freed.
643 AT_PARSER_CHECK([./input '(x)(x)x'], 1, [],
644 [[sending: '(' (0@0-9)
645 sending: 'x' (1@10-19)
646 thing (1@10-19): 'x' (1@10-19)
647 sending: ')' (2@20-29)
648 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
649 sending: '(' (3@30-39)
650 sending: 'x' (4@40-49)
651 thing (4@40-49): 'x' (4@40-49)
652 sending: ')' (5@50-59)
653 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
654 sending: 'x' (6@60-69)
655 thing (6@60-69): 'x' (6@60-69)
656 sending: END (7@70-79)
657 70.70-79.78: syntax error, unexpected END, expecting 'x'
658 Freeing nterm thing (6@60-69)
659 Freeing nterm line (3@30-59)
660 Freeing nterm line (0@0-29)
661 Freeing token END (7@70-79)
666 # Check destruction upon stack overflow
667 # -------------------------------------
668 # Upon stack overflow, all symbols on the stack should be destroyed.
669 # Only check for yacc.c.
671 AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2, [],
672 [[sending: '(' (0@0-9)
673 sending: 'x' (1@10-19)
674 thing (1@10-19): 'x' (1@10-19)
675 sending: ')' (2@20-29)
676 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
677 sending: '(' (3@30-39)
678 sending: 'x' (4@40-49)
679 thing (4@40-49): 'x' (4@40-49)
680 sending: ')' (5@50-59)
681 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
682 sending: '(' (6@60-69)
683 sending: 'x' (7@70-79)
684 thing (7@70-79): 'x' (7@70-79)
685 sending: ')' (8@80-89)
686 line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
687 sending: '(' (9@90-99)
688 sending: 'x' (10@100-109)
689 thing (10@100-109): 'x' (10@100-109)
690 sending: ')' (11@110-119)
691 line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
692 sending: '(' (12@120-129)
693 sending: 'x' (13@130-139)
694 thing (13@130-139): 'x' (13@130-139)
695 sending: ')' (14@140-149)
696 line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
697 sending: '(' (15@150-159)
698 sending: 'x' (16@160-169)
699 thing (16@160-169): 'x' (16@160-169)
700 sending: ')' (17@170-179)
701 line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
702 sending: '(' (18@180-189)
703 sending: 'x' (19@190-199)
704 thing (19@190-199): 'x' (19@190-199)
705 sending: ')' (20@200-209)
706 200.200-209.208: memory exhausted
707 Freeing nterm thing (19@190-199)
708 Freeing nterm line (15@150-179)
709 Freeing nterm line (12@120-149)
710 Freeing nterm line (9@90-119)
711 Freeing nterm line (6@60-89)
712 Freeing nterm line (3@30-59)
713 Freeing nterm line (0@0-29)
714 Parsing FAILED (status 2).
718 AT_BISON_OPTION_POPDEFS
719 ])# _AT_CHECK_PRINTER_AND_DESTRUCTOR
722 # AT_CHECK_PRINTER_AND_DESTRUCTOR([BISON-OPTIONS], [UNION-FLAG], [SKIP_FLAG])
723 # ---------------------------------------------------------------------------
724 m4_define([AT_CHECK_PRINTER_AND_DESTRUCTOR],
725 [AT_SETUP([Printers and Destructors$2]m4_ifval([$1], [[: $1]]))
728 _AT_CHECK_PRINTER_AND_DESTRUCTOR($[1], $[2], $[3], $[4],
729 [%define parse.error verbose
739 AT_CHECK_PRINTER_AND_DESTRUCTOR([])
740 AT_CHECK_PRINTER_AND_DESTRUCTOR([], [with union])
742 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"])
743 AT_CHECK_PRINTER_AND_DESTRUCTOR([%defines %skeleton "lalr1.cc"], [with union])
745 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser])
746 AT_CHECK_PRINTER_AND_DESTRUCTOR([%glr-parser], [with union])
750 ## ----------------------------------------- ##
751 ## Default tagless %printer and %destructor. ##
752 ## ----------------------------------------- ##
754 # Check that the right %printer and %destructor are called, that they're not
755 # called for $end, and that $$ and @$ work correctly.
757 AT_SETUP([Default tagless %printer and %destructor])
758 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
759 AT_DATA_GRAMMAR([[input.y]],
760 [[%define parse.error verbose
771 fprintf (yyoutput, "<*> printer should not be called.\n");
775 fprintf (yyoutput, "<> printer for '%c' @ %d", $$, @$.first_column);
778 fprintf (stdout, "<> destructor for '%c' @ %d.\n", $$, @$.first_column);
782 fprintf (yyoutput, "'b'/'c' printer for '%c' @ %d", $$, @$.first_column);
785 fprintf (stdout, "'b'/'c' destructor for '%c' @ %d.\n", $$, @$.first_column);
789 fprintf (yyoutput, "<*> destructor should not be called.\n");
794 start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
798 ]AT_YYLEX_DEFINE(["abcd"], [[yylval = res]])[
802 AT_BISON_CHECK([-o input.c input.y], [], [],
803 [[input.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
804 input.y:30.3-5: warning: useless %printer for type <*> [-Wother]
807 AT_PARSER_CHECK([./input --debug], 1,
808 [[<> destructor for 'd' @ 4.
809 'b'/'c' destructor for 'c' @ 3.
810 'b'/'c' destructor for 'b' @ 2.
811 <> destructor for 'a' @ 1.
815 Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1)
816 Shifting token 'a' (1.1: <> printer for 'a' @ 1)
818 Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
819 Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
821 Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
822 Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
824 Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4)
825 Shifting token 'd' (1.4: <> printer for 'd' @ 4)
827 Reading a token: Now at end of input.
828 1.5: syntax error, unexpected $end, expecting 'e'
829 Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
831 Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
833 Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
835 Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
837 Cleanup: discarding lookahead token $end (1.5: )
841 AT_BISON_OPTION_POPDEFS
846 ## ------------------------------------------------------ ##
847 ## Default tagged and per-type %printer and %destructor. ##
848 ## ------------------------------------------------------ ##
850 AT_SETUP([Default tagged and per-type %printer and %destructor])
851 AT_BISON_OPTION_PUSHDEFS([%debug])
852 AT_DATA_GRAMMAR([[input.y]],
853 [[%define parse.error verbose
863 fprintf (yyoutput, "<> printer should not be called.\n");
866 %union { int field0; int field1; int field2; }
867 %type <field0> start 'a' 'g'
871 fprintf (yyoutput, "<*>/<field2>/e printer");
874 fprintf (stdout, "<*>/<field2>/e destructor.\n");
878 %printer { fprintf (yyoutput, "<field1> printer"); } <field1>
879 %destructor { fprintf (stdout, "<field1> destructor.\n"); } <field1>
882 %printer { fprintf (yyoutput, "'c' printer"); } 'c'
883 %destructor { fprintf (stdout, "'c' destructor.\n"); } 'c'
886 %printer { fprintf (yyoutput, "'d' printer"); } 'd'
887 %destructor { fprintf (stdout, "'d' destructor.\n"); } 'd'
890 fprintf (yyoutput, "<> destructor should not be called.\n");
896 'a' 'b' 'c' 'd' 'e' 'f' 'g'
898 USE(($1, $2, $3, $4, $5, $6, $7));
905 ]AT_YYLEX_DEFINE(["abcdef"])[
909 AT_BISON_CHECK([-o input.c input.y], [], [],
910 [[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
911 input.y:22.3-4: warning: useless %printer for type <> [-Wother]
914 AT_PARSER_CHECK([./input --debug], 1,
915 [[<*>/<field2>/e destructor.
916 <*>/<field2>/e destructor.
920 <*>/<field2>/e destructor.
924 Reading a token: Next token is token 'a' (<*>/<field2>/e printer)
925 Shifting token 'a' (<*>/<field2>/e printer)
927 Reading a token: Next token is token 'b' (<field1> printer)
928 Shifting token 'b' (<field1> printer)
930 Reading a token: Next token is token 'c' ('c' printer)
931 Shifting token 'c' ('c' printer)
933 Reading a token: Next token is token 'd' ('d' printer)
934 Shifting token 'd' ('d' printer)
936 Reading a token: Next token is token 'e' (<*>/<field2>/e printer)
937 Shifting token 'e' (<*>/<field2>/e printer)
939 Reading a token: Next token is token 'f' (<*>/<field2>/e printer)
940 Shifting token 'f' (<*>/<field2>/e printer)
942 Reading a token: Now at end of input.
943 syntax error, unexpected $end, expecting 'g'
944 Error: popping token 'f' (<*>/<field2>/e printer)
945 Stack now 0 1 3 5 6 7
946 Error: popping token 'e' (<*>/<field2>/e printer)
948 Error: popping token 'd' ('d' printer)
950 Error: popping token 'c' ('c' printer)
952 Error: popping token 'b' (<field1> printer)
954 Error: popping token 'a' (<*>/<field2>/e printer)
956 Cleanup: discarding lookahead token $end ()
960 AT_BISON_OPTION_POPDEFS
965 ## ------------------------------------------------------------- ##
966 ## Default %printer and %destructor for user-defined end token. ##
967 ## ------------------------------------------------------------- ##
969 AT_SETUP([Default %printer and %destructor for user-defined end token])
973 m4_pushdef([AT_TEST],
975 [m4_pushdef([kind], []) m4_pushdef([not_kind], [*])],
976 [m4_pushdef([kind], [*]) m4_pushdef([not_kind], [])])
978 AT_BISON_OPTION_PUSHDEFS([%locations %debug])
979 AT_DATA_GRAMMAR([[input]]$1[[.y]],
980 [[%define parse.error verbose
991 fprintf (yyoutput, "<]]not_kind[[> destructor should not be called.\n");
996 fprintf (yyoutput, "<]]kind[[> for '%c' @ %d", $$, @$.first_column);
999 fprintf (stdout, "<]]kind[[> for '%c' @ %d.\n", $$, @$.first_column);
1003 fprintf (yyoutput, "<]]not_kind[[> printer should not be called.\n");
1008 [[[%union { char tag; }
1009 %type <tag> start END]]])[[
1013 start: { $$ = 'S'; } ;
1016 #include <stdlib.h> // abort
1023 yylval]]m4_if($1, 0,, [[[.tag]]])[[ = 'E';
1024 yylloc.first_line = yylloc.last_line = 1;
1025 yylloc.first_column = yylloc.last_column = 1;
1031 AT_BISON_OPTION_POPDEFS
1033 AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
1035 [[input0.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
1036 input0.y:30.3-5: warning: useless %printer for type <*> [-Wother]
1038 [[input1.y:30.3-4: warning: useless %destructor for type <> [-Wother]
1039 input1.y:30.3-4: warning: useless %printer for type <> [-Wother]
1042 AT_COMPILE([input$1])
1044 AT_PARSER_CHECK([./input$1 --debug], 0,
1045 [[<]]kind[[> for 'E' @ 1.
1046 <]]kind[[> for 'S' @ 1.
1050 Reducing stack by rule 1 (line 49):
1051 -> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
1054 Reading a token: Now at end of input.
1055 Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
1058 Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
1059 Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
1063 m4_popdef([not_kind])
1069 m4_popdef([AT_TEST])
1075 ## ------------------------------------------------------------------ ##
1076 ## Default %printer and %destructor are not for error or $undefined. ##
1077 ## ------------------------------------------------------------------ ##
1079 AT_SETUP([Default %printer and %destructor are not for error or $undefined])
1081 # If Bison were to apply the default %printer and %destructor to the error
1082 # token or to $undefined:
1083 # - For the error token:
1084 # - It would generate warnings for unused $n.
1085 # - It would invoke the %printer and %destructor on the error token's
1086 # semantic value, which would be initialized from the lookahead, which
1087 # would be destroyed separately.
1088 # - For $undefined, who knows what the semantic value would be.
1089 AT_BISON_OPTION_PUSHDEFS([%debug])
1090 AT_DATA_GRAMMAR([[input.y]],
1095 # include <stdlib.h>
1096 ]AT_YYERROR_DECLARE[
1102 fprintf (yyoutput, "'%c'", $$);
1105 fprintf (stderr, "DESTROY '%c'\n", $$);
1112 /* In order to reveal the problems that this bug caused during parsing, add
1114 | 'a' error 'b' 'c' { USE(($1, $3, $4)); $$ = 'S'; }
1119 ]AT_YYLEX_DEFINE(["abd"], [yylval = res])[
1122 AT_BISON_OPTION_POPDEFS
1124 AT_BISON_CHECK([-o input.c input.y], [], [],
1125 [[input.y:23.6-8: warning: useless %destructor for type <*> [-Wother]
1126 input.y:23.6-8: warning: useless %printer for type <*> [-Wother]
1129 AT_PARSER_CHECK([./input --debug], [1], [],
1132 Reading a token: Next token is token 'a' ('a')
1133 Shifting token 'a' ('a')
1135 Reading a token: Next token is token 'b' ('b')
1137 Shifting token error ()
1139 Next token is token 'b' ('b')
1140 Shifting token 'b' ('b')
1142 Reading a token: Next token is token $undefined ()
1143 Error: popping token 'b' ('b')
1146 Error: popping token error ()
1148 Shifting token error ()
1150 Next token is token $undefined ()
1151 Error: discarding token $undefined ()
1152 Error: popping token error ()
1154 Shifting token error ()
1156 Reading a token: Now at end of input.
1157 Cleanup: discarding lookahead token $end ()
1159 Cleanup: popping token error ()
1160 Cleanup: popping token 'a' ('a')
1168 ## ------------------------------------------------------ ##
1169 ## Default %printer and %destructor are not for $accept. ##
1170 ## ------------------------------------------------------ ##
1172 AT_SETUP([Default %printer and %destructor are not for $accept])
1174 # If YYSTYPE is a union and Bison were to apply the default %printer and
1175 # %destructor to $accept:
1176 # - The %printer and %destructor code generated for $accept would always be
1177 # dead code because $accept is currently never shifted onto the stack.
1178 # - $$ for $accept would always be of type YYSTYPE because it's not possible
1179 # to declare `%type <field> $accept'. (Also true for $undefined.)
1180 # - Thus, the compiler might complain that the user code assumes the wrong
1181 # type for $$ since the code might assume the type associated with a
1182 # specific union field, which is especially reasonable in C++ since that
1183 # type may be a base type. This test case checks for this problem. (Also
1184 # true for $undefined and the error token, so there are three warnings for
1185 # %printer and three for %destructor.)
1187 AT_BISON_OPTION_PUSHDEFS([%debug])
1188 AT_DATA_GRAMMAR([[input.y]],
1189 [[%debug /* So that %printer is actually compiled. */
1193 # include <stdlib.h>
1194 ]AT_YYERROR_DECLARE[
1201 fprintf (yyoutput, "'%c'", chr);
1205 fprintf (stderr, "DESTROY '%c'\n", chr);
1208 %union { char chr; }
1213 start: { USE($$); } ;
1220 AT_BISON_OPTION_POPDEFS
1222 AT_BISON_CHECK([-o input.c input.y], [], [],
1223 [[input.y:24.3-4: warning: useless %destructor for type <> [-Wother]
1224 input.y:24.3-4: warning: useless %printer for type <> [-Wother]
1232 ## ------------------------------------------------------ ##
1233 ## Default %printer and %destructor for mid-rule values. ##
1234 ## ------------------------------------------------------ ##
1236 AT_SETUP([Default %printer and %destructor for mid-rule values])
1238 AT_BISON_OPTION_PUSHDEFS([%debug])
1239 AT_DATA_GRAMMAR([[input.y]],
1240 [[%debug /* So that %printer is actually compiled. */
1243 ]AT_YYERROR_DECLARE[
1246 # define YYLTYPE int
1247 # define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
1248 # define LOCATION_PRINT(File, Loc)
1251 %printer { fprintf (yyoutput, "%d", @$); } <>
1252 %destructor { fprintf (stderr, "DESTROY %d\n", @$); } <>
1253 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1254 %destructor { fprintf (yyoutput, "<*> destructor should not be called"); } <*>
1259 { @$ = 1; } // Not set or used.
1260 { USE ($$); @$ = 2; } // Both set and used.
1261 { USE ($$); @$ = 3; } // Only set.
1262 { @$ = 4; } // Only used.
1264 { USE (($$, $2, $4, $5)); @$ = 0; }
1272 AT_BISON_OPTION_POPDEFS
1274 AT_BISON_CHECK([-o input.c input.y], 0,,
1275 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1276 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1277 input.y:33.3-23: warning: unset value: $$ [-Wother]
1278 input.y:32.3-23: warning: unused value: $3 [-Wother]
1281 AT_BISON_CHECK([-fcaret -o input.c input.y], 0,,
1282 [[input.y:24.70-72: warning: useless %destructor for type <*> [-Wother]
1283 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1285 input.y:24.70-72: warning: useless %printer for type <*> [-Wother]
1286 %printer { fprintf (yyoutput, "<*> printer should not be called"); } <*>
1288 input.y:33.3-23: warning: unset value: $$ [-Wother]
1289 { @$ = 4; } // Only used.
1290 ^^^^^^^^^^^^^^^^^^^^^
1291 input.y:32.3-23: warning: unused value: $3 [-Wother]
1292 { USE ($$); @$ = 3; } // Only set.
1293 ^^^^^^^^^^^^^^^^^^^^^
1297 AT_PARSER_CHECK([./input --debug], 1,,
1300 Reducing stack by rule 1 (line 30):
1301 -> $$ = nterm $@1 (: )
1304 Reducing stack by rule 2 (line 31):
1305 -> $$ = nterm @2 (: 2)
1308 Reducing stack by rule 3 (line 32):
1309 -> $$ = nterm @3 (: 3)
1312 Reducing stack by rule 4 (line 33):
1313 -> $$ = nterm @4 (: 4)
1316 Reading a token: Now at end of input.
1318 Error: popping nterm @4 (: 4)
1321 Error: popping nterm @3 (: 3)
1324 Error: popping nterm @2 (: 2)
1327 Error: popping nterm $@1 (: )
1329 Cleanup: discarding lookahead token $end (: )
1336 ## ----------------------- ##
1337 ## @$ implies %locations. ##
1338 ## ----------------------- ##
1340 # Bison once forgot to check for @$ in actions other than semantic actions.
1342 # AT_CHECK_ACTION_LOCATIONS(ACTION-DIRECTIVE)
1343 # -------------------------------------------
1344 m4_define([AT_CHECK_ACTION_LOCATIONS],
1345 [AT_SETUP([[@$ in ]$1[ implies %locations]])
1346 AT_BISON_OPTION_PUSHDEFS([%debug])
1347 AT_DATA_GRAMMAR([[input.y]],
1350 ]AT_YYERROR_DECLARE[
1357 fprintf (stderr, "%d\n", @$.first_line);
1358 } ]m4_if($1, [%initial-action], [], [[start]])[
1376 AT_BISON_CHECK([[-o input.c input.y]])
1377 AT_COMPILE([[input]])
1378 AT_BISON_OPTION_POPDEFS
1381 AT_CHECK_ACTION_LOCATIONS([[%initial-action]])
1382 AT_CHECK_ACTION_LOCATIONS([[%destructor]])
1383 AT_CHECK_ACTION_LOCATIONS([[%printer]])
1386 ## ------------------------- ##
1387 ## Qualified $$ in actions. ##
1388 ## ------------------------- ##
1390 # Check that we can use qualified $$ (v.g., $<type>$) not only in rule
1391 # actions, but also where $$ is valid: %destructor/%printer and
1394 # FIXME: Not actually checking %destructor, but it's the same code as
1397 # To do that, use a semantic value that has two fields (sem_type),
1398 # declare symbols to have only one of these types (INT, float), and
1399 # use $<type>$ to get the other one. Including for symbols that are
1400 # not typed (UNTYPED).
1402 m4_pushdef([AT_TEST],
1403 [AT_SETUP([[Qualified $$ in actions: $1]])
1405 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %debug])
1407 AT_DATA_GRAMMAR([[input.y]],
1412 typedef struct sem_type
1418 # define YYSTYPE sem_type
1421 # include <iostream>
1423 report (std::ostream& yyo, int ival, float fval)
1425 yyo << "ival: " << ival << ", fval: " << fval;
1430 report (FILE* yyo, int ival, float fval)
1432 fprintf (yyo, "ival: %d, fval: %1.1f", ival, fval);
1439 ]AT_YYERROR_DECLARE[
1446 %printer { report (yyo, $$, $<fval>$); } <ival>;
1447 %printer { report (yyo, $<ival>$, $$ ); } <fval>;
1448 %printer { report (yyo, $<ival>$, $<fval>$); } <>;
1459 $$ = $<fval>1 + $<fval>2;
1460 $<ival>$ = $<ival>1 + $][2;
1464 ]AT_YYLEX_DEFINE(AT_SKEL_CC_IF([[{yy::parser::token::UNTYPED,
1465 yy::parser::token::INT,
1467 [[{UNTYPED, INT, EOF}]]),
1468 [AT_VAL.ival = toknum * 10; AT_VAL.fval = toknum / 10.0;])[
1472 AT_FULL_COMPILE([[input]])
1473 AT_PARSER_CHECK([./input --debug], 0, [], [stderr])
1474 # Don't be too picky on the traces, GLR is not exactly the same. Keep
1475 # only the lines from the printer.
1476 AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
1477 [[Reading a token: Next token is token UNTYPED (ival: 10, fval: 0.1)
1478 Shifting token UNTYPED (ival: 10, fval: 0.1)
1479 Reading a token: Next token is token INT (ival: 20, fval: 0.2)
1480 Shifting token INT (ival: 20, fval: 0.2)
1481 $][1 = token UNTYPED (ival: 10, fval: 0.1)
1482 $][2 = token INT (ival: 20, fval: 0.2)
1483 -> $$ = nterm float (ival: 30, fval: 0.3)
1484 Cleanup: popping nterm float (ival: 30, fval: 0.3)
1487 AT_BISON_OPTION_POPDEFS
1497 m4_popdef([AT_TEST])
1499 ## ----------------------------------------------- ##
1500 ## Fix user actions without a trailing semicolon. ##
1501 ## ----------------------------------------------- ##
1503 AT_SETUP([[Fix user actions without a trailing semicolon]])
1505 # This feature is undocumented, but we accidentally broke it in 2.3a,
1506 # and there was a complaint at:
1507 # <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
1508 AT_BISON_OPTION_PUSHDEFS
1511 start: test2 test1 test0 testc;
1514 : 'a' { semi; /* TEST:N:2 */ }
1515 | 'b' { if (0) {no_semi} /* TEST:N:2 */ }
1516 | 'c' { if (0) {semi;} /* TEST:N:2 */ }
1517 | 'd' { semi; no_semi /* TEST:Y:2 */ }
1518 | 'e' { semi(); no_semi() /* TEST:Y:2 */ }
1519 | 'f' { semi[]; no_semi[] /* TEST:Y:2 */ }
1520 | 'g' { semi++; no_semi++ /* TEST:Y:2 */ }
1521 | 'h' { {no_semi} no_semi /* TEST:Y:2 */ }
1522 | 'i' { {semi;} no_semi /* TEST:Y:2 */ }
1525 : 'a' { semi; // TEST:N:1 ;
1526 } | 'b' { if (0) {no_semi} // TEST:N:1 ;
1527 } | 'c' { if (0) {semi;} // TEST:N:1 ;
1528 } | 'd' { semi; no_semi // TEST:Y:1 ;
1529 } | 'e' { semi(); no_semi() // TEST:Y:1 ;
1530 } | 'f' { semi[]; no_semi[] // TEST:Y:1 ;
1531 } | 'g' { semi++; no_semi++ // TEST:Y:1 ;
1532 } | 'h' { {no_semi} no_semi // TEST:Y:1 ;
1533 } | 'i' { {semi;} no_semi // TEST:Y:1 ;
1536 : 'a' { semi; // TEST:N:1 {}
1537 } | 'b' { if (0) {no_semi} // TEST:N:1 {}
1538 } | 'c' { if (0) {semi;} // TEST:N:1 {}
1539 } | 'd' { semi; no_semi // TEST:Y:1 {}
1540 } | 'e' { semi(); no_semi() // TEST:Y:1 {}
1541 } | 'f' { semi[]; no_semi[] // TEST:Y:1 {}
1542 } | 'g' { semi++; no_semi++ // TEST:Y:1 {}
1543 } | 'h' { {no_semi} no_semi // TEST:Y:1 {}
1544 } | 'i' { {semi;} no_semi // TEST:Y:1 {}
1549 #define TEST_MACRO_N \
1550 []"broken\" $ @ $$ @$ [];\
1554 #define TEST_MACRO_N \
1555 []"broken\" $ @ $$ @$ [];\
1558 AT_BISON_OPTION_POPDEFS
1560 AT_BISON_CHECK([[-o input.c input.y]], [0], [],
1561 [[input.y:8.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1562 input.y:8.48: future versions of Bison will not add the ';'
1563 input.y:9.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1564 input.y:9.48: future versions of Bison will not add the ';'
1565 input.y:10.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1566 input.y:10.48: future versions of Bison will not add the ';'
1567 input.y:11.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1568 input.y:11.48: future versions of Bison will not add the ';'
1569 input.y:12.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1570 input.y:12.48: future versions of Bison will not add the ';'
1571 input.y:13.48: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1572 input.y:13.48: future versions of Bison will not add the ';'
1573 input.y:20.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1574 input.y:20.1: future versions of Bison will not add the ';'
1575 input.y:21.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1576 input.y:21.1: future versions of Bison will not add the ';'
1577 input.y:22.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1578 input.y:22.1: future versions of Bison will not add the ';'
1579 input.y:23.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1580 input.y:23.1: future versions of Bison will not add the ';'
1581 input.y:24.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1582 input.y:24.1: future versions of Bison will not add the ';'
1583 input.y:25.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1584 input.y:25.1: future versions of Bison will not add the ';'
1585 input.y:31.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1586 input.y:31.1: future versions of Bison will not add the ';'
1587 input.y:32.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1588 input.y:32.1: future versions of Bison will not add the ';'
1589 input.y:33.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1590 input.y:33.1: future versions of Bison will not add the ';'
1591 input.y:34.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1592 input.y:34.1: future versions of Bison will not add the ';'
1593 input.y:35.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1594 input.y:35.1: future versions of Bison will not add the ';'
1595 input.y:36.1: warning: a ';' might be needed at the end of action code [-Wdeprecated]
1596 input.y:36.1: future versions of Bison will not add the ';'
1599 AT_MATCHES_CHECK([input.c], [[/\* TEST:N:2 \*/ \}$]], [[3]])
1600 AT_MATCHES_CHECK([input.c], [[/\* TEST:Y:2 \*/ ;\}$]], [[6]])
1601 AT_MATCHES_CHECK([input.c], [[// TEST:N:1 [;{}]*\n\}$]], [[6]])
1602 AT_MATCHES_CHECK([input.c], [[// TEST:Y:1 [;{}]*\n;\}$]], [[12]])
1603 AT_MATCHES_CHECK([input.c], [[#define TEST_MACRO_N \\\n\[\]"broken\\" \$ \@ \$\$ \@\$ \[\];\\\nstring;"\}]], [[2]])
1608 ## -------------------------------------------------- ##
1609 ## Destroying lookahead assigned by semantic action. ##
1610 ## -------------------------------------------------- ##
1612 AT_SETUP([[Destroying lookahead assigned by semantic action]])
1614 AT_BISON_OPTION_PUSHDEFS
1615 AT_DATA_GRAMMAR([input.y],
1620 ]AT_YYERROR_DECLARE[
1625 %destructor { fprintf (stderr, "'a' destructor\n"); } 'a'
1626 %destructor { fprintf (stderr, "'b' destructor\n"); } 'b'
1630 // In a previous version of Bison, yychar assigned by the semantic
1631 // action below was not translated into yytoken before the lookahead was
1632 // discarded and thus before its destructor (selected according to
1633 // yytoken) was called in order to return from yyparse. This would
1634 // happen even if YYACCEPT was performed in a later semantic action as
1635 // long as only consistent states with default reductions were visited
1636 // in between. However, we leave YYACCEPT in the same semantic action
1637 // for this test in order to show that skeletons cannot simply translate
1638 // immediately after every semantic action because a semantic action
1639 // that has set yychar might not always return normally. Instead,
1640 // skeletons must translate before every use of yytoken.
1641 start: 'a' accept { USE($1); } ;
1643 assert (yychar == YYEMPTY);
1650 ]AT_YYLEX_DEFINE(["a"])[
1653 AT_BISON_OPTION_POPDEFS
1654 AT_BISON_CHECK([[-o input.c input.y]])
1655 AT_COMPILE([[input]])
1656 AT_PARSER_CHECK([[./input]], [[0]], [],
1667 AT_SETUP([[YYBACKUP]])
1669 AT_BISON_OPTION_PUSHDEFS([%pure-parser %debug])
1671 AT_DATA_GRAMMAR([input.y],
1678 # include <stdlib.h>
1679 # include <assert.h>
1681 ]AT_YYERROR_DECLARE[
1690 'a' { printf ("a: %d\n", $1); }
1691 | 'b' { YYBACKUP('a', 123); }
1692 | 'c' 'd' { YYBACKUP('a', 456); }
1697 ]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[
1700 AT_BISON_OPTION_POPDEFS
1702 AT_BISON_CHECK([[-o input.c input.y]])
1703 AT_COMPILE([[input]])
1704 AT_PARSER_CHECK([[./input]], [[0]],