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
])));
239 # b4_symbol_constructor_specializations
240 # -------------------------------------
241 # Declare specializations of make_symbol.
242 m4_define([b4_symbol_constructor_specializations
],
244 // Specializations of make_symbol for each symbol type.
245 m4_map([b4_symbol_constructor_specialization_
],
246 m4_defn([b4_symbol_numbers
]))])dnl
251 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
252 # ------------------------------------------------
253 # Define make_symbol for this SYMBOL-NUMBER.
254 m4_define([b4_symbol_constructor_definition_
],
255 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
257 b4_parser_class_name::symbol_type
258 b4_parser_class_name::make_symbol
<b4_parser_class_name::token::b4_symbol([$
1], [id
])> (dnl
259 b4_args(b4_symbol_if([$
1], [has_type
],
260 [const b4_symbol([$
1], [type
])& v
]),
261 b4_locations_if([const location_type
& l
])))
263 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$
1], [id
]))],
264 b4_symbol_if([$
1], [has_type
], [v
]),
265 b4_locations_if([l
])));
271 # b4_symbol_constructor_definitions
272 # ----------------------------------
273 # Define the overloaded versions of make_symbol for all the value types.
274 m4_define([b4_symbol_constructor_definitions
],
275 [[ // symbol_base_type.
276 template <typename Exact
>
277 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
278 : value()]b4_locations_if([
283 template <typename Exact
>
284 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
290 template <typename Exact
>
291 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
292 [const semantic_type
& v
],
293 b4_locations_if([const location_type
& l
]))[)
294 : value(v
)]b4_locations_if([
299 template <typename Exact
>
301 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
303 return static_cast<const Exact
&>(*this);
306 template <typename Exact
>
308 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
310 return static_cast<Exact
&>(*this);
313 template <typename Exact
>
315 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
317 return self ().type_get_ ();
321 ]b4_parser_class_name
[::symbol_type::symbol_type ()
327 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
329 b4_locations_if([const location_type
& l
]))[)
330 : super_type (]b4_locations_if([l
])[)
335 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
337 [const semantic_type
& v
],
338 b4_locations_if([const location_type
& l
]))[)
339 : super_type (v
]b4_locations_if([, l
])[)
345 ]b4_parser_class_name
[::symbol_type::type_get_ () const
351 [ // Implementation of make_symbol for each symbol type.
352 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
355 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
356 # ------------------------------------------------
357 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
359 m4_define([b4_symbol_variant
],
360 [m4_pushdef([b4_dollar_dollar
],
361 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
364 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
368 m4_popdef([b4_dollar_dollar
])dnl
372 # _b4_char_sizeof_counter
373 # -----------------------
374 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
375 m4_define([_b4_char_sizeof_counter
],
378 # _b4_char_sizeof_dummy
379 # ---------------------
380 # At each call return a new C++ identifier.
381 m4_define([_b4_char_sizeof_dummy
],
382 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
383 dummy
[]_b4_char_sizeof_counter
])
386 # b4_char_sizeof_(SYMBOL-NUM)
387 # ---------------------------
388 # A comment describing this symbol.
389 m4_define([b4_char_sizeof_
],
390 [ // b4_symbol([$1], [tag])
393 # b4_char_sizeof(SYMBOL-NUMS)
394 # --------------------------
395 # To be mapped on the list of type names to produce:
397 # char dummy1[sizeof(type_name_1)];
398 # char dummy2[sizeof(type_name_2)];
400 # for defined type names.
401 m4_define([b4_char_sizeof
],
402 [b4_symbol_if([$
1], [has_type
],
404 m4_map([b4_char_sizeof_
], [$@
])dnl
405 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type
])])@
};
409 # b4_yytranslate_definition
410 # -------------------------
411 # Define yytranslate_. Sometimes we want it in the header file,
412 # sometimes the cc file suffices.
413 m4_define([b4_yytranslate_definition
],
414 [[ // Symbol number corresponding to token number t.
415 ]b4_parser_class_name
[::token_number_type
416 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
420 const token_number_type
425 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
426 const token_number_type undef_token_
= ]b4_undef_token_number
[;
428 if (static_cast<int>(t
) <= yyeof_
)
430 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
431 return translate_table
[t
];
438 m4_pushdef([b4_copyright_years
],
439 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
441 m4_define([b4_parser_class_name
],
442 [b4_percent_define_get([[parser_class_name]])])
444 # The header is mandatory.
446 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
449 [# Backward compatibility.
450 m4_define([b4_location_constructors
])
451 m4_include(b4_pkgdatadir
/[location
.cc
])])
453 # We do want M4 expansion after # for CPP macros.
456 @
output(b4_spec_defines_file@
)@
457 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
458 dnl FIXME
: This is wrong
, we want computed header guards
.
460 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
462 #ifndef PARSER_HEADER_H
463 # define PARSER_HEADER_H
465 ]b4_percent_code_get([[requires]])[
467 ]b4_assert_if([#include <cassert>])[
473 ]b4_locations_if([ class position
;
477 /// A char[S] buffer to store and retrieve objects.
479 /// Sort of a variant, but does not keep track of the nature
480 /// of the stored data, since that knowledge is available
481 /// via the current state.
485 /// Whether something is contained.
488 /// Empty construction.
490 variant ()]b4_assert_if([
494 /// Instantiate a \a T in here.
495 template <typename T
>
501 return *new (buffer
) T
;
504 /// Instantiate a \a T in here from \a t.
505 template <typename T
>
511 return *new (buffer
) T(t
);
514 /// Construct and fill.
515 template <typename T
>
517 variant (const T
& t
)]b4_assert_if([
523 /// Accessor to a built \a T.
524 template <typename T
>
529 return reinterpret_cast<T
&>(buffer
);
532 /// Const accessor to a built \a T (for %printer).
533 template <typename T
>
538 return reinterpret_cast<const T
&>(buffer
);
541 /// Swap the content with \a other.
542 template <typename T
>
544 swap(variant
<S
>& other
)
546 std::swap(as
<T
>(), other
.as
<T
>());
549 /// Assign the content of \a other to this.
550 /// Destroys \a other.
551 template <typename T
>
553 build(variant
<S
>& other
)
560 /// Destroy the stored \a T.
561 template <typename T
>
565 as
<T
>().~T();]b4_assert_if([
569 /// A buffer large enough to store any of the semantic values.
575 ]b4_locations_if([#include "location.hh"])[
577 /* Enabling traces. */
579 # define YYDEBUG ]b4_debug_flag[
582 /* Enabling verbose error messages. */
583 #ifdef YYERROR_VERBOSE
584 # undef YYERROR_VERBOSE
585 # define YYERROR_VERBOSE 1
587 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
590 /* Enabling the token table. */
591 #ifndef YYTOKEN_TABLE
592 # define YYTOKEN_TABLE ]b4_token_table[
595 ]b4_locations_if([dnl
596 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
597 If N is 0, then set CURRENT to the empty location which ends
598 the previous symbol: RHS[0] (always defined). */
600 #ifndef YYLLOC_DEFAULT
601 # define YYLLOC_DEFAULT(Current, Rhs, N) \
605 (Current).begin = (Rhs)[1].location.begin; \
606 (Current).end = (Rhs)[N].location.end; \
610 (Current).begin = (Current).end = (Rhs)[0].location.end; \
618 class ]b4_parser_class_name
[
623 [ /// An auxiliary type to compute the largest semantic type.
625 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[};
627 /// Symbol semantic values.
628 typedef variant
<sizeof(union_type
)> semantic_type
;],
629 [ /// Symbol semantic values.
631 [ union semantic_type
634 [m4_if(b4_tag_seen_flag
, 0,
635 [[ typedef int semantic_type
;]],
636 [[ typedef YYSTYPE semantic_type
;]])])])[
638 typedef YYSTYPE semantic_type
;
639 #endif]b4_locations_if([
640 /// Symbol locations.
641 typedef b4_percent_define_get([[location_type]]) location_type
;])[
645 ]b4_token_enums(b4_tokens
)[
648 typedef token::yytokentype token_type
;
650 /// Build a parser object.
651 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
652 virtual ~]b4_parser_class_name
[ ();
655 /// \returns 0 iff parsing succeeded.
656 virtual int parse ();
659 /// The current debugging stream.
660 std::ostream
& debug_stream () const;
661 /// Set the current debugging stream.
662 void set_debug_stream (std::ostream
&);
664 /// Type for debugging levels.
665 typedef int debug_level_type
;
666 /// The current debugging level.
667 debug_level_type
debug_level () const;
668 /// Set the current debugging level.
669 void set_debug_level (debug_level_type l
);
673 /// Report a syntax error.]b4_locations_if([
674 /// \param loc where the syntax error is found.])[
675 /// \param msg a description of the syntax error.
676 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
678 /// Generate an error message.
679 /// \param state the state where the error occurred.
680 /// \param tok the lookahead token.
681 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
684 typedef int state_type
;
686 /// Internal symbol numbers.
687 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
689 /// For a state, the index in \a yytable_ of its portion.
690 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
691 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
693 /// For a state, default rule to reduce.
694 /// Unless\a yytable_ specifies something else to do.
695 /// Zero means the default is an error.
696 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
698 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
699 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
701 /// What to do in a state.
702 /// \a yytable_[yypact_[s]]: what to do in state \a s.
703 /// - if positive, shift that token.
704 /// - if negative, reduce the rule which number is the opposite.
705 /// - if zero, do what YYDEFACT says.
706 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
707 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
709 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
711 /// For a state, its accessing symbol.
712 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
714 /// For a rule, its LHS.
715 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
716 /// For a rule, its RHS length.
717 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
719 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
720 /// For a symbol, its name in clear.
721 static const char* const yytname_
[];
722 #endif]b4_error_verbose_if([
724 /// Convert the symbol name \a n to a form suitable for a diagnostic.
725 static std::string
yytnamerr_ (const char *n
);])[
728 /// For each rule, its source line number.
729 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
730 /// (External) token number corresponding to the (internal) symbol
731 /// number (which must be that of a token).
732 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
733 /// Report on the debug stream that the rule \a r is going to be reduced.
734 virtual void yy_reduce_print_ (int r
);
735 /// Print the state stack on the debug stream.
736 virtual void yystack_print_ ();
740 std::ostream
* yycdebug_
;
743 /// Convert a scanner token number \a t to a symbol number.
744 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
746 /// A complete symbol, with its type.
747 template <typename Exact
>
748 struct symbol_base_type
750 /// Default constructor.
751 inline symbol_base_type ();
753 /// Constructor.]b4_locations_if([
754 inline symbol_base_type (const location_type
& l
)])[;
755 inline symbol_base_type (]b4_args(
756 [const semantic_type
& v
],
757 b4_locations_if([const location_type
& l
]))[);
759 /// Return this with its exact type.
760 const Exact
& self () const;
763 /// Return the type of this symbol.
764 int type_get () const;
766 /// The semantic value.
767 semantic_type value
;]b4_locations_if([
770 location_type location
;])[
774 /// \brief Display a symbol type, value and location.
775 /// \param yyo The output stream.
776 /// \param yysym The symbol.
777 template <typename Exact
>
778 void yy_print_ (std::ostream
& yyo
,
779 const symbol_base_type
<Exact
>& yysym
) const;
782 /// \brief Reclaim the memory associated to a symbol.
783 /// \param yymsg Why this token is reclaimed.
784 /// If null, print nothing.
785 /// \param s The symbol.
786 template <typename Exact
>
787 inline void yy_destroy_ (const char* yymsg
,
788 symbol_base_type
<Exact
>& yysym
) const;
791 /// Element of the stack: a state and its attributes.
792 struct symbol_type
: symbol_base_type
<symbol_type
>
794 /// The parent class.
795 typedef symbol_base_type
<symbol_type
> super_type
;
797 /// Default constructor.
798 inline symbol_type ();
801 inline symbol_type (]b4_args([int t
],
802 [const semantic_type
& v
],
803 b4_locations_if([const location_type
& l
]))[);
805 inline symbol_type (]b4_args([int t
],
806 b4_locations_if([const location_type
& l
]))[);
811 /// Return the type corresponding to this state.
812 inline int type_get_ () const;
815 ]b4_symbol_constructor_declarations
[
818 /// Element of the stack: a state and its attributes.
819 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
821 /// The parent class.
822 typedef symbol_base_type
<stack_symbol_type
> super_type
;
824 /// Default constructor.
825 inline stack_symbol_type ();
828 inline stack_symbol_type (]b4_args([state_type s
],
829 [const semantic_type
& v
],
830 b4_locations_if([const location_type
& l
]))[);
835 /// Return the type corresponding to this state.
836 inline int type_get_ () const;
840 typedef stack
<stack_symbol_type
> stack_type
;
845 /// Push a new state on the stack.
846 /// \param m a debug message to display
847 /// if null, no trace is output.
848 /// \param s the symbol
849 /// \warning the contents of \a s.value is stolen.
850 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
852 /// Push a new look ahead token on the state on the stack.
853 /// \param m a debug message to display
854 /// if null, no trace is output.
855 /// \param s the state
856 /// \param sym the symbol (for its value and location).
857 /// \warning the contents of \a s.value is stolen.
858 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
860 /// Pop \a n symbols the three stacks.
861 inline void yypop_ (unsigned int n
= 1);
867 yylast_
= ]b4_last
[, //< Last index in yytable_.
868 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
870 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
873 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
876 ]b4_parse_param_vars
[
879 ]b4_lex_symbol_if([b4_yytranslate_definition
])[
880 ]b4_symbol_constructor_specializations
[
881 ]b4_lex_symbol_if([b4_symbol_constructor_definitions
])[
884 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
885 [b4_token_defines(b4_tokens
)
888 /* Redirection for backward compatibility. */
889 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
892 b4_percent_code_get([[provides]])[]dnl
894 [#endif /* ! defined PARSER_HEADER_H */]
895 @
output(b4_parser_file_name@
)@
896 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
897 b4_percent_code_get([[top]])[]dnl
898 m4_if(b4_prefix
, [yy
], [],
900 // Take the name prefix into account.
901 #define yylex b4_prefix[]lex])[
903 /* First part of user declarations. */
904 ]b4_user_pre_prologue
[
906 #include "@basename(]b4_spec_defines_file[@)"
908 /* User implementation prologue. */
909 ]b4_user_post_prologue
910 b4_percent_code_get
[]dnl
915 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
916 # define YY_(msgid) dgettext ("bison-runtime", msgid)
920 # define YY_(msgid) msgid
924 /* Suppress unused-variable warnings by "using" E. */
925 #define YYUSE(e) ((void) (e))
927 /* Enable debugging if requested. */
930 /* A pseudo ostream that takes yydebug_ into account. */
931 # define YYCDEBUG if (yydebug_) (*yycdebug_)
933 # define YY_SYMBOL_PRINT(Title, Symbol) \
937 *yycdebug_ << Title << ' '; \
938 yy_print_ (*yycdebug_, Symbol); \
939 *yycdebug_ << std::endl; \
943 # define YY_REDUCE_PRINT(Rule) \
946 yy_reduce_print_ (Rule); \
949 # define YY_STACK_PRINT() \
957 # define YYCDEBUG if (false) std::cerr
958 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
959 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
960 # define YY_STACK_PRINT() static_cast<void>(0)
962 #endif /* !YYDEBUG */
964 #define yyerrok (yyerrstatus_ = 0)
965 #define yyclearin (yyempty = true)
967 #define YYACCEPT goto yyacceptlab
968 #define YYABORT goto yyabortlab
969 #define YYERROR goto yyerrorlab
970 #define YYRECOVERING() (!!yyerrstatus_)
972 ]b4_namespace_open
[]b4_error_verbose_if([[
974 /* Return YYSTR after stripping away unnecessary quotes and
975 backslashes, so that it's suitable for yyerror. The heuristic is
976 that double-quoting is unnecessary unless the string contains an
977 apostrophe, a comma, or backslash (other than backslash-backslash).
978 YYSTR is taken from yytname. */
980 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
984 std::string yyr
= "";
985 char const *yyp
= yystr
;
992 goto do_not_strip_quotes
;
996 goto do_not_strip_quotes
;
1005 do_not_strip_quotes
: ;
1012 /// Build a parser object.
1013 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
1016 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
1017 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
1018 #endif]b4_parse_param_cons[
1022 ]b4_parser_class_name::~b4_parser_class_name
[ ()
1031 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions
])[
1033 // stack_symbol_type.
1034 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
1040 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
1042 [const semantic_type
& v
],
1043 b4_locations_if([const location_type
& l
]))[)
1044 : super_type (v
]b4_locations_if([, l
])[)
1050 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
1052 return yystos_
[state
];
1056 template <typename Exact
>
1058 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
1059 symbol_base_type
<Exact
>& yysym
) const
1061 int yytype
= yysym
.type_get ();
1064 YY_SYMBOL_PRINT (yymsg
, yysym
);
1069 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
1075 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1079 template <typename Exact
>
1081 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1082 const symbol_base_type
<Exact
>& yysym
) const
1084 int yytype
= yysym
.type_get ();
1085 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1086 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1087 << yysym
.location
<< ": "])[;
1090 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1099 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1103 YY_SYMBOL_PRINT (m
, sym
);
1105 [[ yystack_
.push (stack_symbol_type (]b4_args(
1108 b4_locations_if([sym
.location
]))[));
1109 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1110 [build
], [sym
.value
])],
1111 [[ yystack_
.push (stack_symbol_type (]b4_args(
1114 b4_locations_if([sym
.location
]))[));]])[
1118 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1121 YY_SYMBOL_PRINT (m
, s
);
1123 [[ yystack_
.push (stack_symbol_type (]b4_args(
1126 b4_locations_if([s
.location
]))[));
1127 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1128 [build
], [s
.value
])],
1129 [ yystack_
.push (s
);])[
1133 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1140 ]b4_parser_class_name
[::debug_stream () const
1146 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1152 ]b4_parser_class_name
[::debug_level_type
1153 ]b4_parser_class_name
[::debug_level () const
1159 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1166 ]b4_parser_class_name
[::parse ()
1168 /// Whether yyla contains a lookahead.
1169 bool yyempty
= true;
1176 /* Error handling. */
1178 int yyerrstatus_
= 0;
1180 /// The lookahead symbol.
1181 symbol_type yyla
;]b4_locations_if([[
1183 /// The locations where the error started and ended.
1184 stack_symbol_type yyerror_range
[2];]])[
1187 stack_symbol_type yylhs
;
1189 /// The return value of parse().
1192 YYCDEBUG
<< "Starting parse" << std::endl
;
1194 ]m4_ifdef([b4_initial_action
], [
1195 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1196 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1197 /* User initialization code. */
1198 b4_user_initial_action
1199 m4_popdef([b4_dollar_dollar
])dnl
1200 m4_popdef([b4_at_dollar
])])dnl
1202 [ /* Initialize the stack. The initial state will be set in
1203 yynewstate, since the latter expects the semantical and the
1204 location values to have been already stored, initialize these
1205 stacks with a primary value. */
1206 yystack_
= stack_type (0);
1207 yypush_ (0, 0, yyla
);
1209 // A new state was pushed on the stack.
1210 // Invariant: yystate == yystack_[0].state, i.e.,
1211 // yystate was just pushed onto the state stack.
1213 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1216 if (yystate
== yyfinal_
)
1224 /* Try to take a decision without lookahead. */
1225 yyn
= yypact_
[yystate
];
1226 if (yyn
== yypact_ninf_
)
1229 /* Read a lookahead token. */
1232 YYCDEBUG
<< "Reading a token: ";
1234 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1235 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1236 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1237 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1238 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1239 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1242 YY_SYMBOL_PRINT ("Next token is", yyla
);
1244 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1245 to detect an error, take that action. */
1247 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1250 /* Reduce or error. */
1251 yyn
= yytable_
[yyn
];
1254 if (yyn
== 0 || yyn
== yytable_ninf_
)
1260 /* Discard the token being shifted. */
1263 /* Count tokens shifted since error; after three, turn off error
1268 /* Shift the lookahead token. */
1270 yypush_ ("Shifting", yystate
, yyla
);
1273 /*-----------------------------------------------------------.
1274 | yydefault -- do the default action for the current state. |
1275 `-----------------------------------------------------------*/
1277 yyn
= yydefact_
[yystate
];
1282 /*-----------------------------.
1283 | yyreduce -- Do a reduction. |
1284 `-----------------------------*/
1286 yylen
= yyr2_
[yyn
];]b4_variant_if([
1287 /* Variants are always initialized to an empty instance of the
1288 correct type. The default $$=$1 rule is NOT applied when using
1290 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1291 /* If YYLEN is nonzero, implement the default value of the action:
1292 `$$ = $1'. Otherwise, use the top of the stack.
1294 Otherwise, the following line sets YYLHS.VALUE to garbage.
1295 This behavior is undocumented and Bison
1296 users should not rely upon it. */
1298 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1300 yylhs
.value
= yystack_@
{0@
}.value
;])[
1301 ]b4_locations_if([dnl
1303 // Compute the default @@$.
1305 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1306 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1309 // Perform the reduction.
1310 YY_REDUCE_PRINT (yyn
);
1317 // Compute post-reduction state.
1319 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1320 if (0 <= yystate
&& yystate
<= yylast_
1321 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1322 yystate
= yytable_
[yystate
];
1324 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1325 yylhs
.state
= yystate
;
1326 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1328 // Destroy the lhs symbols.
1329 for (int i
= 0; i
< yylen
; ++i
)
1330 // Destroy a variant which value may have be swapped with
1331 // yylhs.value. The value of yylhs.value (hence maybe one of
1332 // these lhs symbols) depends on what does the default
1333 // contruction for this type. In the case of pointers for
1334 // instance, nothing is done, so the value is junk. Therefore
1335 // do not try to report the content in the debug trace, it's
1336 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1337 // traces as with the other Bison skeletons.
1338 yy_destroy_ (0, yystack_
[i
]);]])[
1344 /* Shift the result of the reduction. */
1348 /*------------------------------------.
1349 | yyerrlab -- here on detecting error |
1350 `------------------------------------*/
1352 /* If not already recovering from an error, report this error. */
1356 error (]b4_args(b4_locations_if([yyla
.location
]),
1357 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1361 yyerror_range
[0].location
= yyla
.location
;]])[
1362 if (yyerrstatus_
== 3)
1364 /* If just tried and failed to reuse lookahead token after an
1365 error, discard it. */
1367 /* Return failure if at end of input. */
1368 if (yyla
.type
== yyeof_
)
1372 yy_destroy_ ("Error: discarding", yyla
);
1377 /* Else will try to reuse lookahead token after shifting the error
1382 /*---------------------------------------------------.
1383 | yyerrorlab -- error raised explicitly by YYERROR. |
1384 `---------------------------------------------------*/
1387 /* Pacify compilers like GCC when the user code never invokes
1388 YYERROR and the label yyerrorlab therefore never appears in user
1394 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1395 /* Do not reclaim the symbols of the rule which action triggered
1399 yystate
= yystack_
[0].state
;
1402 /*-------------------------------------------------------------.
1403 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1404 `-------------------------------------------------------------*/
1406 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1408 stack_symbol_type error_token
;
1411 yyn
= yypact_
[yystate
];
1412 if (yyn
!= yypact_ninf_
)
1415 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1417 yyn
= yytable_
[yyn
];
1423 // Pop the current state because it cannot handle the error token.
1424 if (yystack_
.size () == 1)
1427 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1428 yy_destroy_ ("Error: popping", yystack_
[0]);
1430 yystate
= yystack_
[0].state
;
1434 yyerror_range
[1].location
= yyla
.location
;
1435 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1437 /* Shift the error token. */
1438 error_token
.state
= yystate
= yyn
;
1439 yypush_ ("Shifting", error_token
);
1455 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1457 /* Do not reclaim the symbols of the rule which action triggered
1458 this YYABORT or YYACCEPT. */
1460 while (yystack_
.size () != 1)
1462 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1469 // Generate an error message.
1471 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1472 b4_error_verbose_if([int yystate
, int yytoken
],
1475 std::string yyres
;]b4_error_verbose_if([[
1476 int yyn
= yypact_
[yystate
];
1477 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1479 /* Start YYX at -YYN if negative to avoid negative indexes in
1481 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1483 /* Stay within bounds of both yycheck and yytname. */
1484 int yychecklim
= yylast_
- yyn
+ 1;
1485 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1487 // Number of "expected" tokens.
1490 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1491 // Arguments of yyformat.
1492 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1493 yyarg
[yycount
++] = yytname_
[yytoken
];
1494 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1495 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1497 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1503 yyarg
[yycount
++] = yytname_
[yyx
];
1506 char const* yyformat
= 0;
1509 #define YYCASE_(N, S) \
1513 YYCASE_(1, YY_("syntax error, unexpected %s"));
1514 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1515 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1516 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1517 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1522 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1523 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1525 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1533 [ yyres
= YY_("syntax error");
1538 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1540 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1541 ]b4_table_define([pact
], [b4_pact
])[;
1543 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1544 doesn't specify something else to do. Zero means the default is an
1546 ]b4_table_define([defact
], [b4_defact
])[;
1548 /* YYPGOTO[NTERM-NUM]. */
1549 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1551 /* YYDEFGOTO[NTERM-NUM]. */
1552 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1554 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1555 positive, shift that token. If negative, reduce the rule which
1556 number is the opposite. If zero, do what YYDEFACT says. */
1557 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1558 ]b4_table_define([table
], [b4_table
])[;
1561 ]b4_table_define([check
], [b4_check
])[;
1563 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1564 symbol of state STATE-NUM. */
1565 ]b4_table_define([stos
], [b4_stos
])[;
1568 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
1569 (internal) symbol number NUM (which must be that of a token). */
1570 ]b4_table_define([token_number
], [b4_toknum
])[;
1573 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1574 ]b4_table_define([r1
], [b4_r1
])[;
1576 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1577 ]b4_table_define([r2
], [b4_r2
])[;
1579 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1580 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1581 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1583 const ]b4_parser_class_name
[::yytname_
[] =
1590 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1591 ]b4_table_define([rline
], [b4_rline
])[;
1593 // Print the state stack on the debug stream.
1595 ]b4_parser_class_name
[::yystack_print_ ()
1597 *yycdebug_
<< "Stack now";
1598 for (stack_type::const_iterator
1599 i
= yystack_
.begin (),
1600 i_end
= yystack_
.end ();
1602 *yycdebug_
<< ' ' << i
->state
;
1603 *yycdebug_
<< std::endl
;
1606 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1608 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1610 unsigned int yylno
= yyrline_
[yyrule
];
1611 int yynrhs
= yyr2_
[yyrule
];
1612 /* Print the symbols being reduced, and their result. */
1613 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1614 << " (line " << yylno
<< "):" << std::endl
;
1615 /* The symbols being reduced. */
1616 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1617 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1618 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1622 ]b4_lex_symbol_if([], [b4_yytranslate_definition
])[
1623 ]b4_namespace_close
[
1626 @
output(b4_dir_prefix
[]stack
.hh@
)@
1627 b4_copyright([Stack handling
for Bison parsers in C
++])[
1629 #ifndef BISON_STACK_HH
1630 # define BISON_STACK_HH
1635 template <class T
, class S
= std::deque
<T
> >
1640 // Hide our reversed order.
1641 typedef typename
S::reverse_iterator iterator
;
1642 typedef typename
S::const_reverse_iterator const_iterator
;
1648 stack (unsigned int n
) : seq_ (n
)
1654 operator [] (unsigned int i
)
1661 operator [] (unsigned int i
) const
1670 seq_
.push_front (t
);
1675 pop (unsigned int n
= 1)
1682 typename
S::size_type
1685 return seq_
.size ();
1688 inline const_iterator
begin () const { return seq_
.rbegin (); }
1689 inline const_iterator
end () const { return seq_
.rend (); }
1692 /// The wrapped container.
1696 /// Present a slice of the top of a stack.
1697 template <class T
, class S
= stack
<T
> >
1702 slice (const S
& stack
,
1703 unsigned int range
) : stack_ (stack
),
1710 operator [] (unsigned int i
) const
1712 return stack_
[range_
- i
];
1718 unsigned int range_
;
1720 ]b4_namespace_close
[
1722 #endif // not BISON_STACK_HH[]dnl
1725 m4_popdef([b4_copyright_years
])dnl