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_definitions
271 # ----------------------------------
272 # Define the overloaded versions of make_symbol for all the value types.
273 m4_define([b4_symbol_constructor_definitions
],
274 [[ // symbol_base_type.
275 template <typename Exact
>
276 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
277 : value()]b4_locations_if([
282 template <typename Exact
>
283 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
289 template <typename Exact
>
290 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
291 [const semantic_type
& v
],
292 b4_locations_if([const location_type
& l
]))[)
293 : value(v
)]b4_locations_if([
298 template <typename Exact
>
300 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
302 return static_cast<const Exact
&>(*this);
305 template <typename Exact
>
307 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
309 return static_cast<Exact
&>(*this);
312 template <typename Exact
>
314 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
316 return self ().type_get_ ();
320 ]b4_parser_class_name
[::symbol_type::symbol_type ()
326 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
328 b4_locations_if([const location_type
& l
]))[)
329 : super_type (]b4_locations_if([l
])[)
334 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
336 [const semantic_type
& v
],
337 b4_locations_if([const location_type
& l
]))[)
338 : super_type (v
]b4_locations_if([, l
])[)
344 ]b4_parser_class_name
[::symbol_type::type_get_ () const
350 [ // Implementation of make_symbol for each symbol type.
351 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
354 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
355 # ------------------------------------------------
356 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
358 m4_define([b4_symbol_variant
],
359 [m4_pushdef([b4_dollar_dollar
],
360 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
363 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
367 m4_popdef([b4_dollar_dollar
])dnl
371 # _b4_char_sizeof_counter
372 # -----------------------
373 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
374 m4_define([_b4_char_sizeof_counter
],
377 # _b4_char_sizeof_dummy
378 # ---------------------
379 # At each call return a new C++ identifier.
380 m4_define([_b4_char_sizeof_dummy
],
381 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
382 dummy
[]_b4_char_sizeof_counter
])
385 # b4_char_sizeof_(SYMBOL-NUM)
386 # ---------------------------
387 # A comment describing this symbol.
388 m4_define([b4_char_sizeof_
],
389 [ // b4_symbol([$1], [tag])
392 # b4_char_sizeof(SYMBOL-NUMS)
393 # --------------------------
394 # To be mapped on the list of type names to produce:
396 # char dummy1[sizeof(type_name_1)];
397 # char dummy2[sizeof(type_name_2)];
399 # for defined type names.
400 m4_define([b4_char_sizeof
],
401 [b4_symbol_if([$
1], [has_type
],
403 m4_map([b4_char_sizeof_
], [$@
])dnl
404 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type
])])@
};
408 # b4_yytranslate_definition
409 # -------------------------
410 # Define yytranslate_. Sometimes we want it in the header file,
411 # sometimes the cc file suffices.
412 m4_define([b4_yytranslate_definition
],
413 [[ // YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.
414 ]b4_parser_class_name
[::token_number_type
415 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
419 const token_number_type
424 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
425 const token_number_type undef_token_
= ]b4_undef_token_number
[;
427 if (static_cast<int>(t
) <= yyeof_
)
429 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
430 return translate_table
[t
];
437 m4_pushdef([b4_copyright_years
],
438 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
440 m4_define([b4_parser_class_name
],
441 [b4_percent_define_get([[parser_class_name]])])
443 # The header is mandatory.
445 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
448 [# Backward compatibility.
449 m4_define([b4_location_constructors
])
450 m4_include(b4_pkgdatadir
/[location
.cc
])])
452 # We do want M4 expansion after # for CPP macros.
455 @
output(b4_spec_defines_file@
)@
456 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
457 dnl FIXME
: This is wrong
, we want computed header guards
.
459 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
461 #ifndef PARSER_HEADER_H
462 # define PARSER_HEADER_H
464 ]b4_percent_code_get([[requires]])[
466 ]b4_assert_if([#include <cassert>])[
472 ]b4_locations_if([ class position
;
476 /// A char[S] buffer to store and retrieve objects.
478 /// Sort of a variant, but does not keep track of the nature
479 /// of the stored data, since that knowledge is available
480 /// via the current state.
484 /// Whether something is contained.
487 /// Empty construction.
489 variant ()]b4_assert_if([
493 /// Instantiate a \a T in here.
494 template <typename T
>
500 return *new (buffer
) T
;
503 /// Instantiate a \a T in here from \a t.
504 template <typename T
>
510 return *new (buffer
) T(t
);
513 /// Construct and fill.
514 template <typename T
>
516 variant (const T
& t
)]b4_assert_if([
522 /// Accessor to a built \a T.
523 template <typename T
>
528 return reinterpret_cast<T
&>(buffer
);
531 /// Const accessor to a built \a T (for %printer).
532 template <typename T
>
537 return reinterpret_cast<const T
&>(buffer
);
540 /// Swap the content with \a other.
541 template <typename T
>
543 swap(variant
<S
>& other
)
545 std::swap(as
<T
>(), other
.as
<T
>());
548 /// Assign the content of \a other to this.
549 /// Destroys \a other.
550 template <typename T
>
552 build(variant
<S
>& other
)
559 /// Destroy the stored \a T.
560 template <typename T
>
564 as
<T
>().~T();]b4_assert_if([
568 /// A buffer large enough to store any of the semantic values.
574 ]b4_locations_if([#include "location.hh"])[
576 /* Enabling traces. */
578 # define YYDEBUG ]b4_debug_flag[
581 /* Enabling verbose error messages. */
582 #ifdef YYERROR_VERBOSE
583 # undef YYERROR_VERBOSE
584 # define YYERROR_VERBOSE 1
586 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
589 /* Enabling the token table. */
590 #ifndef YYTOKEN_TABLE
591 # define YYTOKEN_TABLE ]b4_token_table[
594 ]b4_locations_if([dnl
595 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
596 If N is 0, then set CURRENT to the empty location which ends
597 the previous symbol: RHS[0] (always defined). */
599 #ifndef YYLLOC_DEFAULT
600 # define YYLLOC_DEFAULT(Current, Rhs, N) \
604 (Current).begin = (Rhs)[1].location.begin; \
605 (Current).end = (Rhs)[N].location.end; \
609 (Current).begin = (Current).end = (Rhs)[0].location.end; \
617 class ]b4_parser_class_name
[
622 [ /// An auxiliary type to compute the largest semantic type.
624 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[};
626 /// Symbol semantic values.
627 typedef variant
<sizeof(union_type
)> semantic_type
;],
628 [ /// Symbol semantic values.
630 [ union semantic_type
633 [m4_if(b4_tag_seen_flag
, 0,
634 [[ typedef int semantic_type
;]],
635 [[ typedef YYSTYPE semantic_type
;]])])])[
637 typedef YYSTYPE semantic_type
;
638 #endif]b4_locations_if([
639 /// Symbol locations.
640 typedef b4_percent_define_get([[location_type]]) location_type
;])[
644 ]b4_token_enums(b4_tokens
)[
647 typedef token::yytokentype token_type
;
649 /// Build a parser object.
650 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
651 virtual ~]b4_parser_class_name
[ ();
654 /// \returns 0 iff parsing succeeded.
655 virtual int parse ();
658 /// The current debugging stream.
659 std::ostream
& debug_stream () const;
660 /// Set the current debugging stream.
661 void set_debug_stream (std::ostream
&);
663 /// Type for debugging levels.
664 typedef int debug_level_type
;
665 /// The current debugging level.
666 debug_level_type
debug_level () const;
667 /// Set the current debugging level.
668 void set_debug_level (debug_level_type l
);
672 /// Report a syntax error.]b4_locations_if([
673 /// \param loc where the syntax error is found.])[
674 /// \param msg a description of the syntax error.
675 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
677 /// Generate an error message.
678 /// \param state the state where the error occurred.
679 /// \param tok the lookahead token.
680 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
683 typedef int state_type
;
685 /// Internal symbol numbers.
686 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
688 /// For a state, the index in \a yytable_ of its portion.
689 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
690 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
692 /// For a state, default rule to reduce.
693 /// Unless\a yytable_ specifies something else to do.
694 /// Zero means the default is an error.
695 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
697 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
698 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
700 /// What to do in a state.
701 /// \a yytable_[yypact_[s]]: what to do in state \a s.
702 /// - if positive, shift that token.
703 /// - if negative, reduce the rule which number is the opposite.
704 /// - if zero, do what YYDEFACT says.
705 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
706 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
708 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
710 /// For a state, its accessing symbol.
711 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
713 /// For a rule, its LHS.
714 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
715 /// For a rule, its RHS length.
716 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
718 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
719 /// For a symbol, its name in clear.
720 static const char* const yytname_
[];
721 #endif]b4_error_verbose_if([
723 /// Convert the symbol name \a n to a form suitable for a diagnostic.
724 static std::string
yytnamerr_ (const char *n
);])[
727 /// For each rule, its source line number.
728 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
729 /// For each scanner token number, its symbol number.
730 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
731 /// Report on the debug stream that the rule \a r is going to be reduced.
732 virtual void yy_reduce_print_ (int r
);
733 /// Print the state stack on the debug stream.
734 virtual void yystack_print_ ();
738 std::ostream
* yycdebug_
;
741 /// Convert a scanner token number \a t to a symbol number.
742 static token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
744 /// A complete symbol, with its type.
745 template <typename Exact
>
746 struct symbol_base_type
748 /// Default constructor.
749 inline symbol_base_type ();
751 /// Constructor.]b4_locations_if([
752 inline symbol_base_type (const location_type
& l
)])[;
753 inline symbol_base_type (]b4_args(
754 [const semantic_type
& v
],
755 b4_locations_if([const location_type
& l
]))[);
757 /// Return this with its exact type.
758 const Exact
& self () const;
761 /// Return the type of this symbol.
762 int type_get () const;
764 /// The semantic value.
765 semantic_type value
;]b4_locations_if([
768 location_type location
;])[
772 /// \brief Display a symbol type, value and location.
773 /// \param yyo The output stream.
774 /// \param yysym The symbol.
775 template <typename Exact
>
776 void yy_print_ (std::ostream
& yyo
,
777 const symbol_base_type
<Exact
>& yysym
) const;
780 /// \brief Reclaim the memory associated to a symbol.
781 /// \param yymsg Why this token is reclaimed.
782 /// If null, print nothing.
783 /// \param s The symbol.
784 template <typename Exact
>
785 inline void yy_destroy_ (const char* yymsg
,
786 symbol_base_type
<Exact
>& yysym
) const;
789 /// Element of the stack: a state and its attributes.
790 struct symbol_type
: symbol_base_type
<symbol_type
>
792 /// The parent class.
793 typedef symbol_base_type
<symbol_type
> super_type
;
795 /// Default constructor.
796 inline symbol_type ();
799 inline symbol_type (]b4_args([int t
],
800 [const semantic_type
& v
],
801 b4_locations_if([const location_type
& l
]))[);
803 inline symbol_type (]b4_args([int t
],
804 b4_locations_if([const location_type
& l
]))[);
809 /// Return the type corresponding to this state.
810 inline int type_get_ () const;
813 ]b4_symbol_constructor_declarations
[
816 /// Element of the stack: a state and its attributes.
817 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
819 /// The parent class.
820 typedef symbol_base_type
<stack_symbol_type
> super_type
;
822 /// Default constructor.
823 inline stack_symbol_type ();
826 inline stack_symbol_type (]b4_args([state_type s
],
827 [const semantic_type
& v
],
828 b4_locations_if([const location_type
& l
]))[);
833 /// Return the type corresponding to this state.
834 inline int type_get_ () const;
838 typedef stack
<stack_symbol_type
> stack_type
;
843 /// Push a new state on the stack.
844 /// \param m a debug message to display
845 /// if null, no trace is output.
846 /// \param s the symbol
847 /// \warning the contents of \a s.value is stolen.
848 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
850 /// Push a new look ahead token on the state on the stack.
851 /// \param m a debug message to display
852 /// if null, no trace is output.
853 /// \param s the state
854 /// \param sym the symbol (for its value and location).
855 /// \warning the contents of \a s.value is stolen.
856 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
858 /// Pop \a n symbols the three stacks.
859 inline void yypop_ (unsigned int n
= 1);
865 yylast_
= ]b4_last
[, //< Last index in yytable_.
866 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
868 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
871 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
874 ]b4_parse_param_vars
[
876 ]b4_symbol_constructor_specializations
[
879 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
880 [b4_token_defines(b4_tokens
)
883 /* Redirection for backward compatibility. */
884 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
887 b4_percent_code_get([[provides]])[]dnl
889 [#endif /* ! defined PARSER_HEADER_H */]
890 @
output(b4_parser_file_name@
)@
891 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
892 b4_percent_code_get([[top]])[]dnl
893 m4_if(b4_prefix
, [yy
], [],
895 // Take the name prefix into account.
896 #define yylex b4_prefix[]lex])[
898 /* First part of user declarations. */
899 ]b4_user_pre_prologue
[
901 #include "@basename(]b4_spec_defines_file[@)"
903 /* User implementation prologue. */
904 ]b4_user_post_prologue
905 b4_percent_code_get
[]dnl
910 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
911 # define YY_(msgid) dgettext ("bison-runtime", msgid)
915 # define YY_(msgid) msgid
919 /* Suppress unused-variable warnings by "using" E. */
920 #define YYUSE(e) ((void) (e))
922 /* Enable debugging if requested. */
925 /* A pseudo ostream that takes yydebug_ into account. */
926 # define YYCDEBUG if (yydebug_) (*yycdebug_)
928 # define YY_SYMBOL_PRINT(Title, Symbol) \
932 *yycdebug_ << Title << ' '; \
933 yy_print_ (*yycdebug_, Symbol); \
934 *yycdebug_ << std::endl; \
938 # define YY_REDUCE_PRINT(Rule) \
941 yy_reduce_print_ (Rule); \
944 # define YY_STACK_PRINT() \
952 # define YYCDEBUG if (false) std::cerr
953 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
954 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
955 # define YY_STACK_PRINT() static_cast<void>(0)
957 #endif /* !YYDEBUG */
959 #define yyerrok (yyerrstatus_ = 0)
960 #define yyclearin (yyempty = true)
962 #define YYACCEPT goto yyacceptlab
963 #define YYABORT goto yyabortlab
964 #define YYERROR goto yyerrorlab
965 #define YYRECOVERING() (!!yyerrstatus_)
967 ]b4_namespace_open
[]b4_error_verbose_if([[
969 /* Return YYSTR after stripping away unnecessary quotes and
970 backslashes, so that it's suitable for yyerror. The heuristic is
971 that double-quoting is unnecessary unless the string contains an
972 apostrophe, a comma, or backslash (other than backslash-backslash).
973 YYSTR is taken from yytname. */
975 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
979 std::string yyr
= "";
980 char const *yyp
= yystr
;
987 goto do_not_strip_quotes
;
991 goto do_not_strip_quotes
;
1000 do_not_strip_quotes
: ;
1007 /// Build a parser object.
1008 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
1011 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
1012 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
1013 #endif]b4_parse_param_cons[
1017 ]b4_parser_class_name::~b4_parser_class_name
[ ()
1026 ]b4_symbol_constructor_definitions
[
1028 // stack_symbol_type.
1029 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
1035 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
1037 [const semantic_type
& v
],
1038 b4_locations_if([const location_type
& l
]))[)
1039 : super_type (v
]b4_locations_if([, l
])[)
1045 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
1047 return yystos_
[state
];
1051 template <typename Exact
>
1053 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
1054 symbol_base_type
<Exact
>& yysym
) const
1056 int yytype
= yysym
.type_get ();
1059 YY_SYMBOL_PRINT (yymsg
, yysym
);
1064 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
1070 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1074 template <typename Exact
>
1076 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1077 const symbol_base_type
<Exact
>& yysym
) const
1079 int yytype
= yysym
.type_get ();
1080 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1081 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1082 << yysym
.location
<< ": "])[;
1085 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1094 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1098 YY_SYMBOL_PRINT (m
, sym
);
1100 [[ yystack_
.push (stack_symbol_type (]b4_args(
1103 b4_locations_if([sym
.location
]))[));
1104 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1105 [build
], [sym
.value
])],
1106 [[ yystack_
.push (stack_symbol_type (]b4_args(
1109 b4_locations_if([sym
.location
]))[));]])[
1113 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1116 YY_SYMBOL_PRINT (m
, s
);
1118 [[ yystack_
.push (stack_symbol_type (]b4_args(
1121 b4_locations_if([s
.location
]))[));
1122 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1123 [build
], [s
.value
])],
1124 [ yystack_
.push (s
);])[
1128 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1135 ]b4_parser_class_name
[::debug_stream () const
1141 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1147 ]b4_parser_class_name
[::debug_level_type
1148 ]b4_parser_class_name
[::debug_level () const
1154 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1161 ]b4_parser_class_name
[::parse ()
1163 /// Whether yyla contains a lookahead.
1164 bool yyempty
= true;
1171 /* Error handling. */
1173 int yyerrstatus_
= 0;
1175 /// The lookahead symbol.
1176 symbol_type yyla
;]b4_locations_if([[
1178 /// The locations where the error started and ended.
1179 stack_symbol_type yyerror_range
[2];]])[
1182 stack_symbol_type yylhs
;
1184 /// The return value of parse().
1187 YYCDEBUG
<< "Starting parse" << std::endl
;
1189 ]m4_ifdef([b4_initial_action
], [
1190 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1191 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1192 /* User initialization code. */
1193 b4_user_initial_action
1194 m4_popdef([b4_dollar_dollar
])dnl
1195 m4_popdef([b4_at_dollar
])])dnl
1197 [ /* Initialize the stack. The initial state will be set in
1198 yynewstate, since the latter expects the semantical and the
1199 location values to have been already stored, initialize these
1200 stacks with a primary value. */
1201 yystack_
= stack_type (0);
1202 yypush_ (0, 0, yyla
);
1204 // A new state was pushed on the stack.
1205 // Invariant: yystate == yystack_[0].state, i.e.,
1206 // yystate was just pushed onto the state stack.
1208 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1211 if (yystate
== yyfinal_
)
1219 /* Try to take a decision without lookahead. */
1220 yyn
= yypact_
[yystate
];
1221 if (yyn
== yypact_ninf_
)
1224 /* Read a lookahead token. */
1227 YYCDEBUG
<< "Reading a token: ";
1229 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1230 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1231 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1232 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1233 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1234 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1237 YY_SYMBOL_PRINT ("Next token is", yyla
);
1239 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1240 to detect an error, take that action. */
1242 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1245 /* Reduce or error. */
1246 yyn
= yytable_
[yyn
];
1249 if (yyn
== 0 || yyn
== yytable_ninf_
)
1255 /* Discard the token being shifted. */
1258 /* Count tokens shifted since error; after three, turn off error
1263 /* Shift the lookahead token. */
1265 yypush_ ("Shifting", yystate
, yyla
);
1268 /*-----------------------------------------------------------.
1269 | yydefault -- do the default action for the current state. |
1270 `-----------------------------------------------------------*/
1272 yyn
= yydefact_
[yystate
];
1277 /*-----------------------------.
1278 | yyreduce -- Do a reduction. |
1279 `-----------------------------*/
1281 yylen
= yyr2_
[yyn
];]b4_variant_if([
1282 /* Variants are always initialized to an empty instance of the
1283 correct type. The default $$=$1 rule is NOT applied when using
1285 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1286 /* If YYLEN is nonzero, implement the default value of the action:
1287 `$$ = $1'. Otherwise, use the top of the stack.
1289 Otherwise, the following line sets YYLHS.VALUE to garbage.
1290 This behavior is undocumented and Bison
1291 users should not rely upon it. */
1293 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1295 yylhs
.value
= yystack_@
{0@
}.value
;])[
1296 ]b4_locations_if([dnl
1298 // Compute the default @@$.
1300 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1301 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1304 // Perform the reduction.
1305 YY_REDUCE_PRINT (yyn
);
1312 // Compute post-reduction state.
1314 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1315 if (0 <= yystate
&& yystate
<= yylast_
1316 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1317 yystate
= yytable_
[yystate
];
1319 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1320 yylhs
.state
= yystate
;
1321 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1323 // Destroy the lhs symbols.
1324 for (int i
= 0; i
< yylen
; ++i
)
1325 // Destroy a variant which value may have be swapped with
1326 // yylhs.value. The value of yylhs.value (hence maybe one of
1327 // these lhs symbols) depends on what does the default
1328 // contruction for this type. In the case of pointers for
1329 // instance, nothing is done, so the value is junk. Therefore
1330 // do not try to report the content in the debug trace, it's
1331 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1332 // traces as with the other Bison skeletons.
1333 yy_destroy_ (0, yystack_
[i
]);]])[
1339 /* Shift the result of the reduction. */
1343 /*------------------------------------.
1344 | yyerrlab -- here on detecting error |
1345 `------------------------------------*/
1347 /* If not already recovering from an error, report this error. */
1351 error (]b4_args(b4_locations_if([yyla
.location
]),
1352 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1356 yyerror_range
[0].location
= yyla
.location
;]])[
1357 if (yyerrstatus_
== 3)
1359 /* If just tried and failed to reuse lookahead token after an
1360 error, discard it. */
1362 /* Return failure if at end of input. */
1363 if (yyla
.type
== yyeof_
)
1367 yy_destroy_ ("Error: discarding", yyla
);
1372 /* Else will try to reuse lookahead token after shifting the error
1377 /*---------------------------------------------------.
1378 | yyerrorlab -- error raised explicitly by YYERROR. |
1379 `---------------------------------------------------*/
1382 /* Pacify compilers like GCC when the user code never invokes
1383 YYERROR and the label yyerrorlab therefore never appears in user
1389 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1390 /* Do not reclaim the symbols of the rule which action triggered
1394 yystate
= yystack_
[0].state
;
1397 /*-------------------------------------------------------------.
1398 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1399 `-------------------------------------------------------------*/
1401 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1403 stack_symbol_type error_token
;
1406 yyn
= yypact_
[yystate
];
1407 if (yyn
!= yypact_ninf_
)
1410 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1412 yyn
= yytable_
[yyn
];
1418 // Pop the current state because it cannot handle the error token.
1419 if (yystack_
.size () == 1)
1422 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1423 yy_destroy_ ("Error: popping", yystack_
[0]);
1425 yystate
= yystack_
[0].state
;
1429 yyerror_range
[1].location
= yyla
.location
;
1430 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1432 /* Shift the error token. */
1433 error_token
.state
= yystate
= yyn
;
1434 yypush_ ("Shifting", error_token
);
1450 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1452 /* Do not reclaim the symbols of the rule which action triggered
1453 this YYABORT or YYACCEPT. */
1455 while (yystack_
.size () != 1)
1457 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1464 // Generate an error message.
1466 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1467 b4_error_verbose_if([int yystate
, int yytoken
],
1470 std::string yyres
;]b4_error_verbose_if([[
1471 int yyn
= yypact_
[yystate
];
1472 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1474 /* Start YYX at -YYN if negative to avoid negative indexes in
1476 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1478 /* Stay within bounds of both yycheck and yytname. */
1479 int yychecklim
= yylast_
- yyn
+ 1;
1480 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1482 // Number of "expected" tokens.
1485 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1486 // Arguments of yyformat.
1487 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1488 yyarg
[yycount
++] = yytname_
[yytoken
];
1489 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1490 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1492 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1498 yyarg
[yycount
++] = yytname_
[yyx
];
1501 char const* yyformat
= 0;
1504 #define YYCASE_(N, S) \
1508 YYCASE_(1, YY_("syntax error, unexpected %s"));
1509 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1510 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1511 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1512 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1517 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1518 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1520 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1528 [ yyres
= YY_("syntax error");
1533 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1535 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1536 ]b4_table_define([pact
], [b4_pact
])[;
1538 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1539 doesn't specify something else to do. Zero means the default is an
1541 ]b4_table_define([defact
], [b4_defact
])[;
1543 /* YYPGOTO[NTERM-NUM]. */
1544 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1546 /* YYDEFGOTO[NTERM-NUM]. */
1547 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1549 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1550 positive, shift that token. If negative, reduce the rule which
1551 number is the opposite. If zero, do what YYDEFACT says. */
1552 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1553 ]b4_table_define([table
], [b4_table
])[;
1556 ]b4_table_define([check
], [b4_check
])[;
1558 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1559 symbol of state STATE-NUM. */
1560 ]b4_table_define([stos
], [b4_stos
])[;
1563 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1565 ]b4_table_define([token_number
], [b4_toknum
])[;
1568 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1569 ]b4_table_define([r1
], [b4_r1
])[;
1571 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1572 ]b4_table_define([r2
], [b4_r2
])[;
1574 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1575 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1576 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1578 const ]b4_parser_class_name
[::yytname_
[] =
1585 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1586 ]b4_table_define([rline
], [b4_rline
])[;
1588 // Print the state stack on the debug stream.
1590 ]b4_parser_class_name
[::yystack_print_ ()
1592 *yycdebug_
<< "Stack now";
1593 for (stack_type::const_iterator
1594 i
= yystack_
.begin (),
1595 i_end
= yystack_
.end ();
1597 *yycdebug_
<< ' ' << i
->state
;
1598 *yycdebug_
<< std::endl
;
1601 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1603 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1605 unsigned int yylno
= yyrline_
[yyrule
];
1606 int yynrhs
= yyr2_
[yyrule
];
1607 /* Print the symbols being reduced, and their result. */
1608 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1609 << " (line " << yylno
<< "):" << std::endl
;
1610 /* The symbols being reduced. */
1611 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1612 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1613 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1617 ]b4_yytranslate_definition
[
1618 ]b4_namespace_close
[
1621 @
output(b4_dir_prefix
[]stack
.hh@
)@
1622 b4_copyright([Stack handling
for Bison parsers in C
++])[
1624 #ifndef BISON_STACK_HH
1625 # define BISON_STACK_HH
1630 template <class T
, class S
= std::deque
<T
> >
1635 // Hide our reversed order.
1636 typedef typename
S::reverse_iterator iterator
;
1637 typedef typename
S::const_reverse_iterator const_iterator
;
1643 stack (unsigned int n
) : seq_ (n
)
1649 operator [] (unsigned int i
)
1656 operator [] (unsigned int i
) const
1665 seq_
.push_front (t
);
1670 pop (unsigned int n
= 1)
1677 typename
S::size_type
1680 return seq_
.size ();
1683 inline const_iterator
begin () const { return seq_
.rbegin (); }
1684 inline const_iterator
end () const { return seq_
.rend (); }
1687 /// The wrapped container.
1691 /// Present a slice of the top of a stack.
1692 template <class T
, class S
= stack
<T
> >
1697 slice (const S
& stack
,
1698 unsigned int range
) : stack_ (stack
),
1705 operator [] (unsigned int i
) const
1707 return stack_
[range_
- i
];
1713 unsigned int range_
;
1715 ]b4_namespace_close
[
1717 #endif // not BISON_STACK_HH[]dnl
1720 m4_popdef([b4_copyright_years
])dnl