1 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 # Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 m4_include(b4_pkgdatadir
/[c
++.m4
])
22 # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
23 # --------------------------------------------------------------
24 # Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
25 m4_define([b4_integral_parser_table_declare
],
26 [m4_ifval([$
3], [b4_c_comment([$
3], [ ])
28 static const b4_int_type_for([$
2]) yy$
1_
[[]];dnl
31 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
32 # ---------------------------------------------
33 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
34 m4_define([b4_integral_parser_table_define
],
35 [ const b4_int_type_for([$
2])
36 b4_parser_class_name::yy$
1_
[[]] =
43 # b4_symbol_value_template(VAL, [TYPE])
44 # -------------------------------------
45 # Same as b4_symbol_value, but used in a template method.
46 m4_copy([b4_symbol_value
], [b4_symbol_value_template
])
48 # How the semantic value is extracted when using variants.
50 # b4_symbol_value(VAL, [TYPE])
51 # ----------------------------
52 m4_define([b4_symbol_value
],
57 # b4_symbol_value_template(VAL, [TYPE])
58 # -------------------------------------
59 # Same as b4_symbol_value, but used in a template method.
60 m4_define([b4_symbol_value_template
],
62 [$
1.template as
< $
2 >()],
67 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
68 # ----------------------------------------------------------------
69 m4_define([b4_lex_symbol_if
],
70 [b4_percent_define_ifdef([[lex_symbol]], [$
1], [$
2])])
73 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
74 # ------------------------------------------------
75 m4_define([b4_assert_if
],
76 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
79 # b4_lhs_value([TYPE])
80 # --------------------
81 # Expansion of $<TYPE>$.
82 m4_define([b4_lhs_value
],
83 [b4_symbol_value([yylhs
.value
], [$
1])])
89 m4_define([b4_lhs_location
],
93 # b4_rhs_data(RULE-LENGTH, NUM)
94 # -----------------------------
95 # Return the data corresponding to the symbol #NUM, where the current
96 # rule has RULE-LENGTH symbols on RHS.
97 m4_define([b4_rhs_data
],
98 [yystack_@
{b4_subtract($@
)@
}])
101 # b4_rhs_state(RULE-LENGTH, NUM)
102 # -----------------------------
103 # The state corresponding to the symbol #NUM, where the current
104 # rule has RULE-LENGTH symbols on RHS.
105 m4_define([b4_rhs_state
],
106 [b4_rhs_data([$
1], [$
2]).state
])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
117 # b4_rhs_location(RULE-LENGTH, NUM)
118 # ---------------------------------
119 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
121 m4_define([b4_rhs_location
],
122 [b4_rhs_data([$
1], [$
2]).location
])
125 # b4_symbol_(NUM, FIELD)
126 # ----------------------
127 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
129 m4_define([b4_symbol_
],
130 [m4_indir([b4_symbol($
1, $
2)])])
133 # b4_symbol(NUM, FIELD)
134 # ---------------------
135 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
136 # undefined. If FIELD = id, prepend the prefix.
137 m4_define([b4_symbol
],
139 [id
], [m4_do([b4_percent_define_get([token
.prefix
])],
140 [b4_symbol_([$
1], [id
])])],
144 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
145 # -------------------------------------------
146 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
147 # Otherwise an error.
148 m4_define([b4_symbol_if
],
149 [m4_case(b4_symbol([$
1], [$
2]),
152 [m4_fatal([$
0: field $
2 of $
1 is
not a Boolean
:] b4_symbol([$
1], [$
2]))])])
155 # b4_symbol_action(SYMBOL-NUM, KIND)
156 # ----------------------------------
157 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
158 # Same as in C, but using references instead of pointers.
159 m4_define([b4_symbol_action
],
160 [b4_symbol_if([$
1], [has_$
2],
161 [m4_pushdef([b4_dollar_dollar
],
162 [b4_symbol_value_template([yysym
.value
],
163 b4_symbol_if([$
1], [has_type
],
164 [b4_symbol([$
1], [type
])]))])dnl
165 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
166 case $
1: // b4_symbol([$1], [tag])
167 b4_syncline([b4_symbol([$
1], [$
2_line
])], ["b4_symbol([$1], [$2_file])"])
168 b4_symbol([$
1], [$
2])
169 b4_syncline([@oline@
], [@ofile@
])
172 m4_popdef([b4_at_dollar
])dnl
173 m4_popdef([b4_dollar_dollar
])dnl
177 # b4_symbol_destructor(SYMBOL-NUM)
178 # b4_symbol_printer(SYMBOL-NUM)
179 # --------------------------------
180 m4_define([b4_symbol_destructor
], [b4_symbol_action([$
1], [destructor
])])
181 m4_define([b4_symbol_printer
], [b4_symbol_action([$
1], [printer
])])
184 # b4_symbol_case_(SYMBOL-NUM)
185 # ---------------------------
186 # Issue a "case NUM" for SYMBOL-NUM.
187 m4_define([b4_symbol_case_
],
188 [ case b4_symbol([$
1], [number
]): // b4_symbol([$1], [tag])
192 # b4_type_action_(NUMS)
193 # ---------------------
194 # Run actions for the symbol NUMS that all have the same type-name.
195 # Skip NUMS that have no type-name.
196 m4_define([b4_type_action_
],
197 [b4_symbol_if([$
1], [has_type
],
198 [m4_map([b4_symbol_case_
], [$@
])[]dnl
199 b4_dollar_dollar([b4_symbol([$
1], [number
])],
200 [b4_symbol([$
1], [tag
])],
201 [b4_symbol([$
1], [type
])]);
207 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
208 # -------------------------------------------------
209 # Declare the overloaded version of make_symbol for the (common) type of
210 # these SYMBOL-NUMBERS. Use at class-level.
211 m4_define([b4_symbol_constructor_declaration_
],
212 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
215 make_
[]b4_symbol_([$
1], [id
]) (dnl
216 b4_args(b4_symbol_if([$
1], [has_type
],
217 [const b4_symbol([$
1], [type
])& v
]),
218 b4_locations_if([const location_type
& l
])));
223 # b4_symbol_constructor_declarations
224 # ----------------------------------
225 # Declare symbol constructors for all the value types.
226 # Use at class-level.
227 m4_define([b4_symbol_constructor_declarations
],
229 // Symbol constructors declarations.
230 m4_map([b4_symbol_constructor_declaration_
], m4_defn([b4_symbol_numbers
]))])])
234 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
235 # ------------------------------------------------
236 # Define symbol constructor for this SYMBOL-NUMBER.
237 m4_define([b4_symbol_constructor_definition_
],
238 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
239 [ b4_parser_class_name::symbol_type
240 b4_parser_class_name::make_
[]b4_symbol_([$
1], [id
]) (dnl
241 b4_args(b4_symbol_if([$
1], [has_type
],
242 [const b4_symbol([$
1], [type
])& v
]),
243 b4_locations_if([const location_type
& l
])))
245 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$
1], [id
]))],
246 b4_symbol_if([$
1], [has_type
], [v
]),
247 b4_locations_if([l
])));
253 # b4_symbol_constructor_definitions
254 # ----------------------------------
255 # Define the overloaded versions of make_symbol for all the value types.
256 m4_define([b4_symbol_constructor_definitions
],
257 [[ // symbol_base_type.
258 template <typename Exact
>
259 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
260 : value()]b4_locations_if([
265 template <typename Exact
>
266 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
272 template <typename Exact
>
273 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
274 [const semantic_type
& v
],
275 b4_locations_if([const location_type
& l
]))[)
276 : value(v
)]b4_locations_if([
281 template <typename Exact
>
283 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
285 return static_cast<const Exact
&>(*this);
288 template <typename Exact
>
290 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
292 return static_cast<Exact
&>(*this);
295 template <typename Exact
>
297 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
299 return self ().type_get_ ();
303 ]b4_parser_class_name
[::symbol_type::symbol_type ()
309 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
311 b4_locations_if([const location_type
& l
]))[)
312 : super_type (]b4_locations_if([l
])[)
317 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
319 [const semantic_type
& v
],
320 b4_locations_if([const location_type
& l
]))[)
321 : super_type (v
]b4_locations_if([, l
])[)
327 ]b4_parser_class_name
[::symbol_type::type_get_ () const
332 ]b4_parser_class_name
[::token_type
333 ]b4_parser_class_name
[::symbol_type::token () const
335 // YYTOKNUM[NUM] -- (External) token number corresponding to the
336 // (internal) symbol number NUM (which must be that of a token). */
338 const ]b4_int_type_for([b4_toknum
])[
343 return static_cast<token_type
> (yytoken_number_
[type
]);
348 [ // Implementation of make_symbol for each symbol type.
349 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
352 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
353 # ------------------------------------------------
354 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
356 m4_define([b4_symbol_variant
],
357 [m4_pushdef([b4_dollar_dollar
],
358 [$
2.$
3< $
][3 >(m4_shift3($@
))])dnl
361 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
365 m4_popdef([b4_dollar_dollar
])dnl
369 # _b4_char_sizeof_counter
370 # -----------------------
371 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
372 m4_define([_b4_char_sizeof_counter
],
375 # _b4_char_sizeof_dummy
376 # ---------------------
377 # At each call return a new C++ identifier.
378 m4_define([_b4_char_sizeof_dummy
],
379 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
380 dummy
[]_b4_char_sizeof_counter
])
383 # b4_char_sizeof_(SYMBOL-NUM)
384 # ---------------------------
385 # A comment describing this symbol.
386 m4_define([b4_char_sizeof_
],
387 [ // b4_symbol([$1], [tag])
390 # b4_char_sizeof(SYMBOL-NUMS)
391 # --------------------------
392 # To be mapped on the list of type names to produce:
394 # char dummy1[sizeof(type_name_1)];
395 # char dummy2[sizeof(type_name_2)];
397 # for defined type names.
398 m4_define([b4_char_sizeof
],
399 [b4_symbol_if([$
1], [has_type
],
401 m4_map([b4_char_sizeof_
], [$@
])dnl
402 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type
])])@
};
406 # b4_yytranslate_definition
407 # -------------------------
408 # Define yytranslate_. Sometimes we want it in the header file,
409 # sometimes the cc file suffices.
410 m4_define([b4_yytranslate_definition
],
411 [[ // Symbol number corresponding to token number t.
412 ]b4_parser_class_name
[::token_number_type
413 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
417 const token_number_type
422 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
423 const token_number_type undef_token_
= ]b4_undef_token_number
[;
425 if (static_cast<int>(t
) <= yyeof_
)
427 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
428 return translate_table
[t
];
435 m4_pushdef([b4_copyright_years
],
436 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
438 m4_define([b4_parser_class_name
],
439 [b4_percent_define_get([[parser_class_name]])])
441 # The header is mandatory.
443 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
446 [# Backward compatibility.
447 m4_define([b4_location_constructors
])
448 m4_include(b4_pkgdatadir
/[location
.cc
])])
450 # We do want M4 expansion after # for CPP macros.
453 @
output(b4_spec_defines_file@
)@
454 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
455 dnl FIXME
: This is wrong
, we want computed header guards
.
457 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
459 #ifndef PARSER_HEADER_H
460 # define PARSER_HEADER_H
462 ]b4_percent_code_get([[requires]])[
464 ]b4_assert_if([#include <cassert>])[
470 ]b4_locations_if([ class position
;
474 /// A char[S] buffer to store and retrieve objects.
476 /// Sort of a variant, but does not keep track of the nature
477 /// of the stored data, since that knowledge is available
478 /// via the current state.
482 /// Whether something is contained.
485 /// Empty construction.
487 variant ()]b4_assert_if([
491 /// Instantiate a \a T in here.
492 template <typename T
>
498 return *new (buffer
) T
;
501 /// Instantiate a \a T in here from \a t.
502 template <typename T
>
508 return *new (buffer
) T(t
);
511 /// Construct and fill.
512 template <typename T
>
514 variant (const T
& t
)]b4_assert_if([
520 /// Accessor to a built \a T.
521 template <typename T
>
526 return reinterpret_cast<T
&>(buffer
);
529 /// Const accessor to a built \a T (for %printer).
530 template <typename T
>
535 return reinterpret_cast<const T
&>(buffer
);
538 /// Swap the content with \a other.
539 template <typename T
>
541 swap(variant
<S
>& other
)
543 std::swap(as
<T
>(), other
.as
<T
>());
546 /// Assign the content of \a other to this.
547 /// Destroys \a other.
548 template <typename T
>
550 build(variant
<S
>& other
)
557 /// Destroy the stored \a T.
558 template <typename T
>
562 as
<T
>().~T();]b4_assert_if([
566 /// A buffer large enough to store any of the semantic values.
572 ]b4_locations_if([#include "location.hh"])[
574 /* Enabling traces. */
576 # define YYDEBUG ]b4_debug_flag[
579 /* Enabling verbose error messages. */
580 #ifdef YYERROR_VERBOSE
581 # undef YYERROR_VERBOSE
582 # define YYERROR_VERBOSE 1
584 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
587 /* Enabling the token table. */
588 #ifndef YYTOKEN_TABLE
589 # define YYTOKEN_TABLE ]b4_token_table[
592 ]b4_locations_if([dnl
593 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
594 If N is 0, then set CURRENT to the empty location which ends
595 the previous symbol: RHS[0] (always defined). */
597 #ifndef YYLLOC_DEFAULT
598 # define YYLLOC_DEFAULT(Current, Rhs, N) \
602 (Current).begin = (Rhs)[1].location.begin; \
603 (Current).end = (Rhs)[N].location.end; \
607 (Current).begin = (Current).end = (Rhs)[0].location.end; \
615 class ]b4_parser_class_name
[
620 [ /// An auxiliary type to compute the largest semantic type.
622 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[};
624 /// Symbol semantic values.
625 typedef variant
<sizeof(union_type
)> semantic_type
;],
626 [ /// Symbol semantic values.
628 [ union semantic_type
631 [m4_if(b4_tag_seen_flag
, 0,
632 [[ typedef int semantic_type
;]],
633 [[ typedef YYSTYPE semantic_type
;]])])])[
635 typedef YYSTYPE semantic_type
;
636 #endif]b4_locations_if([
637 /// Symbol locations.
638 typedef b4_percent_define_get([[location_type]]) location_type
;])[
642 ]b4_token_enums(b4_tokens
)[
645 typedef token::yytokentype token_type
;
647 /// Build a parser object.
648 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
649 virtual ~]b4_parser_class_name
[ ();
652 /// \returns 0 iff parsing succeeded.
653 virtual int parse ();
656 /// The current debugging stream.
657 std::ostream
& debug_stream () const;
658 /// Set the current debugging stream.
659 void set_debug_stream (std::ostream
&);
661 /// Type for debugging levels.
662 typedef int debug_level_type
;
663 /// The current debugging level.
664 debug_level_type
debug_level () const;
665 /// Set the current debugging level.
666 void set_debug_level (debug_level_type l
);
670 /// Report a syntax error.]b4_locations_if([
671 /// \param loc where the syntax error is found.])[
672 /// \param msg a description of the syntax error.
673 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
675 /// Generate an error message.
676 /// \param state the state where the error occurred.
677 /// \param tok the lookahead token.
678 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
681 typedef int state_type
;
683 /// Internal symbol numbers.
684 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
685 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
686 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
689 ]b4_parser_tables_declare
[
691 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
692 /// For a symbol, its name in clear.
693 static const char* const yytname_
[];
694 #endif]b4_error_verbose_if([
696 /// Convert the symbol name \a n to a form suitable for a diagnostic.
697 static std::string
yytnamerr_ (const char *n
);])[
700 ]b4_integral_parser_table_declare([rline
], [b4_rline
],
701 [YYRLINE
[YYN
] -- Source line where rule number YYN was defined
.])[
702 /// Report on the debug stream that the rule \a r is going to be reduced.
703 virtual void yy_reduce_print_ (int r
);
704 /// Print the state stack on the debug stream.
705 virtual void yystack_print_ ();
709 std::ostream
* yycdebug_
;
712 /// Convert a scanner token number \a t to a symbol number.
713 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
715 /// A complete symbol, with its type.
716 template <typename Exact
>
717 struct symbol_base_type
719 /// Default constructor.
720 inline symbol_base_type ();
722 /// Constructor.]b4_locations_if([
723 inline symbol_base_type (const location_type
& l
)])[;
724 inline symbol_base_type (]b4_args(
725 [const semantic_type
& v
],
726 b4_locations_if([const location_type
& l
]))[);
728 /// Return this with its exact type.
729 const Exact
& self () const;
732 /// Return the type of this symbol.
733 int type_get () const;
735 /// The semantic value.
736 semantic_type value
;]b4_locations_if([
739 location_type location
;])[
743 /// \brief Display a symbol type, value and location.
744 /// \param yyo The output stream.
745 /// \param yysym The symbol.
746 template <typename Exact
>
747 void yy_print_ (std::ostream
& yyo
,
748 const symbol_base_type
<Exact
>& yysym
) const;
751 /// \brief Reclaim the memory associated to a symbol.
752 /// \param yymsg Why this token is reclaimed.
753 /// If null, print nothing.
754 /// \param s The symbol.
755 template <typename Exact
>
756 inline void yy_destroy_ (const char* yymsg
,
757 symbol_base_type
<Exact
>& yysym
) const;
760 /// Element of the stack: a state and its attributes.
761 struct symbol_type
: symbol_base_type
<symbol_type
>
763 /// The parent class.
764 typedef symbol_base_type
<symbol_type
> super_type
;
766 /// Default constructor.
767 inline symbol_type ();
770 inline symbol_type (]b4_args([int t
],
771 [const semantic_type
& v
],
772 b4_locations_if([const location_type
& l
]))[);
774 inline symbol_type (]b4_args([int t
],
775 b4_locations_if([const location_type
& l
]))[);
780 /// Return the type corresponding to this state.
781 inline int type_get_ () const;
784 inline token_type
token () const;
787 ]b4_symbol_constructor_declarations
[
790 /// Element of the stack: a state and its attributes.
791 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
793 /// The parent class.
794 typedef symbol_base_type
<stack_symbol_type
> super_type
;
796 /// Default constructor.
797 inline stack_symbol_type ();
800 inline stack_symbol_type (]b4_args([state_type s
],
801 [const semantic_type
& v
],
802 b4_locations_if([const location_type
& l
]))[);
807 /// Return the type corresponding to this state.
808 inline int type_get_ () const;
812 typedef stack
<stack_symbol_type
> stack_type
;
817 /// Push a new state on the stack.
818 /// \param m a debug message to display
819 /// if null, no trace is output.
820 /// \param s the symbol
821 /// \warning the contents of \a s.value is stolen.
822 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
824 /// Push a new look ahead token on the state on the stack.
825 /// \param m a debug message to display
826 /// if null, no trace is output.
827 /// \param s the state
828 /// \param sym the symbol (for its value and location).
829 /// \warning the contents of \a s.value is stolen.
830 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
832 /// Pop \a n symbols the three stacks.
833 inline void yypop_ (unsigned int n
= 1);
839 yylast_
= ]b4_last
[, //< Last index in yytable_.
840 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
842 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
845 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
848 ]b4_parse_param_vars
[
851 ]b4_lex_symbol_if([b4_yytranslate_definition
])[
852 ]b4_lex_symbol_if([b4_symbol_constructor_definitions
])[
855 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
856 [b4_token_defines(b4_tokens
)
859 /* Redirection for backward compatibility. */
860 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
863 b4_percent_code_get([[provides]])[]dnl
865 [#endif /* ! defined PARSER_HEADER_H */]
866 @
output(b4_parser_file_name@
)@
867 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
868 b4_percent_code_get([[top]])[]dnl
869 m4_if(b4_prefix
, [yy
], [],
871 // Take the name prefix into account.
872 #define yylex b4_prefix[]lex])[
874 /* First part of user declarations. */
875 ]b4_user_pre_prologue
[
877 #include "@basename(]b4_spec_defines_file[@)"
879 /* User implementation prologue. */
880 ]b4_user_post_prologue
881 b4_percent_code_get
[]dnl
886 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
887 # define YY_(msgid) dgettext ("bison-runtime", msgid)
891 # define YY_(msgid) msgid
895 /* Suppress unused-variable warnings by "using" E. */
896 #define YYUSE(e) ((void) (e))
898 /* Enable debugging if requested. */
901 /* A pseudo ostream that takes yydebug_ into account. */
902 # define YYCDEBUG if (yydebug_) (*yycdebug_)
904 # define YY_SYMBOL_PRINT(Title, Symbol) \
908 *yycdebug_ << Title << ' '; \
909 yy_print_ (*yycdebug_, Symbol); \
910 *yycdebug_ << std::endl; \
914 # define YY_REDUCE_PRINT(Rule) \
917 yy_reduce_print_ (Rule); \
920 # define YY_STACK_PRINT() \
928 # define YYCDEBUG if (false) std::cerr
929 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
930 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
931 # define YY_STACK_PRINT() static_cast<void>(0)
933 #endif /* !YYDEBUG */
935 #define yyerrok (yyerrstatus_ = 0)
936 #define yyclearin (yyempty = true)
938 #define YYACCEPT goto yyacceptlab
939 #define YYABORT goto yyabortlab
940 #define YYERROR goto yyerrorlab
941 #define YYRECOVERING() (!!yyerrstatus_)
943 ]b4_namespace_open
[]b4_error_verbose_if([[
945 /* Return YYSTR after stripping away unnecessary quotes and
946 backslashes, so that it's suitable for yyerror. The heuristic is
947 that double-quoting is unnecessary unless the string contains an
948 apostrophe, a comma, or backslash (other than backslash-backslash).
949 YYSTR is taken from yytname. */
951 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
955 std::string yyr
= "";
956 char const *yyp
= yystr
;
963 goto do_not_strip_quotes
;
967 goto do_not_strip_quotes
;
976 do_not_strip_quotes
: ;
983 /// Build a parser object.
984 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
987 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
988 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
989 #endif]b4_parse_param_cons[
993 ]b4_parser_class_name::~b4_parser_class_name
[ ()
1002 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions
])[
1004 // stack_symbol_type.
1005 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
1011 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
1013 [const semantic_type
& v
],
1014 b4_locations_if([const location_type
& l
]))[)
1015 : super_type (v
]b4_locations_if([, l
])[)
1021 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
1023 return yystos_
[state
];
1027 template <typename Exact
>
1029 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
1030 symbol_base_type
<Exact
>& yysym
) const
1032 int yytype
= yysym
.type_get ();
1035 YY_SYMBOL_PRINT (yymsg
, yysym
);
1040 ]m4_map([b4_symbol_destructor
], m4_defn([b4_symbol_numbers
]))dnl
1046 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1050 template <typename Exact
>
1052 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1053 const symbol_base_type
<Exact
>& yysym
) const
1055 int yytype
= yysym
.type_get ();
1056 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1057 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1058 << yysym
.location
<< ": "])[;
1061 ]m4_map([b4_symbol_printer
], m4_defn([b4_symbol_numbers
]))dnl
1070 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1074 YY_SYMBOL_PRINT (m
, sym
);
1076 [[ yystack_
.push (stack_symbol_type (]b4_args(
1079 b4_locations_if([sym
.location
]))[));
1080 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1081 [build
], [sym
.value
])],
1082 [[ yystack_
.push (stack_symbol_type (]b4_args(
1085 b4_locations_if([sym
.location
]))[));]])[
1089 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1092 YY_SYMBOL_PRINT (m
, s
);
1094 [[ yystack_
.push (stack_symbol_type (]b4_args(
1097 b4_locations_if([s
.location
]))[));
1098 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1099 [build
], [s
.value
])],
1100 [ yystack_
.push (s
);])[
1104 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1111 ]b4_parser_class_name
[::debug_stream () const
1117 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1123 ]b4_parser_class_name
[::debug_level_type
1124 ]b4_parser_class_name
[::debug_level () const
1130 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1137 ]b4_parser_class_name
[::parse ()
1139 /// Whether yyla contains a lookahead.
1140 bool yyempty
= true;
1147 /* Error handling. */
1149 int yyerrstatus_
= 0;
1151 /// The lookahead symbol.
1152 symbol_type yyla
;]b4_locations_if([[
1154 /// The locations where the error started and ended.
1155 stack_symbol_type yyerror_range
[2];]])[
1158 stack_symbol_type yylhs
;
1160 /// The return value of parse().
1163 YYCDEBUG
<< "Starting parse" << std::endl
;
1165 ]m4_ifdef([b4_initial_action
], [
1166 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1167 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1168 /* User initialization code. */
1169 b4_user_initial_action
1170 m4_popdef([b4_dollar_dollar
])dnl
1171 m4_popdef([b4_at_dollar
])])dnl
1173 [ /* Initialize the stack. The initial state will be set in
1174 yynewstate, since the latter expects the semantical and the
1175 location values to have been already stored, initialize these
1176 stacks with a primary value. */
1177 yystack_
= stack_type (0);
1178 yypush_ (0, 0, yyla
);
1180 // A new state was pushed on the stack.
1181 // Invariant: yystate == yystack_[0].state, i.e.,
1182 // yystate was just pushed onto the state stack.
1184 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1187 if (yystate
== yyfinal_
)
1195 /* Try to take a decision without lookahead. */
1196 yyn
= yypact_
[yystate
];
1197 if (yyn
== yypact_ninf_
)
1200 /* Read a lookahead token. */
1203 YYCDEBUG
<< "Reading a token: ";
1205 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1206 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1207 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1208 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1209 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1210 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1213 YY_SYMBOL_PRINT ("Next token is", yyla
);
1215 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1216 to detect an error, take that action. */
1218 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1221 /* Reduce or error. */
1222 yyn
= yytable_
[yyn
];
1225 if (yyn
== 0 || yyn
== yytable_ninf_
)
1231 /* Discard the token being shifted. */
1234 /* Count tokens shifted since error; after three, turn off error
1239 /* Shift the lookahead token. */
1241 yypush_ ("Shifting", yystate
, yyla
);
1244 /*-----------------------------------------------------------.
1245 | yydefault -- do the default action for the current state. |
1246 `-----------------------------------------------------------*/
1248 yyn
= yydefact_
[yystate
];
1253 /*-----------------------------.
1254 | yyreduce -- Do a reduction. |
1255 `-----------------------------*/
1257 yylen
= yyr2_
[yyn
];]b4_variant_if([
1258 /* Variants are always initialized to an empty instance of the
1259 correct type. The default $$=$1 rule is NOT applied when using
1261 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1262 /* If YYLEN is nonzero, implement the default value of the action:
1263 `$$ = $1'. Otherwise, use the top of the stack.
1265 Otherwise, the following line sets YYLHS.VALUE to garbage.
1266 This behavior is undocumented and Bison
1267 users should not rely upon it. */
1269 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1271 yylhs
.value
= yystack_@
{0@
}.value
;])[
1272 ]b4_locations_if([dnl
1274 // Compute the default @@$.
1276 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1277 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1280 // Perform the reduction.
1281 YY_REDUCE_PRINT (yyn
);
1288 // Compute post-reduction state.
1290 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1291 if (0 <= yystate
&& yystate
<= yylast_
1292 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1293 yystate
= yytable_
[yystate
];
1295 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1296 yylhs
.state
= yystate
;
1297 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1299 // Destroy the lhs symbols.
1300 for (int i
= 0; i
< yylen
; ++i
)
1301 // Destroy a variant which value may have be swapped with
1302 // yylhs.value. The value of yylhs.value (hence maybe one of
1303 // these lhs symbols) depends on what does the default
1304 // contruction for this type. In the case of pointers for
1305 // instance, nothing is done, so the value is junk. Therefore
1306 // do not try to report the content in the debug trace, it's
1307 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1308 // traces as with the other Bison skeletons.
1309 yy_destroy_ (0, yystack_
[i
]);]])[
1315 /* Shift the result of the reduction. */
1319 /*------------------------------------.
1320 | yyerrlab -- here on detecting error |
1321 `------------------------------------*/
1323 /* If not already recovering from an error, report this error. */
1327 error (]b4_args(b4_locations_if([yyla
.location
]),
1328 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1332 yyerror_range
[0].location
= yyla
.location
;]])[
1333 if (yyerrstatus_
== 3)
1335 /* If just tried and failed to reuse lookahead token after an
1336 error, discard it. */
1338 /* Return failure if at end of input. */
1339 if (yyla
.type
== yyeof_
)
1343 yy_destroy_ ("Error: discarding", yyla
);
1348 /* Else will try to reuse lookahead token after shifting the error
1353 /*---------------------------------------------------.
1354 | yyerrorlab -- error raised explicitly by YYERROR. |
1355 `---------------------------------------------------*/
1358 /* Pacify compilers like GCC when the user code never invokes
1359 YYERROR and the label yyerrorlab therefore never appears in user
1365 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1366 /* Do not reclaim the symbols of the rule which action triggered
1370 yystate
= yystack_
[0].state
;
1373 /*-------------------------------------------------------------.
1374 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1375 `-------------------------------------------------------------*/
1377 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1379 stack_symbol_type error_token
;
1382 yyn
= yypact_
[yystate
];
1383 if (yyn
!= yypact_ninf_
)
1386 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1388 yyn
= yytable_
[yyn
];
1394 // Pop the current state because it cannot handle the error token.
1395 if (yystack_
.size () == 1)
1398 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1399 yy_destroy_ ("Error: popping", yystack_
[0]);
1401 yystate
= yystack_
[0].state
;
1405 yyerror_range
[1].location
= yyla
.location
;
1406 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1408 /* Shift the error token. */
1409 error_token
.state
= yystate
= yyn
;
1410 yypush_ ("Shifting", error_token
);
1426 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1428 /* Do not reclaim the symbols of the rule which action triggered
1429 this YYABORT or YYACCEPT. */
1431 while (yystack_
.size () != 1)
1433 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1440 // Generate an error message.
1442 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1443 b4_error_verbose_if([int yystate
, int yytoken
],
1446 std::string yyres
;]b4_error_verbose_if([[
1447 int yyn
= yypact_
[yystate
];
1448 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1450 /* Start YYX at -YYN if negative to avoid negative indexes in
1452 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1454 /* Stay within bounds of both yycheck and yytname. */
1455 int yychecklim
= yylast_
- yyn
+ 1;
1456 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1458 // Number of "expected" tokens.
1461 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1462 // Arguments of yyformat.
1463 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1464 yyarg
[yycount
++] = yytname_
[yytoken
];
1465 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1466 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1468 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1474 yyarg
[yycount
++] = yytname_
[yyx
];
1477 char const* yyformat
= 0;
1480 #define YYCASE_(N, S) \
1484 YYCASE_(1, YY_("syntax error, unexpected %s"));
1485 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1486 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1487 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1488 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1493 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1494 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1496 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1504 [ yyres
= YY_("syntax error");
1509 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1511 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1513 ]b4_parser_tables_define
[
1515 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1516 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1517 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1519 const ]b4_parser_class_name
[::yytname_
[] =
1526 ]b4_integral_parser_table_define([rline
], [b4_rline
])[
1528 // Print the state stack on the debug stream.
1530 ]b4_parser_class_name
[::yystack_print_ ()
1532 *yycdebug_
<< "Stack now";
1533 for (stack_type::const_iterator
1534 i
= yystack_
.begin (),
1535 i_end
= yystack_
.end ();
1537 *yycdebug_
<< ' ' << i
->state
;
1538 *yycdebug_
<< std::endl
;
1541 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1543 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1545 unsigned int yylno
= yyrline_
[yyrule
];
1546 int yynrhs
= yyr2_
[yyrule
];
1547 /* Print the symbols being reduced, and their result. */
1548 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1549 << " (line " << yylno
<< "):" << std::endl
;
1550 /* The symbols being reduced. */
1551 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1552 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1553 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1557 ]b4_lex_symbol_if([], [b4_yytranslate_definition
])[
1558 ]b4_namespace_close
[
1561 @
output(b4_dir_prefix
[]stack
.hh@
)@
1562 b4_copyright([Stack handling
for Bison parsers in C
++])[
1564 #ifndef BISON_STACK_HH
1565 # define BISON_STACK_HH
1570 template <class T
, class S
= std::deque
<T
> >
1575 // Hide our reversed order.
1576 typedef typename
S::reverse_iterator iterator
;
1577 typedef typename
S::const_reverse_iterator const_iterator
;
1583 stack (unsigned int n
) : seq_ (n
)
1589 operator [] (unsigned int i
)
1596 operator [] (unsigned int i
) const
1605 seq_
.push_front (t
);
1610 pop (unsigned int n
= 1)
1617 typename
S::size_type
1620 return seq_
.size ();
1623 inline const_iterator
begin () const { return seq_
.rbegin (); }
1624 inline const_iterator
end () const { return seq_
.rend (); }
1627 /// The wrapped container.
1631 /// Present a slice of the top of a stack.
1632 template <class T
, class S
= stack
<T
> >
1637 slice (const S
& stack
,
1638 unsigned int range
) : stack_ (stack
),
1645 operator [] (unsigned int i
) const
1647 return stack_
[range_
- i
];
1653 unsigned int range_
;
1655 ]b4_namespace_close
[
1657 #endif // not BISON_STACK_HH[]dnl
1660 m4_popdef([b4_copyright_years
])dnl