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
])
25 # Join with comma, skipping empty arguments.
26 # b4_args calls itself recursively until it sees the first non-empty
27 # argument, then calls _b4_args which prepends each non-empty argument
33 [$
1[]_$
0(m4_shift($@
))],
34 [$
0(m4_shift($@
))])])])
36 # _b4_args(ARGS1, ...)
37 # --------------------
41 [m4_ifval([$
1], [, $
1])[]$
0(m4_shift($@
))])])
44 # b4_table_define(TABLE-NAME, CONTENT)
45 # ------------------------------------
46 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
47 m4_define([b4_table_define
],
48 [const b4_int_type_for([$
2])
49 b4_parser_class_name::yy$
1_
[[]] =
55 # b4_symbol_value_template(VAL, [TYPE])
56 # -------------------------------------
57 # Same as b4_symbol_value, but used in a template method.
58 m4_copy([b4_symbol_value
], [b4_symbol_value_template
])
60 # How the semantic value is extracted when using variants.
62 # b4_symbol_value(VAL, [TYPE])
63 # ----------------------------
64 m4_define([b4_symbol_value
],
69 # b4_symbol_value_template(VAL, [TYPE])
70 # -------------------------------------
71 # Same as b4_symbol_value, but used in a template method.
72 m4_define([b4_symbol_value_template
],
74 [$
1.template as
<$
2>()],
79 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
80 # ----------------------------------------------------------------
81 m4_define([b4_lex_symbol_if
],
82 [b4_percent_define_ifdef([[lex_symbol]], [$
1], [$
2])])
85 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
86 # ------------------------------------------------
87 m4_define([b4_assert_if
],
88 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
91 # b4_lhs_value([TYPE])
92 # --------------------
93 # Expansion of $<TYPE>$.
94 m4_define([b4_lhs_value
],
95 [b4_symbol_value([yylhs
.value
], [$
1])])
101 m4_define([b4_lhs_location
],
105 # b4_rhs_data(RULE-LENGTH, NUM)
106 # -----------------------------
107 # Return the data corresponding to the symbol #NUM, where the current
108 # rule has RULE-LENGTH symbols on RHS.
109 m4_define([b4_rhs_data
],
110 [yystack_@
{($
1) - ($
2)@
}])
113 # b4_rhs_state(RULE-LENGTH, NUM)
114 # -----------------------------
115 # The state corresponding to the symbol #NUM, where the current
116 # rule has RULE-LENGTH symbols on RHS.
117 m4_define([b4_rhs_state
],
118 [b4_rhs_data([$
1], [$
2]).state
])
121 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
122 # --------------------------------------
123 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
125 m4_define([b4_rhs_value
],
126 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
129 # b4_rhs_location(RULE-LENGTH, NUM)
130 # ---------------------------------
131 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
133 m4_define([b4_rhs_location
],
134 [b4_rhs_data([$
1], [$
2]).location
])
137 # b4_symbol(NUM, FIELD)
138 # ---------------------
139 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
141 m4_define([b4_symbol
],
142 [m4_indir([b4_symbol($
1, $
2)])])
145 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
146 # -------------------------------------------
147 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
148 # Otherwise an error.
149 m4_define([b4_symbol_if
],
150 [m4_case(b4_symbol([$
1], [$
2]),
153 [m4_fatal([$
0: field $
2 of $
1 is
not a Boolean
:] b4_symbol([$
1], [$
2]))])])
156 # b4_symbol_actions(FILENAME, LINENO,
157 # SYMBOL-TAG, SYMBOL-NUM,
158 # SYMBOL-ACTION, SYMBOL-TYPENAME)
159 # -------------------------------------------------
160 # Same as in C, but using references instead of pointers.
161 m4_define([b4_symbol_actions
],
162 [m4_pushdef([b4_dollar_dollar
],
163 [b4_symbol_value_template([yysym
.value
], [$
6])])dnl
164 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
166 b4_syncline([$
2], [$
1])
168 b4_syncline([@oline@
], [@ofile@
])
170 m4_popdef([b4_at_dollar
])dnl
171 m4_popdef([b4_dollar_dollar
])dnl
175 # b4_symbol_case_(SYMBOL-NUM)
176 # ---------------------------
177 # Issue a "case NUM" for SYMBOL-NUM.
178 m4_define([b4_symbol_case_
],
179 [ case b4_symbol([$
1], [number
]): // b4_symbol([$1], [tag])
183 # b4_type_action_(NUMS)
184 # ---------------------
185 # Run actions for the symbol NUMS that all have the same type-name.
186 # Skip NUMS that have no type-name.
187 m4_define([b4_type_action_
],
188 [b4_symbol_if([$
1], [has_type
],
189 [m4_map([b4_symbol_case_
], [$@
])[]dnl
190 b4_dollar_dollar([b4_symbol([$
1], [number
])],
191 [b4_symbol([$
1], [tag
])],
192 [b4_symbol([$
1], [type
])]);
198 # b4_symbol_constructor_declaration_(SYMBOL-NUMBERS)
199 # ----------------------------------------------------
200 # Declare the overloaded version of make_symbol for the (common) type of
201 # these SYMBOL-NUMBERS. Use at class-level.
202 m4_define([b4_symbol_constructor_declaration_
],
203 [ template <token_type
>
204 static inline symbol_type
205 make_symbol (b4_args(b4_symbol_if([$
1], [has_type
],
206 [const b4_symbol([$
1], [type
])& v
]),
207 b4_locations_if([const location_type
& l
])));
211 # b4_symbol_constructor_declarations
212 # ----------------------------------
213 # Declare the overloaded versions of make_symbol for all the value types.
214 # Use at class-level.
215 m4_define([b4_symbol_constructor_declarations
],
217 // Declaration of make_symbol for each value type.
218 m4_map([b4_symbol_constructor_declaration_
], m4_defn([b4_type_names
]))])])
222 # b4_symbol_constructor_specialization_(SYMBOL-NUMBER)
223 # ----------------------------------------------------
224 # Declare the specialization of make_symbol for this each SYMBOL-NUMBER.
225 # Specializations cannot be declared at class-level, this must be done
226 # at namespace-level.
227 m4_define([b4_symbol_constructor_specialization_
],
228 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
231 b4_parser_class_name::symbol_type
232 b4_parser_class_name::make_symbol
<b4_parser_class_name::token::b4_symbol([$
1], [id
])> (dnl
233 b4_args(b4_symbol_if([$
1], [has_type
],
234 [const b4_symbol([$
1], [type
])& v
]),
235 b4_locations_if([const location_type
& l
])));
238 # b4_symbol_constructor_specializations
239 # -------------------------------------
240 # Declare specializations of make_symbol.
241 m4_define([b4_symbol_constructor_specializations
],
243 // Specializations of make_symbol for each symbol type.
244 m4_map([b4_symbol_constructor_specialization_
],
245 m4_defn([b4_symbol_numbers
]))])dnl
250 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
251 # ------------------------------------------------
252 # Define make_symbol for this SYMBOL-NUMBER.
253 m4_define([b4_symbol_constructor_definition_
],
254 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
256 b4_parser_class_name::symbol_type
257 b4_parser_class_name::make_symbol
<b4_parser_class_name::token::b4_symbol([$
1], [id
])> (dnl
258 b4_args(b4_symbol_if([$
1], [has_type
],
259 [const b4_symbol([$
1], [type
])& v
]),
260 b4_locations_if([const location_type
& l
])))
262 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$
1], [id
]))],
263 b4_symbol_if([$
1], [has_type
], [v
]),
264 b4_locations_if([l
])));
270 # b4_symbol_constructor_declarations
271 # ----------------------------------
272 # Define the overloaded versions of make_symbol for all the value types.
273 m4_define([b4_symbol_constructor_definitions
],
275 [ // Implementation of make_symbol for each symbol type.
276 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
279 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
280 # ------------------------------------------------
281 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
283 m4_define([b4_symbol_variant
],
284 [m4_pushdef([b4_dollar_dollar
],
285 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
288 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
292 m4_popdef([b4_dollar_dollar
])dnl
296 # _b4_char_sizeof_counter
297 # -----------------------
298 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
299 m4_define([_b4_char_sizeof_counter
],
302 # _b4_char_sizeof_dummy
303 # ---------------------
304 # At each call return a new C++ identifier.
305 m4_define([_b4_char_sizeof_dummy
],
306 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
307 dummy
[]_b4_char_sizeof_counter
])
310 # b4_char_sizeof_(SYMBOL-NUM)
311 # ---------------------------
312 # A comment describing this symbol.
313 m4_define([b4_char_sizeof_
],
314 [ // b4_symbol([$1], [tag])
317 # b4_char_sizeof(SYMBOL-NUMS)
318 # --------------------------
319 # To be mapped on the list of type names to produce:
321 # char dummy1[sizeof(type_name_1)];
322 # char dummy2[sizeof(type_name_2)];
324 # for defined type names.
325 m4_define([b4_char_sizeof
],
326 [b4_symbol_if([$
1], [has_type
],
328 m4_map([b4_char_sizeof_
], [$@
])dnl
329 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type
])])@
};
333 m4_pushdef([b4_copyright_years
],
334 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
336 m4_define([b4_parser_class_name
],
337 [b4_percent_define_get([[parser_class_name]])])
339 # The header is mandatory.
341 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
344 [# Backward compatibility.
345 m4_define([b4_location_constructors
])
346 m4_include(b4_pkgdatadir
/[location
.cc
])])
348 # We do want M4 expansion after # for CPP macros.
351 @
output(b4_spec_defines_file@
)@
352 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
353 dnl FIXME
: This is wrong
, we want computed header guards
.
355 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
357 #ifndef PARSER_HEADER_H
358 # define PARSER_HEADER_H
360 ]b4_percent_code_get([[requires]])[
362 ]b4_assert_if([#include <cassert>])[
368 ]b4_locations_if([ class position
;
372 /// A char[S] buffer to store and retrieve objects.
374 /// Sort of a variant, but does not keep track of the nature
375 /// of the stored data, since that knowledge is available
376 /// via the current state.
380 /// Whether something is contained.
383 /// Empty construction.
385 variant ()]b4_assert_if([
389 /// Instantiate a \a T in here.
390 template <typename T
>
396 return *new (buffer
) T
;
399 /// Instantiate a \a T in here from \a t.
400 template <typename T
>
406 return *new (buffer
) T(t
);
409 /// Construct and fill.
410 template <typename T
>
412 variant (const T
& t
)]b4_assert_if([
418 /// Accessor to a built \a T.
419 template <typename T
>
424 return reinterpret_cast<T
&>(buffer
);
427 /// Const accessor to a built \a T (for %printer).
428 template <typename T
>
433 return reinterpret_cast<const T
&>(buffer
);
436 /// Swap the content with \a other.
437 template <typename T
>
439 swap(variant
<S
>& other
)
441 std::swap(as
<T
>(), other
.as
<T
>());
444 /// Assign the content of \a other to this.
445 /// Destroys \a other.
446 template <typename T
>
448 build(variant
<S
>& other
)
455 /// Destroy the stored \a T.
456 template <typename T
>
460 as
<T
>().~T();]b4_assert_if([
464 /// A buffer large enough to store any of the semantic values.
470 ]b4_locations_if([#include "location.hh"])[
472 /* Enabling traces. */
474 # define YYDEBUG ]b4_debug_flag[
477 /* Enabling verbose error messages. */
478 #ifdef YYERROR_VERBOSE
479 # undef YYERROR_VERBOSE
480 # define YYERROR_VERBOSE 1
482 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
485 /* Enabling the token table. */
486 #ifndef YYTOKEN_TABLE
487 # define YYTOKEN_TABLE ]b4_token_table[
490 ]b4_locations_if([dnl
491 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
492 If N is 0, then set CURRENT to the empty location which ends
493 the previous symbol: RHS[0] (always defined). */
495 #ifndef YYLLOC_DEFAULT
496 # define YYLLOC_DEFAULT(Current, Rhs, N) \
500 (Current).begin = (Rhs)[1].location.begin; \
501 (Current).end = (Rhs)[N].location.end; \
505 (Current).begin = (Current).end = (Rhs)[0].location.end; \
513 class ]b4_parser_class_name
[
518 [ /// An auxiliary type to compute the largest semantic type.
520 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[};
522 /// Symbol semantic values.
523 typedef variant
<sizeof(union_type
)> semantic_type
;],
524 [ /// Symbol semantic values.
526 [ union semantic_type
529 [m4_if(b4_tag_seen_flag
, 0,
530 [[ typedef int semantic_type
;]],
531 [[ typedef YYSTYPE semantic_type
;]])])])[
533 typedef YYSTYPE semantic_type
;
534 #endif]b4_locations_if([
535 /// Symbol locations.
536 typedef b4_percent_define_get([[location_type]]) location_type
;])[
540 ]b4_token_enums(b4_tokens
)[
543 typedef token::yytokentype token_type
;
545 /// Build a parser object.
546 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
547 virtual ~]b4_parser_class_name
[ ();
550 /// \returns 0 iff parsing succeeded.
551 virtual int parse ();
554 /// The current debugging stream.
555 std::ostream
& debug_stream () const;
556 /// Set the current debugging stream.
557 void set_debug_stream (std::ostream
&);
559 /// Type for debugging levels.
560 typedef int debug_level_type
;
561 /// The current debugging level.
562 debug_level_type
debug_level () const;
563 /// Set the current debugging level.
564 void set_debug_level (debug_level_type l
);
568 /// Report a syntax error.]b4_locations_if([
569 /// \param loc where the syntax error is found.])[
570 /// \param msg a description of the syntax error.
571 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
573 /// Generate an error message.
574 /// \param state the state where the error occurred.
575 /// \param tok the lookahead token.
576 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
579 typedef int state_type
;
581 /// Internal symbol numbers.
582 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
584 /// For a state, the index in \a yytable_ of its portion.
585 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
586 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
588 /// For a state, default rule to reduce.
589 /// Unless\a yytable_ specifies something else to do.
590 /// Zero means the default is an error.
591 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
593 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
594 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
596 /// What to do in a state.
597 /// \a yytable_[yypact_[s]]: what to do in state \a s.
598 /// - if positive, shift that token.
599 /// - if negative, reduce the rule which number is the opposite.
600 /// - if zero, do what YYDEFACT says.
601 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
602 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
604 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
606 /// For a state, its accessing symbol.
607 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
609 /// For a rule, its LHS.
610 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
611 /// For a rule, its RHS length.
612 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
614 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
615 /// For a symbol, its name in clear.
616 static const char* const yytname_
[];
617 #endif]b4_error_verbose_if([
619 /// Convert the symbol name \a n to a form suitable for a diagnostic.
620 static std::string
yytnamerr_ (const char *n
);])[
623 /// For each rule, its source line number.
624 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
625 /// For each scanner token number, its symbol number.
626 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
627 /// Report on the debug stream that the rule \a r is going to be reduced.
628 virtual void yy_reduce_print_ (int r
);
629 /// Print the state stack on the debug stream.
630 virtual void yystack_print_ ();
634 std::ostream
* yycdebug_
;
637 /// Convert a scanner token number \a t to a symbol number.
638 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if(
639 [token_type
], [int])[ t
);
641 /// A complete symbol, with its type.
642 template <typename Exact
>
643 struct symbol_base_type
645 /// Default constructor.
646 inline symbol_base_type ();
648 /// Constructor.]b4_locations_if([
649 inline symbol_base_type (const location_type
& l
)])[;
650 inline symbol_base_type (]b4_args(
651 [const semantic_type
& v
],
652 b4_locations_if([const location_type
& l
]))[);
654 /// Return this with its exact type.
655 const Exact
& self () const;
658 /// Return the type of this symbol.
659 int type_get () const;
661 /// The semantic value.
662 semantic_type value
;]b4_locations_if([
665 location_type location
;])[
669 /// \brief Display a symbol type, value and location.
670 /// \param yyo The output stream.
671 /// \param yysym The symbol.
672 template <typename Exact
>
673 void yy_print_ (std::ostream
& yyo
,
674 const symbol_base_type
<Exact
>& yysym
) const;
677 /// \brief Reclaim the memory associated to a symbol.
678 /// \param yymsg Why this token is reclaimed.
679 /// If null, print nothing.
680 /// \param s The symbol.
681 template <typename Exact
>
682 inline void yy_destroy_ (const char* yymsg
,
683 symbol_base_type
<Exact
>& yysym
) const;
686 /// Element of the stack: a state and its attributes.
687 struct symbol_type
: symbol_base_type
<symbol_type
>
689 /// The parent class.
690 typedef symbol_base_type
<symbol_type
> super_type
;
692 /// Default constructor.
693 inline symbol_type ();
696 inline symbol_type (]b4_args([int t
],
697 [const semantic_type
& v
],
698 b4_locations_if([const location_type
& l
]))[);
700 inline symbol_type (]b4_args([int t
],
701 b4_locations_if([const location_type
& l
]))[);
706 /// Return the type corresponding to this state.
707 inline int type_get_ () const;
710 ]b4_symbol_constructor_declarations
[
713 /// Element of the stack: a state and its attributes.
714 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
716 /// The parent class.
717 typedef symbol_base_type
<stack_symbol_type
> super_type
;
719 /// Default constructor.
720 inline stack_symbol_type ();
723 inline stack_symbol_type (]b4_args([state_type s
],
724 [const semantic_type
& v
],
725 b4_locations_if([const location_type
& l
]))[);
730 /// Return the type corresponding to this state.
731 inline int type_get_ () const;
735 typedef stack
<stack_symbol_type
> stack_type
;
740 /// Push a new state on the stack.
741 /// \param m a debug message to display
742 /// if null, no trace is output.
743 /// \param s the symbol
744 /// \warning the contents of \a s.value is stolen.
745 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
747 /// Push a new look ahead token on the state on the stack.
748 /// \param m a debug message to display
749 /// if null, no trace is output.
750 /// \param s the state
751 /// \param sym the symbol (for its value and location).
752 /// \warning the contents of \a s.value is stolen.
753 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
755 /// Pop \a n symbols the three stacks.
756 inline void yypop_ (unsigned int n
= 1);
762 yylast_
= ]b4_last
[, //< Last index in yytable_.
763 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
765 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
768 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
771 ]b4_parse_param_vars
[
773 ]b4_symbol_constructor_specializations
[
776 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
777 [b4_token_defines(b4_tokens
)
780 /* Redirection for backward compatibility. */
781 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
784 b4_percent_code_get([[provides]])[]dnl
786 [#endif /* ! defined PARSER_HEADER_H */]
787 @
output(b4_parser_file_name@
)@
788 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
789 b4_percent_code_get([[top]])[]dnl
790 m4_if(b4_prefix
, [yy
], [],
792 // Take the name prefix into account.
793 #define yylex b4_prefix[]lex])[
795 /* First part of user declarations. */
796 ]b4_user_pre_prologue
[
798 #include "@basename(]b4_spec_defines_file[@)"
800 /* User implementation prologue. */
801 ]b4_user_post_prologue
802 b4_percent_code_get
[]dnl
807 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
808 # define YY_(msgid) dgettext ("bison-runtime", msgid)
812 # define YY_(msgid) msgid
816 /* Suppress unused-variable warnings by "using" E. */
817 #define YYUSE(e) ((void) (e))
819 /* Enable debugging if requested. */
822 /* A pseudo ostream that takes yydebug_ into account. */
823 # define YYCDEBUG if (yydebug_) (*yycdebug_)
825 # define YY_SYMBOL_PRINT(Title, Symbol) \
829 *yycdebug_ << Title << ' '; \
830 yy_print_ (*yycdebug_, Symbol); \
831 *yycdebug_ << std::endl; \
835 # define YY_REDUCE_PRINT(Rule) \
838 yy_reduce_print_ (Rule); \
841 # define YY_STACK_PRINT() \
849 # define YYCDEBUG if (false) std::cerr
850 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
851 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
852 # define YY_STACK_PRINT() static_cast<void>(0)
854 #endif /* !YYDEBUG */
856 #define yyerrok (yyerrstatus_ = 0)
857 #define yyclearin (yyempty = true)
859 #define YYACCEPT goto yyacceptlab
860 #define YYABORT goto yyabortlab
861 #define YYERROR goto yyerrorlab
862 #define YYRECOVERING() (!!yyerrstatus_)
864 ]b4_namespace_open
[]b4_error_verbose_if([[
866 /* Return YYSTR after stripping away unnecessary quotes and
867 backslashes, so that it's suitable for yyerror. The heuristic is
868 that double-quoting is unnecessary unless the string contains an
869 apostrophe, a comma, or backslash (other than backslash-backslash).
870 YYSTR is taken from yytname. */
872 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
876 std::string yyr
= "";
877 char const *yyp
= yystr
;
884 goto do_not_strip_quotes
;
888 goto do_not_strip_quotes
;
897 do_not_strip_quotes
: ;
904 /// Build a parser object.
905 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
908 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
909 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
910 #endif]b4_parse_param_cons[
914 ]b4_parser_class_name::~b4_parser_class_name
[ ()
924 template <typename Exact
>
925 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
926 : value()]b4_locations_if([
931 template <typename Exact
>
932 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
938 template <typename Exact
>
939 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
940 [const semantic_type
& v
],
941 b4_locations_if([const location_type
& l
]))[)
942 : value(v
)]b4_locations_if([
947 template <typename Exact
>
949 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
951 return static_cast<const Exact
&>(*this);
954 template <typename Exact
>
956 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
958 return static_cast<Exact
&>(*this);
961 template <typename Exact
>
963 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
965 return self ().type_get_ ();
969 ]b4_parser_class_name
[::symbol_type::symbol_type ()
975 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
977 b4_locations_if([const location_type
& l
]))[)
978 : super_type (]b4_locations_if([l
])[)
983 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
985 [const semantic_type
& v
],
986 b4_locations_if([const location_type
& l
]))[)
987 : super_type (v
]b4_locations_if([, l
])[)
993 ]b4_parser_class_name
[::symbol_type::type_get_ () const
998 ]b4_symbol_constructor_definitions
[
1000 // stack_symbol_type.
1001 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
1007 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
1009 [const semantic_type
& v
],
1010 b4_locations_if([const location_type
& l
]))[)
1011 : super_type (v
]b4_locations_if([, l
])[)
1017 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
1019 return yystos_
[state
];
1023 template <typename Exact
>
1025 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
1026 symbol_base_type
<Exact
>& yysym
) const
1028 int yytype
= yysym
.type_get ();
1031 YY_SYMBOL_PRINT (yymsg
, yysym
);
1036 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
1042 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1046 template <typename Exact
>
1048 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1049 const symbol_base_type
<Exact
>& yysym
) const
1051 int yytype
= yysym
.type_get ();
1052 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1053 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1054 << yysym
.location
<< ": "])[;
1057 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1066 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1070 YY_SYMBOL_PRINT (m
, sym
);
1072 [[ yystack_
.push (stack_symbol_type (]b4_args(
1075 b4_locations_if([sym
.location
]))[));
1076 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1077 [build
], [sym
.value
])],
1078 [[ yystack_
.push (stack_symbol_type (]b4_args(
1081 b4_locations_if([sym
.location
]))[));]])[
1085 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1088 YY_SYMBOL_PRINT (m
, s
);
1090 [[ yystack_
.push (stack_symbol_type (]b4_args(
1093 b4_locations_if([s
.location
]))[));
1094 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1095 [build
], [s
.value
])],
1096 [ yystack_
.push (s
);])[
1100 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1107 ]b4_parser_class_name
[::debug_stream () const
1113 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1119 ]b4_parser_class_name
[::debug_level_type
1120 ]b4_parser_class_name
[::debug_level () const
1126 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1133 ]b4_parser_class_name
[::parse ()
1135 /// Whether yyla contains a lookahead.
1136 bool yyempty
= true;
1143 /* Error handling. */
1145 int yyerrstatus_
= 0;
1147 /// The lookahead symbol.
1148 symbol_type yyla
;]b4_locations_if([[
1150 /// The locations where the error started and ended.
1151 stack_symbol_type yyerror_range
[2];]])[
1154 stack_symbol_type yylhs
;
1156 /// The return value of parse().
1159 YYCDEBUG
<< "Starting parse" << std::endl
;
1161 ]m4_ifdef([b4_initial_action
], [
1162 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1163 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1164 /* User initialization code. */
1165 b4_user_initial_action
1166 m4_popdef([b4_dollar_dollar
])dnl
1167 m4_popdef([b4_at_dollar
])])dnl
1169 [ /* Initialize the stack. The initial state will be set in
1170 yynewstate, since the latter expects the semantical and the
1171 location values to have been already stored, initialize these
1172 stacks with a primary value. */
1173 yystack_
= stack_type (0);
1174 yypush_ (0, 0, yyla
);
1176 // A new state was pushed on the stack.
1177 // Invariant: yystate == yystack_[0].state, i.e.,
1178 // yystate was just pushed onto the state stack.
1180 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1183 if (yystate
== yyfinal_
)
1191 /* Try to take a decision without lookahead. */
1192 yyn
= yypact_
[yystate
];
1193 if (yyn
== yypact_ninf_
)
1196 /* Read a lookahead token. */
1199 YYCDEBUG
<< "Reading a token: ";
1201 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1202 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1203 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1204 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1205 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1206 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1209 YY_SYMBOL_PRINT ("Next token is", yyla
);
1211 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1212 to detect an error, take that action. */
1214 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1217 /* Reduce or error. */
1218 yyn
= yytable_
[yyn
];
1221 if (yyn
== 0 || yyn
== yytable_ninf_
)
1227 /* Discard the token being shifted. */
1230 /* Count tokens shifted since error; after three, turn off error
1235 /* Shift the lookahead token. */
1237 yypush_ ("Shifting", yystate
, yyla
);
1240 /*-----------------------------------------------------------.
1241 | yydefault -- do the default action for the current state. |
1242 `-----------------------------------------------------------*/
1244 yyn
= yydefact_
[yystate
];
1249 /*-----------------------------.
1250 | yyreduce -- Do a reduction. |
1251 `-----------------------------*/
1253 yylen
= yyr2_
[yyn
];]b4_variant_if([
1254 /* Variants are always initialized to an empty instance of the
1255 correct type. The default $$=$1 rule is NOT applied when using
1257 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1258 /* If YYLEN is nonzero, implement the default value of the action:
1259 `$$ = $1'. Otherwise, use the top of the stack.
1261 Otherwise, the following line sets YYLHS.VALUE to garbage.
1262 This behavior is undocumented and Bison
1263 users should not rely upon it. */
1265 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1267 yylhs
.value
= yystack_@
{0@
}.value
;])[
1268 ]b4_locations_if([dnl
1270 // Compute the default @@$.
1272 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1273 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1276 // Perform the reduction.
1277 YY_REDUCE_PRINT (yyn
);
1284 // Compute post-reduction state.
1286 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1287 if (0 <= yystate
&& yystate
<= yylast_
1288 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1289 yystate
= yytable_
[yystate
];
1291 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1292 yylhs
.state
= yystate
;
1293 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1295 // Destroy the lhs symbols.
1296 for (int i
= 0; i
< yylen
; ++i
)
1297 // Destroy a variant which value may have be swapped with
1298 // yylhs.value. The value of yylhs.value (hence maybe one of
1299 // these lhs symbols) depends on what does the default
1300 // contruction for this type. In the case of pointers for
1301 // instance, nothing is done, so the value is junk. Therefore
1302 // do not try to report the content in the debug trace, it's
1303 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1304 // traces as with the other Bison skeletons.
1305 yy_destroy_ (0, yystack_
[i
]);]])[
1311 /* Shift the result of the reduction. */
1315 /*------------------------------------.
1316 | yyerrlab -- here on detecting error |
1317 `------------------------------------*/
1319 /* If not already recovering from an error, report this error. */
1323 error (]b4_args(b4_locations_if([yyla
.location
]),
1324 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1328 yyerror_range
[0].location
= yyla
.location
;]])[
1329 if (yyerrstatus_
== 3)
1331 /* If just tried and failed to reuse lookahead token after an
1332 error, discard it. */
1334 /* Return failure if at end of input. */
1335 if (yyla
.type
== yyeof_
)
1339 yy_destroy_ ("Error: discarding", yyla
);
1344 /* Else will try to reuse lookahead token after shifting the error
1349 /*---------------------------------------------------.
1350 | yyerrorlab -- error raised explicitly by YYERROR. |
1351 `---------------------------------------------------*/
1354 /* Pacify compilers like GCC when the user code never invokes
1355 YYERROR and the label yyerrorlab therefore never appears in user
1361 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1362 /* Do not reclaim the symbols of the rule which action triggered
1366 yystate
= yystack_
[0].state
;
1369 /*-------------------------------------------------------------.
1370 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1371 `-------------------------------------------------------------*/
1373 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1375 stack_symbol_type error_token
;
1378 yyn
= yypact_
[yystate
];
1379 if (yyn
!= yypact_ninf_
)
1382 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1384 yyn
= yytable_
[yyn
];
1390 // Pop the current state because it cannot handle the error token.
1391 if (yystack_
.size () == 1)
1394 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1395 yy_destroy_ ("Error: popping", yystack_
[0]);
1397 yystate
= yystack_
[0].state
;
1401 yyerror_range
[1].location
= yyla
.location
;
1402 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1404 /* Shift the error token. */
1405 error_token
.state
= yystate
= yyn
;
1406 yypush_ ("Shifting", error_token
);
1422 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1424 /* Do not reclaim the symbols of the rule which action triggered
1425 this YYABORT or YYACCEPT. */
1427 while (yystack_
.size () != 1)
1429 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1436 // Generate an error message.
1438 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1439 b4_error_verbose_if([int yystate
, int yytoken
],
1442 std::string yyres
;]b4_error_verbose_if([[
1443 int yyn
= yypact_
[yystate
];
1444 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1446 /* Start YYX at -YYN if negative to avoid negative indexes in
1448 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1450 /* Stay within bounds of both yycheck and yytname. */
1451 int yychecklim
= yylast_
- yyn
+ 1;
1452 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1454 // Number of "expected" tokens.
1457 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1458 // Arguments of yyformat.
1459 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1460 yyarg
[yycount
++] = yytname_
[yytoken
];
1461 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1462 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1464 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1470 yyarg
[yycount
++] = yytname_
[yyx
];
1473 char const* yyformat
= 0;
1476 #define YYCASE_(N, S) \
1480 YYCASE_(1, YY_("syntax error, unexpected %s"));
1481 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1482 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1483 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1484 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1489 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1490 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1492 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1500 [ yyres
= YY_("syntax error");
1505 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1507 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1508 ]b4_table_define([pact
], [b4_pact
])[;
1510 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1511 doesn't specify something else to do. Zero means the default is an
1513 ]b4_table_define([defact
], [b4_defact
])[;
1515 /* YYPGOTO[NTERM-NUM]. */
1516 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1518 /* YYDEFGOTO[NTERM-NUM]. */
1519 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1521 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1522 positive, shift that token. If negative, reduce the rule which
1523 number is the opposite. If zero, do what YYDEFACT says. */
1524 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1525 ]b4_table_define([table
], [b4_table
])[;
1528 ]b4_table_define([check
], [b4_check
])[;
1530 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1531 symbol of state STATE-NUM. */
1532 ]b4_table_define([stos
], [b4_stos
])[;
1535 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1537 ]b4_table_define([token_number
], [b4_toknum
])[;
1540 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1541 ]b4_table_define([r1
], [b4_r1
])[;
1543 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1544 ]b4_table_define([r2
], [b4_r2
])[;
1546 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1547 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1548 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1550 const ]b4_parser_class_name
[::yytname_
[] =
1557 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1558 ]b4_table_define([rline
], [b4_rline
])[;
1560 // Print the state stack on the debug stream.
1562 ]b4_parser_class_name
[::yystack_print_ ()
1564 *yycdebug_
<< "Stack now";
1565 for (stack_type::const_iterator
1566 i
= yystack_
.begin (),
1567 i_end
= yystack_
.end ();
1569 *yycdebug_
<< ' ' << i
->state
;
1570 *yycdebug_
<< std::endl
;
1573 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1575 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1577 unsigned int yylno
= yyrline_
[yyrule
];
1578 int yynrhs
= yyr2_
[yyrule
];
1579 /* Print the symbols being reduced, and their result. */
1580 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1581 << " (line " << yylno
<< "):" << std::endl
;
1582 /* The symbols being reduced. */
1583 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1584 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1585 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1589 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1590 ]b4_parser_class_name
[::token_number_type
1591 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
1595 const token_number_type
1600 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
1601 const token_number_type undef_token_
= ]b4_undef_token_number
[;
1603 if (static_cast<int>(t
) <= yyeof_
)
1605 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
1606 return translate_table
[t
];
1608 return undef_token_
;
1611 ]b4_namespace_close
[
1614 @
output(b4_dir_prefix
[]stack
.hh@
)@
1615 b4_copyright([Stack handling
for Bison parsers in C
++])[
1617 #ifndef BISON_STACK_HH
1618 # define BISON_STACK_HH
1623 template <class T
, class S
= std::deque
<T
> >
1628 // Hide our reversed order.
1629 typedef typename
S::reverse_iterator iterator
;
1630 typedef typename
S::const_reverse_iterator const_iterator
;
1636 stack (unsigned int n
) : seq_ (n
)
1642 operator [] (unsigned int i
)
1649 operator [] (unsigned int i
) const
1658 seq_
.push_front (t
);
1663 pop (unsigned int n
= 1)
1670 typename
S::size_type
1673 return seq_
.size ();
1676 inline const_iterator
begin () const { return seq_
.rbegin (); }
1677 inline const_iterator
end () const { return seq_
.rend (); }
1680 /// The wrapped container.
1684 /// Present a slice of the top of a stack.
1685 template <class T
, class S
= stack
<T
> >
1690 slice (const S
& stack
,
1691 unsigned int range
) : stack_ (stack
),
1698 operator [] (unsigned int i
) const
1700 return stack_
[range_
- i
];
1706 unsigned int range_
;
1708 ]b4_namespace_close
[
1710 #endif // not BISON_STACK_HH[]dnl
1713 m4_popdef([b4_copyright_years
])dnl