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
])
24 # Join with comma, skipping empty arguments.
25 # b4_args calls itself recursively until it sees the first non-empty
26 # argument, then calls _b4_args which prepends each non-empty argument
32 [$
1[]_$
0(m4_shift($@
))],
33 [$
0(m4_shift($@
))])])])
35 # _b4_args(ARGS1, ...)
36 # --------------------
40 [m4_ifval([$
1], [, $
1])[]$
0(m4_shift($@
))])])
43 # b4_table_define(TABLE-NAME, CONTENT)
44 # ------------------------------------
45 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
46 m4_define([b4_table_define
],
47 [const b4_int_type_for([$
2])
48 b4_parser_class_name::yy$
1_
[[]] =
54 # b4_symbol_value_template(VAL, [TYPE])
55 # -------------------------------------
56 # Same as b4_symbol_value, but used in a template method.
57 m4_copy([b4_symbol_value
], [b4_symbol_value_template
])
59 # How the semantic value is extracted when using variants.
61 # b4_symbol_value(VAL, [TYPE])
62 # ----------------------------
63 m4_define([b4_symbol_value
],
68 # b4_symbol_value_template(VAL, [TYPE])
69 # -------------------------------------
70 # Same as b4_symbol_value, but used in a template method.
71 m4_define([b4_symbol_value_template
],
73 [$
1.template as
< $
2 >()],
78 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
79 # ----------------------------------------------------------------
80 m4_define([b4_lex_symbol_if
],
81 [b4_percent_define_ifdef([[lex_symbol]], [$
1], [$
2])])
84 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
85 # ------------------------------------------------
86 m4_define([b4_assert_if
],
87 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
90 # b4_lhs_value([TYPE])
91 # --------------------
92 # Expansion of $<TYPE>$.
93 m4_define([b4_lhs_value
],
94 [b4_symbol_value([yylhs
.value
], [$
1])])
100 m4_define([b4_lhs_location
],
104 # b4_rhs_data(RULE-LENGTH, NUM)
105 # -----------------------------
106 # Return the data corresponding to the symbol #NUM, where the current
107 # rule has RULE-LENGTH symbols on RHS.
108 m4_define([b4_rhs_data
],
109 [yystack_@
{b4_subtract($@
)@
}])
112 # b4_rhs_state(RULE-LENGTH, NUM)
113 # -----------------------------
114 # The state corresponding to the symbol #NUM, where the current
115 # rule has RULE-LENGTH symbols on RHS.
116 m4_define([b4_rhs_state
],
117 [b4_rhs_data([$
1], [$
2]).state
])
120 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
121 # --------------------------------------
122 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
124 m4_define([b4_rhs_value
],
125 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
128 # b4_rhs_location(RULE-LENGTH, NUM)
129 # ---------------------------------
130 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
132 m4_define([b4_rhs_location
],
133 [b4_rhs_data([$
1], [$
2]).location
])
136 # b4_symbol_(NUM, FIELD)
137 # ----------------------
138 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
140 m4_define([b4_symbol_
],
141 [m4_indir([b4_symbol($
1, $
2)])])
144 # b4_symbol(NUM, FIELD)
145 # ---------------------
146 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
147 # undefined. If FIELD = id, prepend the prefix.
148 m4_define([b4_symbol
],
150 [id
], [m4_do([b4_percent_define_get([token
.prefix
])],
151 [b4_symbol_([$
1], [id
])])],
155 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
156 # -------------------------------------------
157 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
158 # Otherwise an error.
159 m4_define([b4_symbol_if
],
160 [m4_case(b4_symbol([$
1], [$
2]),
163 [m4_fatal([$
0: field $
2 of $
1 is
not a Boolean
:] b4_symbol([$
1], [$
2]))])])
166 # b4_symbol_actions(FILENAME, LINENO,
167 # SYMBOL-TAG, SYMBOL-NUM,
168 # SYMBOL-ACTION, SYMBOL-TYPENAME)
169 # -------------------------------------------------
170 # Same as in C, but using references instead of pointers.
171 m4_define([b4_symbol_actions
],
172 [m4_pushdef([b4_dollar_dollar
],
173 [b4_symbol_value_template([yysym
.value
], [$
6])])dnl
174 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
176 b4_syncline([$
2], [$
1])
178 b4_syncline([@oline@
], [@ofile@
])
180 m4_popdef([b4_at_dollar
])dnl
181 m4_popdef([b4_dollar_dollar
])dnl
185 # b4_symbol_case_(SYMBOL-NUM)
186 # ---------------------------
187 # Issue a "case NUM" for SYMBOL-NUM.
188 m4_define([b4_symbol_case_
],
189 [ case b4_symbol([$
1], [number
]): // b4_symbol([$1], [tag])
193 # b4_type_action_(NUMS)
194 # ---------------------
195 # Run actions for the symbol NUMS that all have the same type-name.
196 # Skip NUMS that have no type-name.
197 m4_define([b4_type_action_
],
198 [b4_symbol_if([$
1], [has_type
],
199 [m4_map([b4_symbol_case_
], [$@
])[]dnl
200 b4_dollar_dollar([b4_symbol([$
1], [number
])],
201 [b4_symbol([$
1], [tag
])],
202 [b4_symbol([$
1], [type
])]);
208 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
209 # -------------------------------------------------
210 # Declare the overloaded version of make_symbol for the (common) type of
211 # these SYMBOL-NUMBERS. Use at class-level.
212 m4_define([b4_symbol_constructor_declaration_
],
213 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
216 make_
[]b4_symbol_([$
1], [id
]) (dnl
217 b4_args(b4_symbol_if([$
1], [has_type
],
218 [const b4_symbol([$
1], [type
])& v
]),
219 b4_locations_if([const location_type
& l
])));
224 # b4_symbol_constructor_declarations
225 # ----------------------------------
226 # Declare symbol constructors for all the value types.
227 # Use at class-level.
228 m4_define([b4_symbol_constructor_declarations
],
230 // Symbol constructors declarations.
231 m4_map([b4_symbol_constructor_declaration_
], m4_defn([b4_symbol_numbers
]))])])
235 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
236 # ------------------------------------------------
237 # Define symbol constructor for this SYMBOL-NUMBER.
238 m4_define([b4_symbol_constructor_definition_
],
239 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
240 [ b4_parser_class_name::symbol_type
241 b4_parser_class_name::make_
[]b4_symbol_([$
1], [id
]) (dnl
242 b4_args(b4_symbol_if([$
1], [has_type
],
243 [const b4_symbol([$
1], [type
])& v
]),
244 b4_locations_if([const location_type
& l
])))
246 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$
1], [id
]))],
247 b4_symbol_if([$
1], [has_type
], [v
]),
248 b4_locations_if([l
])));
254 # b4_symbol_constructor_definitions
255 # ----------------------------------
256 # Define the overloaded versions of make_symbol for all the value types.
257 m4_define([b4_symbol_constructor_definitions
],
258 [[ // symbol_base_type.
259 template <typename Exact
>
260 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
261 : value()]b4_locations_if([
266 template <typename Exact
>
267 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
273 template <typename Exact
>
274 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
275 [const semantic_type
& v
],
276 b4_locations_if([const location_type
& l
]))[)
277 : value(v
)]b4_locations_if([
282 template <typename Exact
>
284 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
286 return static_cast<const Exact
&>(*this);
289 template <typename Exact
>
291 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
293 return static_cast<Exact
&>(*this);
296 template <typename Exact
>
298 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
300 return self ().type_get_ ();
304 ]b4_parser_class_name
[::symbol_type::symbol_type ()
310 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
312 b4_locations_if([const location_type
& l
]))[)
313 : super_type (]b4_locations_if([l
])[)
318 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
320 [const semantic_type
& v
],
321 b4_locations_if([const location_type
& l
]))[)
322 : super_type (v
]b4_locations_if([, l
])[)
328 ]b4_parser_class_name
[::symbol_type::type_get_ () const
333 ]b4_parser_class_name
[::token_type
334 ]b4_parser_class_name
[::symbol_type::token () const
336 // YYTOKNUM[NUM] -- (External) token number corresponding to the
337 // (internal) symbol number NUM (which must be that of a token). */
339 const ]b4_int_type_for([b4_toknum
])[
344 return static_cast<token_type
> (yytoken_number_
[type
]);
349 [ // Implementation of make_symbol for each symbol type.
350 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
353 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
354 # ------------------------------------------------
355 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
357 m4_define([b4_symbol_variant
],
358 [m4_pushdef([b4_dollar_dollar
],
359 [$
2.$
3< $
][3 >(m4_shift3($@
))])dnl
362 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
366 m4_popdef([b4_dollar_dollar
])dnl
370 # _b4_char_sizeof_counter
371 # -----------------------
372 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
373 m4_define([_b4_char_sizeof_counter
],
376 # _b4_char_sizeof_dummy
377 # ---------------------
378 # At each call return a new C++ identifier.
379 m4_define([_b4_char_sizeof_dummy
],
380 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
381 dummy
[]_b4_char_sizeof_counter
])
384 # b4_char_sizeof_(SYMBOL-NUM)
385 # ---------------------------
386 # A comment describing this symbol.
387 m4_define([b4_char_sizeof_
],
388 [ // b4_symbol([$1], [tag])
391 # b4_char_sizeof(SYMBOL-NUMS)
392 # --------------------------
393 # To be mapped on the list of type names to produce:
395 # char dummy1[sizeof(type_name_1)];
396 # char dummy2[sizeof(type_name_2)];
398 # for defined type names.
399 m4_define([b4_char_sizeof
],
400 [b4_symbol_if([$
1], [has_type
],
402 m4_map([b4_char_sizeof_
], [$@
])dnl
403 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type
])])@
};
407 # b4_yytranslate_definition
408 # -------------------------
409 # Define yytranslate_. Sometimes we want it in the header file,
410 # sometimes the cc file suffices.
411 m4_define([b4_yytranslate_definition
],
412 [[ // Symbol number corresponding to token number t.
413 ]b4_parser_class_name
[::token_number_type
414 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
418 const token_number_type
423 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
424 const token_number_type undef_token_
= ]b4_undef_token_number
[;
426 if (static_cast<int>(t
) <= yyeof_
)
428 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
429 return translate_table
[t
];
436 m4_pushdef([b4_copyright_years
],
437 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
439 m4_define([b4_parser_class_name
],
440 [b4_percent_define_get([[parser_class_name]])])
442 # The header is mandatory.
444 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
447 [# Backward compatibility.
448 m4_define([b4_location_constructors
])
449 m4_include(b4_pkgdatadir
/[location
.cc
])])
451 # We do want M4 expansion after # for CPP macros.
454 @
output(b4_spec_defines_file@
)@
455 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
456 dnl FIXME
: This is wrong
, we want computed header guards
.
458 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
460 #ifndef PARSER_HEADER_H
461 # define PARSER_HEADER_H
463 ]b4_percent_code_get([[requires]])[
465 ]b4_assert_if([#include <cassert>])[
471 ]b4_locations_if([ class position
;
475 /// A char[S] buffer to store and retrieve objects.
477 /// Sort of a variant, but does not keep track of the nature
478 /// of the stored data, since that knowledge is available
479 /// via the current state.
483 /// Whether something is contained.
486 /// Empty construction.
488 variant ()]b4_assert_if([
492 /// Instantiate a \a T in here.
493 template <typename T
>
499 return *new (buffer
) T
;
502 /// Instantiate a \a T in here from \a t.
503 template <typename T
>
509 return *new (buffer
) T(t
);
512 /// Construct and fill.
513 template <typename T
>
515 variant (const T
& t
)]b4_assert_if([
521 /// Accessor to a built \a T.
522 template <typename T
>
527 return reinterpret_cast<T
&>(buffer
);
530 /// Const accessor to a built \a T (for %printer).
531 template <typename T
>
536 return reinterpret_cast<const T
&>(buffer
);
539 /// Swap the content with \a other.
540 template <typename T
>
542 swap(variant
<S
>& other
)
544 std::swap(as
<T
>(), other
.as
<T
>());
547 /// Assign the content of \a other to this.
548 /// Destroys \a other.
549 template <typename T
>
551 build(variant
<S
>& other
)
558 /// Destroy the stored \a T.
559 template <typename T
>
563 as
<T
>().~T();]b4_assert_if([
567 /// A buffer large enough to store any of the semantic values.
573 ]b4_locations_if([#include "location.hh"])[
575 /* Enabling traces. */
577 # define YYDEBUG ]b4_debug_flag[
580 /* Enabling verbose error messages. */
581 #ifdef YYERROR_VERBOSE
582 # undef YYERROR_VERBOSE
583 # define YYERROR_VERBOSE 1
585 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
588 /* Enabling the token table. */
589 #ifndef YYTOKEN_TABLE
590 # define YYTOKEN_TABLE ]b4_token_table[
593 ]b4_locations_if([dnl
594 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
595 If N is 0, then set CURRENT to the empty location which ends
596 the previous symbol: RHS[0] (always defined). */
598 #ifndef YYLLOC_DEFAULT
599 # define YYLLOC_DEFAULT(Current, Rhs, N) \
603 (Current).begin = (Rhs)[1].location.begin; \
604 (Current).end = (Rhs)[N].location.end; \
608 (Current).begin = (Current).end = (Rhs)[0].location.end; \
616 class ]b4_parser_class_name
[
621 [ /// An auxiliary type to compute the largest semantic type.
623 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[};
625 /// Symbol semantic values.
626 typedef variant
<sizeof(union_type
)> semantic_type
;],
627 [ /// Symbol semantic values.
629 [ union semantic_type
632 [m4_if(b4_tag_seen_flag
, 0,
633 [[ typedef int semantic_type
;]],
634 [[ typedef YYSTYPE semantic_type
;]])])])[
636 typedef YYSTYPE semantic_type
;
637 #endif]b4_locations_if([
638 /// Symbol locations.
639 typedef b4_percent_define_get([[location_type]]) location_type
;])[
643 ]b4_token_enums(b4_tokens
)[
646 typedef token::yytokentype token_type
;
648 /// Build a parser object.
649 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
650 virtual ~]b4_parser_class_name
[ ();
653 /// \returns 0 iff parsing succeeded.
654 virtual int parse ();
657 /// The current debugging stream.
658 std::ostream
& debug_stream () const;
659 /// Set the current debugging stream.
660 void set_debug_stream (std::ostream
&);
662 /// Type for debugging levels.
663 typedef int debug_level_type
;
664 /// The current debugging level.
665 debug_level_type
debug_level () const;
666 /// Set the current debugging level.
667 void set_debug_level (debug_level_type l
);
671 /// Report a syntax error.]b4_locations_if([
672 /// \param loc where the syntax error is found.])[
673 /// \param msg a description of the syntax error.
674 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
676 /// Generate an error message.
677 /// \param state the state where the error occurred.
678 /// \param tok the lookahead token.
679 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
682 typedef int state_type
;
684 /// Internal symbol numbers.
685 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
687 /// For a state, the index in \a yytable_ of its portion.
688 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
689 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
691 /// For a state, default rule to reduce.
692 /// Unless\a yytable_ specifies something else to do.
693 /// Zero means the default is an error.
694 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
696 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
697 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
699 /// What to do in a state.
700 /// \a yytable_[yypact_[s]]: what to do in state \a s.
701 /// - if positive, shift that token.
702 /// - if negative, reduce the rule which number is the opposite.
703 /// - if zero, do what YYDEFACT says.
704 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
705 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
707 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
709 /// For a state, its accessing symbol.
710 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
712 /// For a rule, its LHS.
713 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
714 /// For a rule, its RHS length.
715 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
717 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
718 /// For a symbol, its name in clear.
719 static const char* const yytname_
[];
720 #endif]b4_error_verbose_if([
722 /// Convert the symbol name \a n to a form suitable for a diagnostic.
723 static std::string
yytnamerr_ (const char *n
);])[
726 /// For each rule, its source line number.
727 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
728 /// Report on the debug stream that the rule \a r is going to be reduced.
729 virtual void yy_reduce_print_ (int r
);
730 /// Print the state stack on the debug stream.
731 virtual void yystack_print_ ();
735 std::ostream
* yycdebug_
;
738 /// Convert a scanner token number \a t to a symbol number.
739 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
741 /// A complete symbol, with its type.
742 template <typename Exact
>
743 struct symbol_base_type
745 /// Default constructor.
746 inline symbol_base_type ();
748 /// Constructor.]b4_locations_if([
749 inline symbol_base_type (const location_type
& l
)])[;
750 inline symbol_base_type (]b4_args(
751 [const semantic_type
& v
],
752 b4_locations_if([const location_type
& l
]))[);
754 /// Return this with its exact type.
755 const Exact
& self () const;
758 /// Return the type of this symbol.
759 int type_get () const;
761 /// The semantic value.
762 semantic_type value
;]b4_locations_if([
765 location_type location
;])[
769 /// \brief Display a symbol type, value and location.
770 /// \param yyo The output stream.
771 /// \param yysym The symbol.
772 template <typename Exact
>
773 void yy_print_ (std::ostream
& yyo
,
774 const symbol_base_type
<Exact
>& yysym
) const;
777 /// \brief Reclaim the memory associated to a symbol.
778 /// \param yymsg Why this token is reclaimed.
779 /// If null, print nothing.
780 /// \param s The symbol.
781 template <typename Exact
>
782 inline void yy_destroy_ (const char* yymsg
,
783 symbol_base_type
<Exact
>& yysym
) const;
786 /// Element of the stack: a state and its attributes.
787 struct symbol_type
: symbol_base_type
<symbol_type
>
789 /// The parent class.
790 typedef symbol_base_type
<symbol_type
> super_type
;
792 /// Default constructor.
793 inline symbol_type ();
796 inline symbol_type (]b4_args([int t
],
797 [const semantic_type
& v
],
798 b4_locations_if([const location_type
& l
]))[);
800 inline symbol_type (]b4_args([int t
],
801 b4_locations_if([const location_type
& l
]))[);
806 /// Return the type corresponding to this state.
807 inline int type_get_ () const;
810 inline token_type
token () 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
[
877 ]b4_lex_symbol_if([b4_yytranslate_definition
])[
878 ]b4_lex_symbol_if([b4_symbol_constructor_definitions
])[
881 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
882 [b4_token_defines(b4_tokens
)
885 /* Redirection for backward compatibility. */
886 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
889 b4_percent_code_get([[provides]])[]dnl
891 [#endif /* ! defined PARSER_HEADER_H */]
892 @
output(b4_parser_file_name@
)@
893 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
894 b4_percent_code_get([[top]])[]dnl
895 m4_if(b4_prefix
, [yy
], [],
897 // Take the name prefix into account.
898 #define yylex b4_prefix[]lex])[
900 /* First part of user declarations. */
901 ]b4_user_pre_prologue
[
903 #include "@basename(]b4_spec_defines_file[@)"
905 /* User implementation prologue. */
906 ]b4_user_post_prologue
907 b4_percent_code_get
[]dnl
912 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
913 # define YY_(msgid) dgettext ("bison-runtime", msgid)
917 # define YY_(msgid) msgid
921 /* Suppress unused-variable warnings by "using" E. */
922 #define YYUSE(e) ((void) (e))
924 /* Enable debugging if requested. */
927 /* A pseudo ostream that takes yydebug_ into account. */
928 # define YYCDEBUG if (yydebug_) (*yycdebug_)
930 # define YY_SYMBOL_PRINT(Title, Symbol) \
934 *yycdebug_ << Title << ' '; \
935 yy_print_ (*yycdebug_, Symbol); \
936 *yycdebug_ << std::endl; \
940 # define YY_REDUCE_PRINT(Rule) \
943 yy_reduce_print_ (Rule); \
946 # define YY_STACK_PRINT() \
954 # define YYCDEBUG if (false) std::cerr
955 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
956 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
957 # define YY_STACK_PRINT() static_cast<void>(0)
959 #endif /* !YYDEBUG */
961 #define yyerrok (yyerrstatus_ = 0)
962 #define yyclearin (yyempty = true)
964 #define YYACCEPT goto yyacceptlab
965 #define YYABORT goto yyabortlab
966 #define YYERROR goto yyerrorlab
967 #define YYRECOVERING() (!!yyerrstatus_)
969 ]b4_namespace_open
[]b4_error_verbose_if([[
971 /* Return YYSTR after stripping away unnecessary quotes and
972 backslashes, so that it's suitable for yyerror. The heuristic is
973 that double-quoting is unnecessary unless the string contains an
974 apostrophe, a comma, or backslash (other than backslash-backslash).
975 YYSTR is taken from yytname. */
977 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
981 std::string yyr
= "";
982 char const *yyp
= yystr
;
989 goto do_not_strip_quotes
;
993 goto do_not_strip_quotes
;
1002 do_not_strip_quotes
: ;
1009 /// Build a parser object.
1010 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
1013 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
1014 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
1015 #endif]b4_parse_param_cons[
1019 ]b4_parser_class_name::~b4_parser_class_name
[ ()
1028 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions
])[
1030 // stack_symbol_type.
1031 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
1037 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
1039 [const semantic_type
& v
],
1040 b4_locations_if([const location_type
& l
]))[)
1041 : super_type (v
]b4_locations_if([, l
])[)
1047 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
1049 return yystos_
[state
];
1053 template <typename Exact
>
1055 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
1056 symbol_base_type
<Exact
>& yysym
) const
1058 int yytype
= yysym
.type_get ();
1061 YY_SYMBOL_PRINT (yymsg
, yysym
);
1066 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
1072 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1076 template <typename Exact
>
1078 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1079 const symbol_base_type
<Exact
>& yysym
) const
1081 int yytype
= yysym
.type_get ();
1082 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1083 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1084 << yysym
.location
<< ": "])[;
1087 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1096 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1100 YY_SYMBOL_PRINT (m
, sym
);
1102 [[ yystack_
.push (stack_symbol_type (]b4_args(
1105 b4_locations_if([sym
.location
]))[));
1106 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1107 [build
], [sym
.value
])],
1108 [[ yystack_
.push (stack_symbol_type (]b4_args(
1111 b4_locations_if([sym
.location
]))[));]])[
1115 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1118 YY_SYMBOL_PRINT (m
, s
);
1120 [[ yystack_
.push (stack_symbol_type (]b4_args(
1123 b4_locations_if([s
.location
]))[));
1124 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1125 [build
], [s
.value
])],
1126 [ yystack_
.push (s
);])[
1130 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1137 ]b4_parser_class_name
[::debug_stream () const
1143 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1149 ]b4_parser_class_name
[::debug_level_type
1150 ]b4_parser_class_name
[::debug_level () const
1156 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1163 ]b4_parser_class_name
[::parse ()
1165 /// Whether yyla contains a lookahead.
1166 bool yyempty
= true;
1173 /* Error handling. */
1175 int yyerrstatus_
= 0;
1177 /// The lookahead symbol.
1178 symbol_type yyla
;]b4_locations_if([[
1180 /// The locations where the error started and ended.
1181 stack_symbol_type yyerror_range
[2];]])[
1184 stack_symbol_type yylhs
;
1186 /// The return value of parse().
1189 YYCDEBUG
<< "Starting parse" << std::endl
;
1191 ]m4_ifdef([b4_initial_action
], [
1192 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1193 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1194 /* User initialization code. */
1195 b4_user_initial_action
1196 m4_popdef([b4_dollar_dollar
])dnl
1197 m4_popdef([b4_at_dollar
])])dnl
1199 [ /* Initialize the stack. The initial state will be set in
1200 yynewstate, since the latter expects the semantical and the
1201 location values to have been already stored, initialize these
1202 stacks with a primary value. */
1203 yystack_
= stack_type (0);
1204 yypush_ (0, 0, yyla
);
1206 // A new state was pushed on the stack.
1207 // Invariant: yystate == yystack_[0].state, i.e.,
1208 // yystate was just pushed onto the state stack.
1210 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1213 if (yystate
== yyfinal_
)
1221 /* Try to take a decision without lookahead. */
1222 yyn
= yypact_
[yystate
];
1223 if (yyn
== yypact_ninf_
)
1226 /* Read a lookahead token. */
1229 YYCDEBUG
<< "Reading a token: ";
1231 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1232 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1233 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1234 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1235 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1236 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1239 YY_SYMBOL_PRINT ("Next token is", yyla
);
1241 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1242 to detect an error, take that action. */
1244 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1247 /* Reduce or error. */
1248 yyn
= yytable_
[yyn
];
1251 if (yyn
== 0 || yyn
== yytable_ninf_
)
1257 /* Discard the token being shifted. */
1260 /* Count tokens shifted since error; after three, turn off error
1265 /* Shift the lookahead token. */
1267 yypush_ ("Shifting", yystate
, yyla
);
1270 /*-----------------------------------------------------------.
1271 | yydefault -- do the default action for the current state. |
1272 `-----------------------------------------------------------*/
1274 yyn
= yydefact_
[yystate
];
1279 /*-----------------------------.
1280 | yyreduce -- Do a reduction. |
1281 `-----------------------------*/
1283 yylen
= yyr2_
[yyn
];]b4_variant_if([
1284 /* Variants are always initialized to an empty instance of the
1285 correct type. The default $$=$1 rule is NOT applied when using
1287 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1288 /* If YYLEN is nonzero, implement the default value of the action:
1289 `$$ = $1'. Otherwise, use the top of the stack.
1291 Otherwise, the following line sets YYLHS.VALUE to garbage.
1292 This behavior is undocumented and Bison
1293 users should not rely upon it. */
1295 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1297 yylhs
.value
= yystack_@
{0@
}.value
;])[
1298 ]b4_locations_if([dnl
1300 // Compute the default @@$.
1302 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1303 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1306 // Perform the reduction.
1307 YY_REDUCE_PRINT (yyn
);
1314 // Compute post-reduction state.
1316 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1317 if (0 <= yystate
&& yystate
<= yylast_
1318 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1319 yystate
= yytable_
[yystate
];
1321 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1322 yylhs
.state
= yystate
;
1323 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1325 // Destroy the lhs symbols.
1326 for (int i
= 0; i
< yylen
; ++i
)
1327 // Destroy a variant which value may have be swapped with
1328 // yylhs.value. The value of yylhs.value (hence maybe one of
1329 // these lhs symbols) depends on what does the default
1330 // contruction for this type. In the case of pointers for
1331 // instance, nothing is done, so the value is junk. Therefore
1332 // do not try to report the content in the debug trace, it's
1333 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1334 // traces as with the other Bison skeletons.
1335 yy_destroy_ (0, yystack_
[i
]);]])[
1341 /* Shift the result of the reduction. */
1345 /*------------------------------------.
1346 | yyerrlab -- here on detecting error |
1347 `------------------------------------*/
1349 /* If not already recovering from an error, report this error. */
1353 error (]b4_args(b4_locations_if([yyla
.location
]),
1354 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1358 yyerror_range
[0].location
= yyla
.location
;]])[
1359 if (yyerrstatus_
== 3)
1361 /* If just tried and failed to reuse lookahead token after an
1362 error, discard it. */
1364 /* Return failure if at end of input. */
1365 if (yyla
.type
== yyeof_
)
1369 yy_destroy_ ("Error: discarding", yyla
);
1374 /* Else will try to reuse lookahead token after shifting the error
1379 /*---------------------------------------------------.
1380 | yyerrorlab -- error raised explicitly by YYERROR. |
1381 `---------------------------------------------------*/
1384 /* Pacify compilers like GCC when the user code never invokes
1385 YYERROR and the label yyerrorlab therefore never appears in user
1391 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1392 /* Do not reclaim the symbols of the rule which action triggered
1396 yystate
= yystack_
[0].state
;
1399 /*-------------------------------------------------------------.
1400 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1401 `-------------------------------------------------------------*/
1403 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1405 stack_symbol_type error_token
;
1408 yyn
= yypact_
[yystate
];
1409 if (yyn
!= yypact_ninf_
)
1412 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1414 yyn
= yytable_
[yyn
];
1420 // Pop the current state because it cannot handle the error token.
1421 if (yystack_
.size () == 1)
1424 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1425 yy_destroy_ ("Error: popping", yystack_
[0]);
1427 yystate
= yystack_
[0].state
;
1431 yyerror_range
[1].location
= yyla
.location
;
1432 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1434 /* Shift the error token. */
1435 error_token
.state
= yystate
= yyn
;
1436 yypush_ ("Shifting", error_token
);
1452 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1454 /* Do not reclaim the symbols of the rule which action triggered
1455 this YYABORT or YYACCEPT. */
1457 while (yystack_
.size () != 1)
1459 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1466 // Generate an error message.
1468 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1469 b4_error_verbose_if([int yystate
, int yytoken
],
1472 std::string yyres
;]b4_error_verbose_if([[
1473 int yyn
= yypact_
[yystate
];
1474 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1476 /* Start YYX at -YYN if negative to avoid negative indexes in
1478 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1480 /* Stay within bounds of both yycheck and yytname. */
1481 int yychecklim
= yylast_
- yyn
+ 1;
1482 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1484 // Number of "expected" tokens.
1487 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1488 // Arguments of yyformat.
1489 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1490 yyarg
[yycount
++] = yytname_
[yytoken
];
1491 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1492 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1494 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1500 yyarg
[yycount
++] = yytname_
[yyx
];
1503 char const* yyformat
= 0;
1506 #define YYCASE_(N, S) \
1510 YYCASE_(1, YY_("syntax error, unexpected %s"));
1511 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1512 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1513 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1514 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1519 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1520 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1522 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1530 [ yyres
= YY_("syntax error");
1535 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1537 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1538 ]b4_table_define([pact
], [b4_pact
])[;
1540 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1541 doesn't specify something else to do. Zero means the default is an
1543 ]b4_table_define([defact
], [b4_defact
])[;
1545 /* YYPGOTO[NTERM-NUM]. */
1546 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1548 /* YYDEFGOTO[NTERM-NUM]. */
1549 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1551 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1552 positive, shift that token. If negative, reduce the rule which
1553 number is the opposite. If zero, do what YYDEFACT says. */
1554 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1555 ]b4_table_define([table
], [b4_table
])[;
1558 ]b4_table_define([check
], [b4_check
])[;
1560 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1561 symbol of state STATE-NUM. */
1562 ]b4_table_define([stos
], [b4_stos
])[;
1564 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1565 ]b4_table_define([r1
], [b4_r1
])[;
1567 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1568 ]b4_table_define([r2
], [b4_r2
])[;
1570 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1571 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1572 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1574 const ]b4_parser_class_name
[::yytname_
[] =
1581 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1582 ]b4_table_define([rline
], [b4_rline
])[;
1584 // Print the state stack on the debug stream.
1586 ]b4_parser_class_name
[::yystack_print_ ()
1588 *yycdebug_
<< "Stack now";
1589 for (stack_type::const_iterator
1590 i
= yystack_
.begin (),
1591 i_end
= yystack_
.end ();
1593 *yycdebug_
<< ' ' << i
->state
;
1594 *yycdebug_
<< std::endl
;
1597 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1599 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1601 unsigned int yylno
= yyrline_
[yyrule
];
1602 int yynrhs
= yyr2_
[yyrule
];
1603 /* Print the symbols being reduced, and their result. */
1604 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1605 << " (line " << yylno
<< "):" << std::endl
;
1606 /* The symbols being reduced. */
1607 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1608 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1609 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1613 ]b4_lex_symbol_if([], [b4_yytranslate_definition
])[
1614 ]b4_namespace_close
[
1617 @
output(b4_dir_prefix
[]stack
.hh@
)@
1618 b4_copyright([Stack handling
for Bison parsers in C
++])[
1620 #ifndef BISON_STACK_HH
1621 # define BISON_STACK_HH
1626 template <class T
, class S
= std::deque
<T
> >
1631 // Hide our reversed order.
1632 typedef typename
S::reverse_iterator iterator
;
1633 typedef typename
S::const_reverse_iterator const_iterator
;
1639 stack (unsigned int n
) : seq_ (n
)
1645 operator [] (unsigned int i
)
1652 operator [] (unsigned int i
) const
1661 seq_
.push_front (t
);
1666 pop (unsigned int n
= 1)
1673 typename
S::size_type
1676 return seq_
.size ();
1679 inline const_iterator
begin () const { return seq_
.rbegin (); }
1680 inline const_iterator
end () const { return seq_
.rend (); }
1683 /// The wrapped container.
1687 /// Present a slice of the top of a stack.
1688 template <class T
, class S
= stack
<T
> >
1693 slice (const S
& stack
,
1694 unsigned int range
) : stack_ (stack
),
1701 operator [] (unsigned int i
) const
1703 return stack_
[range_
- i
];
1709 unsigned int range_
;
1711 ]b4_namespace_close
[
1713 #endif // not BISON_STACK_HH[]dnl
1716 m4_popdef([b4_copyright_years
])dnl