b4_public_types_declare.
[bison/ericb.git] / data / lalr1.cc
blobe3e0f9a6403b13fd557fdf8cabad26eba096e926
1 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 # Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 m4_include(b4_pkgdatadir/[c++.m4])
22 # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
23 # --------------------------------------------------------------
24 # Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
25 m4_define([b4_integral_parser_table_declare],
26 [m4_ifval([$3], [b4_c_comment([$3], [ ])
27 ])dnl
28 static const b4_int_type_for([$2]) yy$1_[[]];dnl
31 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
32 # ---------------------------------------------
33 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
34 m4_define([b4_integral_parser_table_define],
35 [ const b4_int_type_for([$2])
36 b4_parser_class_name::yy$1_[[]] =
39 };dnl
43 # b4_symbol_value_template(VAL, [TYPE])
44 # -------------------------------------
45 # Same as b4_symbol_value, but used in a template method. It makes
46 # a difference when using variants.
47 m4_copy([b4_symbol_value], [b4_symbol_value_template])
50 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
51 # ----------------------------------------------------------------
52 m4_define([b4_lex_symbol_if],
53 [b4_percent_define_ifdef([[lex_symbol]], [$1], [$2])])
56 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
57 # ------------------------------------------------
58 m4_define([b4_assert_if],
59 [b4_percent_define_ifdef([[assert]], [$1], [$2])])
62 # b4_lhs_value([TYPE])
63 # --------------------
64 # Expansion of $<TYPE>$.
65 m4_define([b4_lhs_value],
66 [b4_symbol_value([yylhs.value], [$1])])
69 # b4_lhs_location()
70 # -----------------
71 # Expansion of @$.
72 m4_define([b4_lhs_location],
73 [yylhs.location])
76 # b4_rhs_data(RULE-LENGTH, NUM)
77 # -----------------------------
78 # Return the data corresponding to the symbol #NUM, where the current
79 # rule has RULE-LENGTH symbols on RHS.
80 m4_define([b4_rhs_data],
81 [yystack_@{b4_subtract($@)@}])
84 # b4_rhs_state(RULE-LENGTH, NUM)
85 # ------------------------------
86 # The state corresponding to the symbol #NUM, where the current
87 # rule has RULE-LENGTH symbols on RHS.
88 m4_define([b4_rhs_state],
89 [b4_rhs_data([$1], [$2]).state])
92 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
93 # --------------------------------------
94 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
95 # symbols on RHS.
96 m4_define([b4_rhs_value],
97 [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
100 # b4_rhs_location(RULE-LENGTH, NUM)
101 # ---------------------------------
102 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
103 # on RHS.
104 m4_define([b4_rhs_location],
105 [b4_rhs_data([$1], [$2]).location])
108 # b4_symbol_action(SYMBOL-NUM, KIND)
109 # ----------------------------------
110 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
111 # Same as in C, but using references instead of pointers.
112 m4_define([b4_symbol_action],
113 [b4_symbol_if([$1], [has_$2],
114 [m4_pushdef([b4_dollar_dollar],
115 [b4_symbol_value_template([yysym.value],
116 b4_symbol_if([$1], [has_type],
117 [b4_symbol([$1], [type])]))])dnl
118 m4_pushdef([b4_at_dollar], [yysym.location])dnl
119 b4_symbol_case_([$1])
120 b4_syncline([b4_symbol([$1], [$2_line])], ["b4_symbol([$1], [$2_file])"])
121 b4_symbol([$1], [$2])
122 b4_syncline([@oline@], [@ofile@])
123 break;
125 m4_popdef([b4_at_dollar])dnl
126 m4_popdef([b4_dollar_dollar])dnl
127 ])])
129 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
130 # -------------------------------------------------
131 # Declare the overloaded version of make_symbol for the (common) type of
132 # these SYMBOL-NUMBERS. Use at class-level.
133 m4_define([b4_symbol_constructor_declaration_],
134 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
135 [ static inline
136 symbol_type
137 make_[]b4_symbol_([$1], [id]) (dnl
138 b4_args(b4_symbol_if([$1], [has_type],
139 [const b4_symbol([$1], [type])& v]),
140 b4_locations_if([const location_type& l])));
142 ])])])
145 # b4_symbol_constructor_declarations
146 # ----------------------------------
147 # Declare symbol constructors for all the value types.
148 # Use at class-level.
149 m4_define([b4_symbol_constructor_declarations],
150 [b4_variant_if([
151 // Symbol constructors declarations.
152 b4_symbol_foreach([b4_symbol_constructor_declaration_])])])
156 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
157 # ------------------------------------------------
158 # Define symbol constructor for this SYMBOL-NUMBER.
159 m4_define([b4_symbol_constructor_definition_],
160 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
161 [ b4_parser_class_name::symbol_type
162 b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
163 b4_args(b4_symbol_if([$1], [has_type],
164 [const b4_symbol([$1], [type])& v]),
165 b4_locations_if([const location_type& l])))
167 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [id]))],
168 b4_symbol_if([$1], [has_type], [v]),
169 b4_locations_if([l])));
172 ])])])
175 # b4_symbol_constructor_definitions
176 # ----------------------------------
177 # Define the overloaded versions of make_symbol for all the value types.
178 m4_define([b4_symbol_constructor_definitions],
179 [[ // symbol_base_type.
180 template <typename Exact>
181 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type ()
182 : value()]b4_locations_if([
183 , location()])[
185 }]b4_locations_if([[
187 template <typename Exact>
188 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (const location_type& l)
189 : value()
190 , location(l)
192 }]])[
194 template <typename Exact>
195 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (]b4_args(
196 [const semantic_type& v],
197 b4_locations_if([const location_type& l]))[)
198 : value(v)]b4_locations_if([
199 , location(l)])[
203 template <typename Exact>
204 const Exact&
205 ]b4_parser_class_name[::symbol_base_type<Exact>::self () const
207 return static_cast<const Exact&>(*this);
210 template <typename Exact>
211 Exact&
212 ]b4_parser_class_name[::symbol_base_type<Exact>::self ()
214 return static_cast<Exact&>(*this);
217 template <typename Exact>
219 ]b4_parser_class_name[::symbol_base_type<Exact>::type_get () const
221 return self ().type_get_ ();
224 // symbol_type.
225 ]b4_parser_class_name[::symbol_type::symbol_type ()
226 : super_type ()
227 , type ()
231 ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
232 [int t],
233 b4_locations_if([const location_type& l]))[)
234 : super_type (]b4_locations_if([l])[)
235 , type (t)
239 ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
240 [int t],
241 [const semantic_type& v],
242 b4_locations_if([const location_type& l]))[)
243 : super_type (v]b4_locations_if([, l])[)
244 , type (t)
249 ]b4_parser_class_name[::symbol_type::type_get_ () const
251 return type;
253 ]b4_lex_symbol_if([[
254 ]b4_parser_class_name[::token_type
255 ]b4_parser_class_name[::symbol_type::token () const
257 // YYTOKNUM[NUM] -- (External) token number corresponding to the
258 // (internal) symbol number NUM (which must be that of a token). */
259 static
260 const ]b4_int_type_for([b4_toknum])[
261 yytoken_number_[] =
263 ]b4_toknum[
265 return static_cast<token_type> (yytoken_number_[type]);
267 ]])[
269 ]b4_variant_if(
270 [ // Implementation of make_symbol for each symbol type.
271 b4_symbol_foreach([b4_symbol_constructor_definition_])])])
274 # b4_yytranslate_definition
275 # -------------------------
276 # Define yytranslate_. Sometimes we want it in the header file,
277 # sometimes the cc file suffices.
278 m4_define([b4_yytranslate_definition],
279 [[ // Symbol number corresponding to token number t.
280 ]b4_parser_class_name[::token_number_type
281 ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type],
282 [int])[ t)
284 static
285 const token_number_type
286 translate_table[] =
288 ]b4_translate[
290 const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
291 const token_number_type undef_token_ = ]b4_undef_token_number[;
293 if (static_cast<int>(t) <= yyeof_)
294 return yyeof_;
295 else if (static_cast<unsigned int> (t) <= user_token_number_max_)
296 return translate_table[t];
297 else
298 return undef_token_;
303 m4_pushdef([b4_copyright_years],
304 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
306 m4_define([b4_parser_class_name],
307 [b4_percent_define_get([[parser_class_name]])])
309 # The header is mandatory.
310 b4_defines_if([],
311 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
313 b4_locations_if(
314 [# Backward compatibility.
315 m4_define([b4_location_constructors])
316 m4_include(b4_pkgdatadir/[location.cc])])
317 m4_include(b4_pkgdatadir/[stack.hh])
318 b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])])
320 # We do want M4 expansion after # for CPP macros.
321 m4_changecom()
322 m4_divert_push(0)dnl
323 @output(b4_spec_defines_file@)@
324 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
325 dnl FIXME: This is wrong, we want computed header guards.
327 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
329 #ifndef PARSER_HEADER_H
330 # define PARSER_HEADER_H
332 ]b4_percent_code_get([[requires]])[
334 ]b4_assert_if([#include <cassert>])[
335 #include <string>
336 #include <iostream>
337 #include "stack.hh"
339 ]b4_namespace_open[
340 ]b4_locations_if([ class position;
341 class location;])[
342 ]b4_variant_if([b4_variant_definition])[
343 ]b4_namespace_close[
345 ]b4_locations_if([#include "location.hh"])[
347 /* Enabling traces. */
348 #ifndef YYDEBUG
349 # define YYDEBUG ]b4_debug_flag[
350 #endif
352 /* Enabling verbose error messages. */
353 #ifdef YYERROR_VERBOSE
354 # undef YYERROR_VERBOSE
355 # define YYERROR_VERBOSE 1
356 #else
357 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
358 #endif
360 /* Enabling the token table. */
361 #ifndef YYTOKEN_TABLE
362 # define YYTOKEN_TABLE ]b4_token_table[
363 #endif
365 ]b4_locations_if([dnl
366 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
367 If N is 0, then set CURRENT to the empty location which ends
368 the previous symbol: RHS[0] (always defined). */
370 #ifndef YYLLOC_DEFAULT
371 # define YYLLOC_DEFAULT(Current, Rhs, N) \
372 do { \
373 if (N) \
375 (Current).begin = (Rhs)[1].location.begin; \
376 (Current).end = (Rhs)[N].location.end; \
378 else \
380 (Current).begin = (Current).end = (Rhs)[0].location.end; \
382 } while (false)
383 #endif]])[
385 ]b4_namespace_open[
387 /// A Bison parser.
388 class ]b4_parser_class_name[
390 public:
391 ]b4_public_types_declare[
392 /// Build a parser object.
393 ]b4_parser_class_name[ (]b4_parse_param_decl[);
394 virtual ~]b4_parser_class_name[ ();
396 /// Parse.
397 /// \returns 0 iff parsing succeeded.
398 virtual int parse ();
400 #if YYDEBUG
401 /// The current debugging stream.
402 std::ostream& debug_stream () const;
403 /// Set the current debugging stream.
404 void set_debug_stream (std::ostream &);
406 /// Type for debugging levels.
407 typedef int debug_level_type;
408 /// The current debugging level.
409 debug_level_type debug_level () const;
410 /// Set the current debugging level.
411 void set_debug_level (debug_level_type l);
412 #endif
414 /// Report a syntax error.]b4_locations_if([
415 /// \param loc where the syntax error is found.])[
416 /// \param msg a description of the syntax error.
417 virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg);
419 private:
420 /// Generate an error message.
421 /// \param state the state where the error occurred.
422 /// \param tok the lookahead token.
423 virtual std::string yysyntax_error_ (int yystate, int tok);
425 /// State numbers.
426 typedef int state_type;
428 /// Internal symbol numbers.
429 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
430 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
431 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
433 /* Tables. */
434 ]b4_parser_tables_declare[
436 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
437 /// For a symbol, its name in clear.
438 static const char* const yytname_[];
439 #endif]b4_error_verbose_if([
441 /// Convert the symbol name \a n to a form suitable for a diagnostic.
442 static std::string yytnamerr_ (const char *n);])[
444 #if YYDEBUG
445 ]b4_integral_parser_table_declare([rline], [b4_rline],
446 [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[
447 /// Report on the debug stream that the rule \a r is going to be reduced.
448 virtual void yy_reduce_print_ (int r);
449 /// Print the state stack on the debug stream.
450 virtual void yystack_print_ ();
452 /* Debugging. */
453 int yydebug_;
454 std::ostream* yycdebug_;
455 #endif
457 /// Convert a scanner token number \a t to a symbol number.
458 static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
460 /// A complete symbol, with its type.
461 template <typename Exact>
462 struct symbol_base_type
464 /// Default constructor.
465 inline symbol_base_type ();
467 /// Constructor.]b4_locations_if([
468 inline symbol_base_type (const location_type& l)])[;
469 inline symbol_base_type (]b4_args(
470 [const semantic_type& v],
471 b4_locations_if([const location_type& l]))[);
473 /// Return this with its exact type.
474 const Exact& self () const;
475 Exact& self ();
477 /// Return the type of this symbol.
478 int type_get () const;
480 /// The semantic value.
481 semantic_type value;]b4_locations_if([
483 /// The location.
484 location_type location;])[
487 #if YYDEBUG
488 /// \brief Display a symbol type, value and location.
489 /// \param yyo The output stream.
490 /// \param yysym The symbol.
491 template <typename Exact>
492 void yy_print_ (std::ostream& yyo,
493 const symbol_base_type<Exact>& yysym) const;
494 #endif
496 /// \brief Reclaim the memory associated to a symbol.
497 /// \param yymsg Why this token is reclaimed.
498 /// If null, print nothing.
499 /// \param s The symbol.
500 template <typename Exact>
501 inline void yy_destroy_ (const char* yymsg,
502 symbol_base_type<Exact>& yysym) const;
504 public:
505 /// External form of a symbol: its type and attributes.
506 struct symbol_type : symbol_base_type<symbol_type>
508 /// The parent class.
509 typedef symbol_base_type<symbol_type> super_type;
511 /// Default constructor.
512 inline symbol_type ();
514 /// Constructor.
515 inline symbol_type (]b4_args([int t],
516 [const semantic_type& v],
517 b4_locations_if([const location_type& l]))[);
519 inline symbol_type (]b4_args([int t],
520 b4_locations_if([const location_type& l]))[);
522 /// The symbol type.
523 int type;
525 /// Return the type corresponding to this state.
526 inline int type_get_ () const;
528 /// Its token.
529 inline token_type token () const;
532 ]b4_symbol_constructor_declarations[
534 private:
535 /// Element of the stack: a state and its attributes.
536 struct stack_symbol_type : symbol_base_type<stack_symbol_type>
538 /// The parent class.
539 typedef symbol_base_type<stack_symbol_type> super_type;
541 /// Default constructor.
542 inline stack_symbol_type ();
544 /// Constructor.
545 inline stack_symbol_type (]b4_args([state_type s],
546 [const semantic_type& v],
547 b4_locations_if([const location_type& l]))[);
549 /// The state.
550 state_type state;
552 /// Return the type corresponding to this state.
553 inline int type_get_ () const;
556 /// Stack type.
557 typedef stack<stack_symbol_type> stack_type;
559 /// The stack.
560 stack_type yystack_;
562 /// Push a new state on the stack.
563 /// \param m a debug message to display
564 /// if null, no trace is output.
565 /// \param s the symbol
566 /// \warning the contents of \a s.value is stolen.
567 inline void yypush_ (const char* m, stack_symbol_type& s);
569 /// Push a new look ahead token on the state on the stack.
570 /// \param m a debug message to display
571 /// if null, no trace is output.
572 /// \param s the state
573 /// \param sym the symbol (for its value and location).
574 /// \warning the contents of \a s.value is stolen.
575 inline void yypush_ (const char* m, state_type s, symbol_type& sym);
577 /// Pop \a n symbols the three stacks.
578 inline void yypop_ (unsigned int n = 1);
580 /* Constants. */
581 enum
583 yyeof_ = 0,
584 yylast_ = ]b4_last[, //< Last index in yytable_.
585 yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
586 yyempty_ = -2,
587 yyfinal_ = ]b4_final_state_number[, //< Termination state number.
588 yyterror_ = 1,
589 yyerrcode_ = 256,
590 yyntokens_ = ]b4_tokens_number[, //< Number of tokens.
593 ]b4_parse_param_vars[
596 ]b4_lex_symbol_if([b4_yytranslate_definition])[
597 ]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
598 ]b4_namespace_close[
600 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
601 [b4_token_defines(b4_tokens)
603 #ifndef YYSTYPE
604 /* Redirection for backward compatibility. */
605 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
606 #endif
608 b4_percent_code_get([[provides]])[]dnl
610 [#endif /* ! defined PARSER_HEADER_H */]
611 @output(b4_parser_file_name@)@
612 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
613 b4_percent_code_get([[top]])[]dnl
614 m4_if(b4_prefix, [yy], [],
616 // Take the name prefix into account.
617 #define yylex b4_prefix[]lex])[
619 /* First part of user declarations. */
620 ]b4_user_pre_prologue[
622 #include "@basename(]b4_spec_defines_file[@)"
624 /* User implementation prologue. */
625 ]b4_user_post_prologue
626 b4_percent_code_get[]dnl
628 [#ifndef YY_
629 # if YYENABLE_NLS
630 # if ENABLE_NLS
631 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
632 # define YY_(msgid) dgettext ("bison-runtime", msgid)
633 # endif
634 # endif
635 # ifndef YY_
636 # define YY_(msgid) msgid
637 # endif
638 #endif
640 /* Suppress unused-variable warnings by "using" E. */
641 #define YYUSE(e) ((void) (e))
643 /* Enable debugging if requested. */
644 #if YYDEBUG
646 /* A pseudo ostream that takes yydebug_ into account. */
647 # define YYCDEBUG if (yydebug_) (*yycdebug_)
649 # define YY_SYMBOL_PRINT(Title, Symbol) \
650 do { \
651 if (yydebug_) \
653 *yycdebug_ << Title << ' '; \
654 yy_print_ (*yycdebug_, Symbol); \
655 *yycdebug_ << std::endl; \
657 } while (false)
659 # define YY_REDUCE_PRINT(Rule) \
660 do { \
661 if (yydebug_) \
662 yy_reduce_print_ (Rule); \
663 } while (false)
665 # define YY_STACK_PRINT() \
666 do { \
667 if (yydebug_) \
668 yystack_print_ (); \
669 } while (false)
671 #else /* !YYDEBUG */
673 # define YYCDEBUG if (false) std::cerr
674 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
675 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
676 # define YY_STACK_PRINT() static_cast<void>(0)
678 #endif /* !YYDEBUG */
680 #define yyerrok (yyerrstatus_ = 0)
681 #define yyclearin (yyempty = true)
683 #define YYACCEPT goto yyacceptlab
684 #define YYABORT goto yyabortlab
685 #define YYERROR goto yyerrorlab
686 #define YYRECOVERING() (!!yyerrstatus_)
688 ]b4_namespace_open[]b4_error_verbose_if([[
690 /* Return YYSTR after stripping away unnecessary quotes and
691 backslashes, so that it's suitable for yyerror. The heuristic is
692 that double-quoting is unnecessary unless the string contains an
693 apostrophe, a comma, or backslash (other than backslash-backslash).
694 YYSTR is taken from yytname. */
695 std::string
696 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
698 if (*yystr == '"')
700 std::string yyr = "";
701 char const *yyp = yystr;
703 for (;;)
704 switch (*++yyp)
706 case '\'':
707 case ',':
708 goto do_not_strip_quotes;
710 case '\\':
711 if (*++yyp != '\\')
712 goto do_not_strip_quotes;
713 /* Fall through. */
714 default:
715 yyr += *yyp;
716 break;
718 case '"':
719 return yyr;
721 do_not_strip_quotes: ;
724 return yystr;
726 ]])[
728 /// Build a parser object.
729 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
730 :])[
731 #if YYDEBUG
732 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
733 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
734 #endif]b4_parse_param_cons[
738 ]b4_parser_class_name::~b4_parser_class_name[ ()
743 /*---------------.
744 | Symbol types. |
745 `---------------*/
747 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[
749 // stack_symbol_type.
750 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
751 : super_type ()
752 , state ()
756 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (]b4_args(
757 [state_type s],
758 [const semantic_type& v],
759 b4_locations_if([const location_type& l]))[)
760 : super_type (v]b4_locations_if([, l])[)
761 , state (s)
766 ]b4_parser_class_name[::stack_symbol_type::type_get_ () const
768 return yystos_[state];
772 template <typename Exact>
773 void
774 ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
775 symbol_base_type<Exact>& yysym) const
777 int yytype = yysym.type_get ();
778 YYUSE (yymsg);
779 if (yymsg)
780 YY_SYMBOL_PRINT (yymsg, yysym);
782 // User destructor.
783 switch (yytype)
785 ]b4_symbol_foreach([b4_symbol_destructor])dnl
786 [ default:
787 break;
788 }]b4_variant_if([
790 // Type destructor.
791 b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
794 #if YYDEBUG
795 template <typename Exact>
796 void
797 ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
798 const symbol_base_type<Exact>& yysym) const
800 int yytype = yysym.type_get ();
801 yyo << (yytype < yyntokens_ ? "token" : "nterm")
802 << ' ' << yytname_[yytype] << " ("]b4_locations_if([
803 << yysym.location << ": "])[;
804 switch (yytype)
806 ]b4_symbol_foreach([b4_symbol_printer])dnl
807 [ default:
808 break;
810 yyo << ')';
812 #endif
814 void
815 ]b4_parser_class_name[::yypush_ (const char* m, state_type s,
816 symbol_type& sym)
818 if (m)
819 YY_SYMBOL_PRINT (m, sym);
820 ]b4_variant_if(
821 [[ yystack_.push (stack_symbol_type (]b4_args(
822 [s],
823 [semantic_type()],
824 b4_locations_if([sym.location]))[));
825 ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]],
826 [build], [sym.value])],
827 [[ yystack_.push (stack_symbol_type (]b4_args(
828 [s],
829 [sym.value],
830 b4_locations_if([sym.location]))[));]])[
833 void
834 ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
836 if (m)
837 YY_SYMBOL_PRINT (m, s);
838 ]b4_variant_if(
839 [[ yystack_.push (stack_symbol_type (]b4_args(
840 [s.state],
841 [semantic_type()],
842 b4_locations_if([s.location]))[));
843 ]b4_symbol_variant([[yystos_[s.state]]], [[yystack_[0].value]],
844 [build], [s.value])],
845 [ yystack_.push (s);])[
848 void
849 ]b4_parser_class_name[::yypop_ (unsigned int n)
851 yystack_.pop (n);
854 #if YYDEBUG
855 std::ostream&
856 ]b4_parser_class_name[::debug_stream () const
858 return *yycdebug_;
861 void
862 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
864 yycdebug_ = &o;
868 ]b4_parser_class_name[::debug_level_type
869 ]b4_parser_class_name[::debug_level () const
871 return yydebug_;
874 void
875 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
877 yydebug_ = l;
879 #endif
882 ]b4_parser_class_name[::parse ()
884 /// Whether yyla contains a lookahead.
885 bool yyempty = true;
887 /* State. */
888 int yyn;
889 int yylen = 0;
890 int yystate = 0;
892 /* Error handling. */
893 int yynerrs_ = 0;
894 int yyerrstatus_ = 0;
896 /// The lookahead symbol.
897 symbol_type yyla;]b4_locations_if([[
899 /// The locations where the error started and ended.
900 stack_symbol_type yyerror_range[2];]])[
902 /// $$ and @@$.
903 stack_symbol_type yylhs;
905 /// The return value of parse().
906 int yyresult;
908 YYCDEBUG << "Starting parse" << std::endl;
910 ]m4_ifdef([b4_initial_action], [
911 m4_pushdef([b4_at_dollar], [yyla.location])dnl
912 m4_pushdef([b4_dollar_dollar], [yyla.value])dnl
913 /* User initialization code. */
914 b4_user_initial_action
915 m4_popdef([b4_dollar_dollar])dnl
916 m4_popdef([b4_at_dollar])])dnl
918 [ /* Initialize the stack. The initial state will be set in
919 yynewstate, since the latter expects the semantical and the
920 location values to have been already stored, initialize these
921 stacks with a primary value. */
922 yystack_ = stack_type (0);
923 yypush_ (0, 0, yyla);
925 // A new state was pushed on the stack.
926 // Invariant: yystate == yystack_[0].state, i.e.,
927 // yystate was just pushed onto the state stack.
928 yynewstate:
929 YYCDEBUG << "Entering state " << yystate << std::endl;
931 /* Accept? */
932 if (yystate == yyfinal_)
933 goto yyacceptlab;
935 goto yybackup;
937 /* Backup. */
938 yybackup:
940 /* Try to take a decision without lookahead. */
941 yyn = yypact_[yystate];
942 if (yyn == yypact_ninf_)
943 goto yydefault;
945 /* Read a lookahead token. */
946 if (yyempty)
948 YYCDEBUG << "Reading a token: ";
949 ]b4_lex_symbol_if(
950 [ yyla = b4_c_function_call([yylex], [symbol_type],
951 m4_ifdef([b4_lex_param], b4_lex_param));],
952 [ yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
953 [[YYSTYPE*], [&yyla.value]][]dnl
954 b4_locations_if([, [[location*], [&yyla.location]]])dnl
955 m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
956 yyempty = false;
958 YY_SYMBOL_PRINT ("Next token is", yyla);
960 /* If the proper action on seeing token YYLA.TYPE is to reduce or
961 to detect an error, take that action. */
962 yyn += yyla.type;
963 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
964 goto yydefault;
966 /* Reduce or error. */
967 yyn = yytable_[yyn];
968 if (yyn <= 0)
970 if (yyn == 0 || yyn == yytable_ninf_)
971 goto yyerrlab;
972 yyn = -yyn;
973 goto yyreduce;
976 /* Discard the token being shifted. */
977 yyempty = true;
979 /* Count tokens shifted since error; after three, turn off error
980 status. */
981 if (yyerrstatus_)
982 --yyerrstatus_;
984 /* Shift the lookahead token. */
985 yystate = yyn;
986 yypush_ ("Shifting", yystate, yyla);
987 goto yynewstate;
989 /*-----------------------------------------------------------.
990 | yydefault -- do the default action for the current state. |
991 `-----------------------------------------------------------*/
992 yydefault:
993 yyn = yydefact_[yystate];
994 if (yyn == 0)
995 goto yyerrlab;
996 goto yyreduce;
998 /*-----------------------------.
999 | yyreduce -- Do a reduction. |
1000 `-----------------------------*/
1001 yyreduce:
1002 yylen = yyr2_[yyn];]b4_variant_if([
1003 /* Variants are always initialized to an empty instance of the
1004 correct type. The default $$=$1 action is NOT applied when using
1005 variants. */
1006 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build]),[
1007 /* If YYLEN is nonzero, implement the default value of the action:
1008 `$$ = $1'. Otherwise, use the top of the stack.
1010 Otherwise, the following line sets YYLHS.VALUE to garbage.
1011 This behavior is undocumented and Bison
1012 users should not rely upon it. */
1013 if (yylen)
1014 yylhs.value = yystack_@{yylen - 1@}.value;
1015 else
1016 yylhs.value = yystack_@{0@}.value;])[
1017 ]b4_locations_if([dnl
1019 // Compute the default @@$.
1021 slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
1022 YYLLOC_DEFAULT (yylhs.location, slice, yylen);
1023 }]])[
1025 // Perform the reduction.
1026 YY_REDUCE_PRINT (yyn);
1027 switch (yyn)
1029 ]b4_user_actions[
1030 default:
1031 break;
1033 // Compute post-reduction state.
1034 yyn = yyr1_[yyn];
1035 yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
1036 if (0 <= yystate && yystate <= yylast_
1037 && yycheck_[yystate] == yystack_[yylen].state)
1038 yystate = yytable_[yystate];
1039 else
1040 yystate = yydefgoto_[yyn - yyntokens_];
1041 yylhs.state = yystate;
1042 YY_SYMBOL_PRINT ("-> $$ =", yylhs);
1043 ]b4_variant_if([[
1044 // Destroy the rhs symbols.
1045 for (int i = 0; i < yylen; ++i)
1046 // Destroy a variant which value may have been swapped with
1047 // yylhs.value (for instance if the action was "std::swap($$,
1048 // $1)"). The value of yylhs.value (hence possibly one of these
1049 // rhs symbols) depends on the default contruction for this
1050 // type. In the case of pointers for instance, no
1051 // initialization is done, so the value is junk. Therefore do
1052 // not try to report the value of symbols about to be destroyed
1053 // in the debug trace, it's possibly junk. Hence yymsg = 0.
1054 // Besides, that keeps exactly the same traces as with the other
1055 // Bison skeletons.
1056 yy_destroy_ (0, yystack_[i]);]])[
1058 yypop_ (yylen);
1059 yylen = 0;
1060 YY_STACK_PRINT ();
1062 /* Shift the result of the reduction. */
1063 yypush_ (0, yylhs);
1064 goto yynewstate;
1066 /*--------------------------------------.
1067 | yyerrlab -- here on detecting error. |
1068 `--------------------------------------*/
1069 yyerrlab:
1070 /* If not already recovering from an error, report this error. */
1071 if (!yyerrstatus_)
1073 ++yynerrs_;
1074 error (]b4_args(b4_locations_if([yyla.location]),
1075 [yysyntax_error_ (yystate, yyla.type)])[);
1078 ]b4_locations_if([[
1079 yyerror_range[0].location = yyla.location;]])[
1080 if (yyerrstatus_ == 3)
1082 /* If just tried and failed to reuse lookahead token after an
1083 error, discard it. */
1085 /* Return failure if at end of input. */
1086 if (yyla.type == yyeof_)
1087 YYABORT;
1088 else
1090 yy_destroy_ ("Error: discarding", yyla);
1091 yyempty = true;
1095 /* Else will try to reuse lookahead token after shifting the error
1096 token. */
1097 goto yyerrlab1;
1100 /*---------------------------------------------------.
1101 | yyerrorlab -- error raised explicitly by YYERROR. |
1102 `---------------------------------------------------*/
1103 yyerrorlab:
1105 /* Pacify compilers like GCC when the user code never invokes
1106 YYERROR and the label yyerrorlab therefore never appears in user
1107 code. */
1108 if (false)
1109 goto yyerrorlab;
1111 ]b4_locations_if([[
1112 yyerror_range[0].location = yystack_[yylen - 1].location;]])[
1113 /* Do not reclaim the symbols of the rule which action triggered
1114 this YYERROR. */
1115 yypop_ (yylen);
1116 yylen = 0;
1117 yystate = yystack_[0].state;
1118 goto yyerrlab1;
1120 /*-------------------------------------------------------------.
1121 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1122 `-------------------------------------------------------------*/
1123 yyerrlab1:
1124 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
1126 stack_symbol_type error_token;
1127 for (;;)
1129 yyn = yypact_[yystate];
1130 if (yyn != yypact_ninf_)
1132 yyn += yyterror_;
1133 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
1135 yyn = yytable_[yyn];
1136 if (0 < yyn)
1137 break;
1141 // Pop the current state because it cannot handle the error token.
1142 if (yystack_.size () == 1)
1143 YYABORT;
1144 ]b4_locations_if([[
1145 yyerror_range[0].location = yystack_[0].location;]])[
1146 yy_destroy_ ("Error: popping", yystack_[0]);
1147 yypop_ ();
1148 yystate = yystack_[0].state;
1149 YY_STACK_PRINT ();
1151 ]b4_locations_if([[
1152 yyerror_range[1].location = yyla.location;
1153 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);]])[
1155 /* Shift the error token. */
1156 error_token.state = yystate = yyn;
1157 yypush_ ("Shifting", error_token);
1159 goto yynewstate;
1161 /* Accept. */
1162 yyacceptlab:
1163 yyresult = 0;
1164 goto yyreturn;
1166 /* Abort. */
1167 yyabortlab:
1168 yyresult = 1;
1169 goto yyreturn;
1171 yyreturn:
1172 if (!yyempty)
1173 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
1175 /* Do not reclaim the symbols of the rule which action triggered
1176 this YYABORT or YYACCEPT. */
1177 yypop_ (yylen);
1178 while (yystack_.size () != 1)
1180 yy_destroy_ ("Cleanup: popping", yystack_[0]);
1181 yypop_ ();
1184 return yyresult;
1187 // Generate an error message.
1188 std::string
1189 ]b4_parser_class_name[::yysyntax_error_ (]dnl
1190 b4_error_verbose_if([int yystate, int yytoken],
1191 [int, int])[)
1193 std::string yyres;]b4_error_verbose_if([[
1194 int yyn = yypact_[yystate];
1195 if (yypact_ninf_ < yyn && yyn <= yylast_)
1197 /* Start YYX at -YYN if negative to avoid negative indexes in
1198 YYCHECK. */
1199 int yyxbegin = yyn < 0 ? -yyn : 0;
1201 /* Stay within bounds of both yycheck and yytname. */
1202 int yychecklim = yylast_ - yyn + 1;
1203 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1205 // Number of reported tokens (one for the "unexpected", one per
1206 // "expected").
1207 size_t yycount = 0;
1208 // Its maximum.
1209 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1210 // Arguments of yyformat.
1211 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1212 yyarg[yycount++] = yytname_[yytoken];
1213 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
1214 if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_)
1216 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1218 yycount = 1;
1219 break;
1221 else
1222 yyarg[yycount++] = yytname_[yyx];
1225 char const* yyformat = 0;
1226 switch (yycount)
1228 #define YYCASE_(N, S) \
1229 case N: \
1230 yyformat = S; \
1231 break
1232 YYCASE_(1, YY_("syntax error, unexpected %s"));
1233 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1234 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1235 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1236 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1237 #undef YYCASE_
1239 // Argument number.
1240 size_t yyi = 0;
1241 for (char const* yyp = yyformat; *yyp; ++yyp)
1242 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
1244 yyres += yytnamerr_ (yyarg[yyi++]);
1245 ++yyp;
1247 else
1248 yyres += *yyp;
1250 else
1251 ]])dnl
1252 [ yyres = YY_("syntax error");
1253 return yyres;
1257 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1259 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1261 ]b4_parser_tables_define[
1263 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1264 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1265 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1266 const char*
1267 const ]b4_parser_class_name[::yytname_[] =
1269 ]b4_tname[
1271 #endif
1273 #if YYDEBUG
1274 ]b4_integral_parser_table_define([rline], [b4_rline])[
1276 // Print the state stack on the debug stream.
1277 void
1278 ]b4_parser_class_name[::yystack_print_ ()
1280 *yycdebug_ << "Stack now";
1281 for (stack_type::const_iterator
1282 i = yystack_.begin (),
1283 i_end = yystack_.end ();
1284 i != i_end; ++i)
1285 *yycdebug_ << ' ' << i->state;
1286 *yycdebug_ << std::endl;
1289 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1290 void
1291 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1293 unsigned int yylno = yyrline_[yyrule];
1294 int yynrhs = yyr2_[yyrule];
1295 /* Print the symbols being reduced, and their result. */
1296 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1297 << " (line " << yylno << "):" << std::endl;
1298 /* The symbols being reduced. */
1299 for (int yyi = 0; yyi < yynrhs; yyi++)
1300 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1301 ]b4_rhs_data(yynrhs, yyi + 1)[);
1303 #endif // YYDEBUG
1305 ]b4_lex_symbol_if([], [b4_yytranslate_definition])[
1306 ]b4_namespace_close[
1307 ]b4_epilogue[]dnl
1308 m4_divert_pop(0)
1309 m4_popdef([b4_copyright_years])dnl