]> git.saurik.com Git - bison.git/blob - tests/c++.at
tests: remove useless %defines
[bison.git] / tests / c++.at
1 # Checking the C++ Features. -*- Autotest -*-
2
3 # Copyright (C) 2004-2005, 2007-2013 Free Software Foundation, Inc.
4
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.
9 #
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.
14 #
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/>.
17
18 AT_BANNER([[C++ Features.]])
19
20
21 ## --------------------------- ##
22 ## C++ Variant-based Symbols. ##
23 ## --------------------------- ##
24
25 AT_SETUP([C++ Variant-based Symbols])
26
27 AT_KEYWORDS([variant])
28
29 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %debug $1])
30 # Store strings and integers in a list of strings.
31 AT_DATA_GRAMMAR([list.yy],
32 [[%skeleton "lalr1.cc"
33 %define api.value.type variant
34 %define parse.assert
35 %debug
36
37 %code top
38 {
39 // Get access to stack_symbol_type for the tests.
40 # define private public
41 }
42 %code provides
43 {
44 ]AT_YYLEX_DECLARE[
45 }
46
47 %token <int> INT "int"
48 %type < std::list<int> > exp
49
50 %printer { yyo << $$; } <int>
51 %printer
52 {
53 for (std::list<int>::const_iterator i = $$.begin (); i != $$.end (); ++i)
54 {
55 if (i != $$.begin ())
56 yyo << ", ";
57 yyo << *i;
58 }
59 } < std::list<int> >
60
61 %code requires { #include <list> }
62 %code { int yylex (yy::parser::semantic_type* yylval); }
63
64 %%
65 exp: "int" { $$.push_back ($1); }
66 %%
67 ]AT_YYERROR_DEFINE[
68 ]AT_YYLEX_DEFINE[
69
70 int main()
71 {
72 {
73 yy::parser::symbol_type s = yy::parser::make_INT(12);
74 std::cerr << s.value.as<int>() << std::endl;
75 }
76
77 {
78 yy::parser::symbol_type s = yy::parser::make_INT(123);
79 yy::parser::stack_symbol_type ss(1, s);
80 std::cerr << ss.value.as<int>() << std::endl;
81 }
82
83 {
84 yy::parser::stack_type st;
85 for (int i = 0; i < 100; ++i)
86 {
87 yy::parser::symbol_type s(yy::parser::make_INT(i));
88 yy::parser::stack_symbol_type ss(1, s);
89 st.push(ss);
90 }
91 }
92 }
93 ]])
94
95 AT_BISON_CHECK([-o list.cc list.yy])
96 AT_COMPILE_CXX([list], [$NO_STRICT_ALIAS_CXXFLAGS list.cc])
97 AT_PARSER_CHECK([./list], 0, [],
98 [12
99 123
100 ])
101
102 AT_BISON_OPTION_POPDEFS
103 AT_CLEANUP
104
105
106 ## ---------- ##
107 ## Variants. ##
108 ## ---------- ##
109
110 # AT_TEST([DIRECTIVES])
111 # ---------------------
112 # Check the support of variants in C++, with the additional DIRECTIVES.
113 m4_pushdef([AT_TEST],
114 [AT_SETUP([Variants $1])
115
116 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %debug $1])
117 # Store strings and integers in a list of strings.
118 AT_DATA_GRAMMAR([list.yy],
119 [[%debug
120 %skeleton "lalr1.cc"
121 %define api.value.type variant
122 ]m4_bpatsubst([$1], [\\n], [
123 ])[
124
125 %code requires // code for the .hh file
126 {
127 #include <list>
128 #include <string>
129 typedef std::list<std::string> strings_type;
130 }
131
132 %code // code for the .cc file
133 {
134 #include <cstdlib> // abort, getenv
135 #include <iostream>
136 #include <sstream>
137
138 namespace yy
139 {
140 static]AT_TOKEN_CTOR_IF([[
141 parser::symbol_type yylex ()]], [[
142 parser::token_type yylex (parser::semantic_type* yylval]AT_LOCATION_IF([,
143 parser::location_type* yylloc])[)]])[;
144 }
145
146 // Printing a list of strings (for %printer).
147 // Koening look up will look into std, since that's an std::list.
148 namespace std
149 {
150 std::ostream&
151 operator<<(std::ostream& o, const strings_type& s)
152 {
153 o << '(';
154 for (strings_type::const_iterator i = s.begin (); i != s.end (); ++i)
155 {
156 if (i != s.begin ())
157 o << ", ";
158 o << *i;
159 }
160 return o << ')';
161 }
162 }
163
164 // Conversion to string.
165 template <typename T>
166 inline
167 std::string
168 string_cast (const T& t)
169 {
170 std::ostringstream o;
171 o << t;
172 return o.str ();
173 }
174 }
175
176 %token <::std::string> TEXT;
177 %token <int> NUMBER;
178 %token END_OF_FILE 0;
179
180 %type <::std::string> item;
181 // Using the template type to exercize its parsing.
182 // Starting with :: to ensure we don't output "<::" which starts by the
183 // digraph for the left square bracket.
184 %type <::std::list<std::string>> list result;
185
186 %printer { yyo << $][$; }
187 <int> <::std::string> <::std::list<std::string>>;
188 %%
189
190 result:
191 list { std::cout << $][1 << std::endl; }
192 ;
193
194 list:
195 /* nothing */ { /* Generates an empty string list */ }
196 | list item { std::swap ($][$,$][1); $$.push_back ($][2); }
197 | list error { std::swap ($][$,$][1); }
198 ;
199
200 item:
201 TEXT { std::swap ($][$,$][1); }
202 | NUMBER { if ($][1 == 3) YYERROR; else $][$ = string_cast ($][1); }
203 ;
204 %%
205 ]AT_TOKEN_CTOR_IF([],
206 [[#ifdef TWO_STAGE_BUILD
207 # define BUILD(Type, Value) build<Type> () = Value
208 #else
209 # define BUILD(Type, Value) build (Value)
210 #endif
211 ]])[
212 #define STAGE_MAX 5
213 namespace yy
214 {
215 static]AT_TOKEN_CTOR_IF([[
216 parser::symbol_type yylex ()]], [[
217 parser::token_type yylex (parser::semantic_type* yylval]AT_LOCATION_IF([,
218 parser::location_type* yylloc])[)]])[
219 {]AT_LOCATION_IF([
220 typedef parser::location_type location;])[
221 static int stage = -1;
222 ++stage;
223 if (stage == STAGE_MAX)
224 {]AT_TOKEN_CTOR_IF([[
225 return parser::make_END_OF_FILE (]AT_LOCATION_IF([location ()])[);]],
226 [AT_LOCATION_IF([
227 *yylloc = location ();])[
228 return parser::token::END_OF_FILE;]])[
229 }
230 else if (stage % 2)
231 {]AT_TOKEN_CTOR_IF([[
232 return parser::make_NUMBER (stage]AT_LOCATION_IF([, location ()])[);]],
233 [[
234 yylval->BUILD (int, stage);]AT_LOCATION_IF([
235 *yylloc = location ();])[
236 return parser::token::NUMBER;]])[
237 }
238 else
239 {]AT_TOKEN_CTOR_IF([[
240 return parser::make_TEXT (string_cast (stage)]AT_LOCATION_IF([, location ()])[);]], [[
241 yylval->BUILD (std::string, string_cast (stage));]AT_LOCATION_IF([
242 *yylloc = location ();])[
243 return parser::token::TEXT;]])[
244 }
245 abort ();
246 }
247 }
248
249 ]AT_YYERROR_DEFINE[
250 ]AT_MAIN_DEFINE[
251 ]])
252
253 AT_BISON_CHECK([-o list.cc list.yy])
254 AT_COMPILE_CXX([list], [$NO_STRICT_ALIAS_CXXFLAGS list.cc])
255 AT_PARSER_CHECK([./list], 0,
256 [(0, 1, 2, 4)
257 ])
258
259 AT_BISON_OPTION_POPDEFS
260 AT_CLEANUP
261 ])
262
263 AT_TEST([])
264 AT_TEST([%define parse.assert])
265 AT_TEST([%locations %define parse.assert])
266 AT_TEST([[%define parse.assert %code {\n#define TWO_STAGE_BUILD\n}]])
267 AT_TEST([[%define parse.assert %define api.token.constructor]])
268 AT_TEST([[%define parse.assert %define api.token.constructor %define api.token.prefix "TOK_"]])
269 AT_TEST([[%locations %define parse.assert %define api.token.constructor %define api.token.prefix "TOK_"]])
270
271 m4_popdef([AT_TEST])
272
273
274 ## ----------------------- ##
275 ## Doxygen Documentation. ##
276 ## ----------------------- ##
277
278 m4_define([AT_CHECK_DOXYGEN],
279 [m4_case([$1],
280 [Public], [m4_pushdef([AT_DOXYGEN_PRIVATE], [NO])],
281 [Private], [m4_pushdef([AT_DOXYGEN_PRIVATE], [YES])],
282 [m4_fatal([invalid argument: $1])])
283 AT_SETUP([Doxygen $1 Documentation])
284
285 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
286 AT_DATA([input.yy],
287 [[%skeleton "lalr1.cc"
288 %locations
289 %debug
290 %%
291 exp: /* empty */;
292 %%
293 ]AT_YYERROR_DEFINE[
294 ]])
295
296 AT_BISON_CHECK([-o input.cc input.yy], 0)
297
298 AT_DATA([Doxyfile],
299 [# The PROJECT_NAME tag is a single word (or a sequence of words
300 # surrounded by quotes) that should identify the project.
301 PROJECT_NAME = "Bison C++ Parser"
302
303 # The QUIET tag can be used to turn on/off the messages that are
304 # generated by doxygen. Possible values are YES and NO. If left blank
305 # NO is used.
306 QUIET = YES
307
308 # The WARNINGS tag can be used to turn on/off the warning messages
309 # that are generated by doxygen. Possible values are YES and NO. If
310 # left blank NO is used.
311 WARNINGS = YES
312 # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
313 # warnings for undocumented members. If EXTRACT_ALL is set to YES then
314 # this flag will automatically be disabled.
315 WARN_IF_UNDOCUMENTED = YES
316 # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
317 # for potential errors in the documentation, such as not documenting
318 # some parameters in a documented function, or documenting parameters
319 # that don't exist or using markup commands wrongly.
320 WARN_IF_DOC_ERROR = YES
321 # The WARN_FORMAT tag determines the format of the warning messages
322 # that doxygen can produce. The string should contain the $file,
323 # $line, and $text tags, which will be replaced by the file and line
324 # number from which the warning originated and the warning text.
325 WARN_FORMAT = "$file:$line: $text"
326
327 # If the EXTRACT_ALL tag is set to YES doxygen will assume all
328 # entities in documentation are documented, even if no documentation
329 # was available. Private class members and static file members will
330 # be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
331 # to YES
332 EXTRACT_ALL = YES
333
334 # If the EXTRACT_PRIVATE tag is set to YES all private members of a
335 # class will be included in the documentation.
336 EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
337
338 # If the EXTRACT_STATIC tag is set to YES all static members of a file
339 # will be included in the documentation.
340 EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
341 ])
342
343 AT_CHECK([doxygen --version || exit 77], 0, ignore)
344 AT_CHECK([doxygen], 0, [], [ignore])
345
346 AT_BISON_OPTION_POPDEFS
347 AT_CLEANUP
348
349 m4_popdef([AT_DOXYGEN_PRIVATE])
350 ])# AT_CHECK_DOXYGEN
351
352 AT_CHECK_DOXYGEN([Public])
353 AT_CHECK_DOXYGEN([Private])
354
355
356 ## ------------ ##
357 ## Namespaces. ##
358 ## ------------ ##
359
360 # AT_TEST(NAMESPACE-DECL, [COMPILE-ERROR])
361 # ----------------------------------------
362 # See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
363 # is specified, then Bison should accept the input, but compilation will fail,
364 # so don't check compilation.
365 m4_pushdef([AT_TEST],
366 [AT_BISON_OPTION_PUSHDEFS([%language "C++" %define api.namespace "$1"])
367 AT_DATA_GRAMMAR([[input.y]],
368 [[%language "C++"
369 %define api.namespace "]$1["
370 %union { int i; }
371 %define global_tokens_and_yystype
372 %locations
373
374 %code {
375 // YYSTYPE contains a namespace reference.
376 int yylex (YYSTYPE *lval, const ]$1[::parser::location_type*) {
377 lval->i = 3;
378 return 0;
379 }
380 }
381
382 %%
383
384 start: ;
385
386 %%
387
388 void
389 ]$1[::parser::error (const ]$1[::parser::location_type &loc,
390 const std::string &msg)
391 {
392 std::cerr << "At " << loc << ": " << msg << std::endl;
393 }
394
395 ]AT_MAIN_DEFINE[
396 ]])
397
398 AT_BISON_CHECK([[-o input.cc input.y]])
399
400 m4_if([$#], [1],
401 [AT_COMPILE_CXX([[input]], [[input.cc]])
402 AT_PARSER_CHECK([[./input]])])
403 AT_BISON_OPTION_POPDEFS
404 ])
405
406 AT_SETUP([[Relative namespace references]])
407 AT_TEST([[foo]])
408 AT_TEST([[foo::bar]])
409 AT_TEST([[foo::bar::baz]])
410 AT_CLEANUP
411
412 AT_SETUP([[Absolute namespace references]])
413 AT_TEST([[::foo]])
414 AT_TEST([[::foo::bar]])
415 AT_TEST([[::foo::bar::baz]])
416 AT_TEST([[ ::foo]])
417 AT_TEST([[ ::foo::bar]])
418 AT_TEST([[ ::foo::bar::baz]])
419 AT_CLEANUP
420
421 AT_SETUP([[Syntactically invalid namespace references]])
422 AT_TEST([[:foo:bar]], [[-]])
423 AT_TEST([[foo: :bar]], [[-]])
424 # This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
425 # contains single occurrences of `:'.
426 AT_TEST([[foo[3]::bar::baz]], [[-]])
427 AT_TEST([[foo::bar,baz]], [[-]])
428 AT_TEST([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
429 AT_CLEANUP
430
431 m4_popdef([AT_TEST])
432
433 ## -------------------------------------- ##
434 ## Syntax error discarding no lookahead. ##
435 ## -------------------------------------- ##
436
437 # After a syntax error, lalr1.cc used to not check whether there
438 # actually is a lookahead before discarding the lookahead. As a result,
439 # it mistakenly invoked the destructor for the previous lookahead.
440
441 AT_SETUP([[Syntax error discarding no lookahead]])
442
443 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
444
445 AT_DATA_GRAMMAR([[input.yy]],
446 [[%skeleton "lalr1.cc"
447
448 %code {
449 #include <string>
450 int yylex (yy::parser::semantic_type *);
451 #define USE(Args)
452 }
453
454 %define parse.error verbose
455
456 %nonassoc 'a' ;
457
458 %destructor {
459 std::cerr << "Discarding 'a'." << std::endl;
460 } 'a'
461
462 %%
463
464 start: error-reduce consistent-error 'a' { USE ($3); };
465
466 error-reduce:
467 'a' 'a' consistent-error 'a' { USE (($1, $2, $4)); }
468 | 'a' error { std::cerr << "Reducing 'a'." << std::endl; USE ($1); }
469 ;
470
471 consistent-error:
472 'a'
473 | /*empty*/ %prec 'a'
474 ;
475
476 // Provide another context in which all rules are useful so that this
477 // test case looks a little more realistic.
478 start: 'b' consistent-error ;
479
480 %%
481
482 int
483 yylex (yy::parser::semantic_type *)
484 {
485 static char const *input = "aa";
486 return *input++;
487 }
488
489 void
490 yy::parser::error (const std::string &m)
491 {
492 std::cerr << m << std::endl;
493 }
494
495 ]AT_MAIN_DEFINE[
496 ]])
497
498 AT_BISON_CHECK([[-o input.cc input.yy]])
499 AT_COMPILE_CXX([[input]])
500 # This used to print "Discarding 'a'." again at the end.
501 AT_PARSER_CHECK([[./input]], [[1]], [[]],
502 [[syntax error
503 Discarding 'a'.
504 Reducing 'a'.
505 ]])
506
507 AT_BISON_OPTION_POPDEFS
508 AT_CLEANUP
509
510
511 ## --------------------------- ##
512 ## Syntax error as exception. ##
513 ## --------------------------- ##
514
515 AT_SETUP([[Syntax error as exception]])
516
517 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
518
519 AT_DATA_GRAMMAR([[input.yy]],
520 [[%skeleton "lalr1.cc"
521
522 %code
523 {
524 #include <cstdlib>
525 int yylex (yy::parser::semantic_type *);
526 }
527
528 %define api.value.type variant
529 %define parse.error verbose
530 %define parse.trace
531 %%
532
533 start:
534 thing
535 | start thing
536 ;
537
538 thing:
539 error { std::cerr << "caught error" << std::endl; }
540 | item
541 ;
542
543 item:
544 'a'
545 | 's'
546 {
547 throw yy::parser::syntax_error ("invalid expression");
548 }
549
550 %%
551
552 int
553 yylex (yy::parser::semantic_type *)
554 {
555 // 's': syntax error, 'l': lexical error.
556 static char const *input = "asal";
557 switch (int res = *input++)
558 {
559 case 'l':
560 throw yy::parser::syntax_error ("invalid character");
561 default:
562 return res;
563 }
564 }
565
566 void
567 yy::parser::error (const std::string &m)
568 {
569 std::cerr << "error: " << m << std::endl;
570 }
571 ]AT_MAIN_DEFINE[
572 ]])
573
574 AT_BISON_CHECK([[-o input.cc input.yy]])
575 AT_COMPILE_CXX([[input]])
576
577 AT_PARSER_CHECK([[./input]], [[0]], [[]],
578 [[error: invalid expression
579 caught error
580 error: invalid character
581 caught error
582 ]])
583
584 AT_BISON_OPTION_POPDEFS
585 AT_CLEANUP
586
587
588 ## ------------------ ##
589 ## Exception safety. ##
590 ## ------------------ ##
591
592 AT_SETUP([[Exception safety]])
593
594 AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
595
596 AT_DATA_GRAMMAR([[input.yy]],
597 [[%skeleton "lalr1.cc"
598 %debug
599 %error-verbose
600
601 %code requires
602 {
603 #include <cassert>
604 #include <cstdlib> // size_t and getenv.
605 #include <iostream>
606 #include <list>
607
608 bool debug = false;
609
610 /// A class that counts its number of instances.
611 struct Object
612 {
613 typedef std::list<const Object*> objects;
614 static objects instances;
615 char val;
616
617 static bool
618 empty ()
619 {
620 return instances.empty();
621 }
622
623 static void
624 log (Object const *o, const std::string& msg)
625 {
626 if (debug)
627 {
628 if (o)
629 std::cerr << o << "->";
630 std::cerr << msg << " {";
631 const char* sep = " ";
632 for (objects::const_iterator i = instances.begin(),
633 i_end = instances.end();
634 i != i_end;
635 ++i)
636 {
637 std::cerr << sep << *i;
638 sep = ", ";
639 }
640 std::cerr << " }" << std::endl;
641 }
642 }
643
644 Object (char v)
645 : val (v)
646 {
647 instances.push_back(this);
648 log (this, "Object::Object");
649 }
650
651 ~Object ()
652 {
653 instances.remove(this);
654 log (this, "Object::~Object");
655 }
656 };
657 }
658
659 %code
660 {
661 #include <cassert>
662 #include <cstring> // strchr
663 #include <stdexcept>
664 int yylex (yy::parser::semantic_type *);
665 Object::objects Object::instances;
666 static char const *input;
667 }
668
669 %union
670 {
671 Object *obj;
672 }
673
674 %initial-action
675 {
676 if (strchr (input, 'i'))
677 throw std::runtime_error ("initial-action");
678 }
679
680 %destructor { delete $$; } <obj>;
681 %printer
682 {
683 yyo << $$ << " '" << $$->val << '\'';
684 if ($$->val == 'p')
685 throw std::runtime_error ("printer");
686 } <obj>;
687
688 %token <obj> 'a' 'E' 'e' 'p' 'R' 's' 'T'
689 %type <obj> list item
690
691 %%
692
693 start: list { delete $1; };
694
695 list:
696 item { $$ = $1; }
697 | item list { $$ = $1; delete $2; } // Right recursion to load the stack.
698 ;
699
700 item:
701 'a' { $$ = $1; }
702 | 'e' { YYUSE ($$); YYUSE($1); error ("syntax error"); }
703 // Not just 'E', otherwise we reduce when 'E' is the lookahead, and
704 // then the stack is emptied, defeating the point of the test.
705 | 'E' 'a' { YYUSE($1); $$ = $2; }
706 | 'R' { $$ = YY_NULL; delete $1; YYERROR; }
707 | 'p' { $$ = $1; }
708 | 's' { $$ = $1; throw std::runtime_error ("reduction"); }
709 | 'T' { $$ = YY_NULL; delete $1; YYABORT; }
710 | error { $$ = YY_NULL; yyerrok; }
711 ;
712 %%
713
714 int
715 yylex (yy::parser::semantic_type *lvalp)
716 {
717 // 'a': no error.
718 // 'e': user action calls error.
719 // 'E': syntax error, with yyerror that throws.
720 // 'i': initial action throws.
721 // 'l': yylex throws.
722 // 'R': call YYERROR in the action
723 // 's': reduction throws.
724 // 'T': call YYABORT in the action
725 switch (int res = *input++)
726 {
727 case 'l':
728 throw std::runtime_error ("yylex");
729 default:
730 lvalp->obj = new Object (res);
731 // Fall through.
732 case 0:
733 return res;
734 }
735 }
736
737 /* A C++ error reporting function. */
738 void
739 yy::parser::error (const std::string& m)
740 {
741 throw std::runtime_error (m);
742 }
743
744 int
745 main (int argc, const char *argv[])
746 {
747 switch (argc)
748 {
749 case 2:
750 input = argv[1];
751 break;
752 case 3:
753 assert (std::string(argv[1]) == "--debug");
754 debug = 1;
755 input = argv[2];
756 break;
757 default:
758 abort ();
759 }
760
761 yy::parser parser;
762 debug |= !!getenv ("YYDEBUG");
763 parser.set_debug_level (debug);
764 int res = 2;
765 try
766 {
767 res = parser.parse ();
768 }
769 catch (const std::exception& e)
770 {
771 std::cerr << "exception caught: " << e.what () << std::endl;
772 }
773 catch (...)
774 {
775 std::cerr << "unknown exception caught" << std::endl;
776 }
777 Object::log (YY_NULL, "end");
778 assert (Object::empty());
779 return res;
780 }
781 ]])
782 AT_BISON_CHECK([[-o input.cc --report=all input.yy]])
783 AT_COMPILE_CXX([[input]])
784
785 AT_PARSER_CHECK([[./input aaaas]], [[2]], [[]],
786 [[exception caught: reduction
787 ]])
788
789 AT_PARSER_CHECK([[./input aaaal]], [[2]], [[]],
790 [[exception caught: yylex
791 ]])
792
793 AT_PARSER_CHECK([[./input i]], [[2]], [[]],
794 [[exception caught: initial-action
795 ]])
796
797 AT_PARSER_CHECK([[./input aaaap]])
798
799 AT_PARSER_CHECK([[./input --debug aaaap]], [[2]], [[]], [[stderr]])
800 AT_CHECK([[grep '^exception caught: printer$' stderr]], [], [ignore])
801
802 AT_PARSER_CHECK([[./input aaaae]], [[2]], [[]],
803 [[exception caught: syntax error
804 ]])
805
806 AT_PARSER_CHECK([[./input aaaaE]], [[2]], [[]],
807 [[exception caught: syntax error, unexpected $end, expecting 'a'
808 ]])
809
810 AT_PARSER_CHECK([[./input aaaaT]], [[1]])
811
812 # There is error-recovery, so exit success.
813 AT_PARSER_CHECK([[./input aaaaR]], [[0]])
814
815 AT_BISON_OPTION_POPDEFS
816
817 AT_CLEANUP
818
819 ## ------------------------------------ ##
820 ## C++ GLR parser identifier shadowing ##
821 ## ------------------------------------ ##
822
823 AT_SETUP([[C++ GLR parser identifier shadowing]])
824
825 AT_DATA_GRAMMAR([input.yy], [
826 %skeleton "glr.cc"
827
828 %union
829 {
830 int ival;
831 }
832
833 %token <ival> ZERO;
834
835 %code
836 {
837 int yylex (yy::parser::semantic_type *yylval);
838 }
839
840 %%
841 exp: ZERO
842
843 %%
844
845 int yylex (yy::parser::semantic_type *yylval)
846 {
847 // Note: this argument is unused, but named on purpose. There used to be a
848 // bug with a macro that erroneously expanded this identifier to
849 // yystackp->yyval.
850 YYUSE (yylval);
851 return yy::parser::token::ZERO;
852 }
853
854 void yy::parser::error (std::string const&)
855 {}
856
857 int main()
858 {}
859 ])
860
861 AT_BISON_CHECK([[-o input.cc input.yy]])
862 AT_COMPILE_CXX([[input]])
863
864 AT_CLEANUP