b4_args is more general than only C++.
[bison/ericb.git] / data / lalr1.cc
blob404309054b3732fcde5d6e0ef46fdf930e428c16
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_table_define(TABLE-NAME, CONTENT)
23 # ------------------------------------
24 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
25 m4_define([b4_table_define],
26 [const b4_int_type_for([$2])
27 b4_parser_class_name::yy$1_[[]] =
30 }dnl
33 # b4_symbol_value_template(VAL, [TYPE])
34 # -------------------------------------
35 # Same as b4_symbol_value, but used in a template method.
36 m4_copy([b4_symbol_value], [b4_symbol_value_template])
38 # How the semantic value is extracted when using variants.
39 b4_variant_if([
40 # b4_symbol_value(VAL, [TYPE])
41 # ----------------------------
42 m4_define([b4_symbol_value],
43 [m4_ifval([$2],
44 [$1.as< $2 >()],
45 [$1])])
47 # b4_symbol_value_template(VAL, [TYPE])
48 # -------------------------------------
49 # Same as b4_symbol_value, but used in a template method.
50 m4_define([b4_symbol_value_template],
51 [m4_ifval([$2],
52 [$1.template as< $2 >()],
53 [$1])])
54 ]) # b4_variant_if
57 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
58 # ----------------------------------------------------------------
59 m4_define([b4_lex_symbol_if],
60 [b4_percent_define_ifdef([[lex_symbol]], [$1], [$2])])
63 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
64 # ------------------------------------------------
65 m4_define([b4_assert_if],
66 [b4_percent_define_ifdef([[assert]], [$1], [$2])])
69 # b4_lhs_value([TYPE])
70 # --------------------
71 # Expansion of $<TYPE>$.
72 m4_define([b4_lhs_value],
73 [b4_symbol_value([yylhs.value], [$1])])
76 # b4_lhs_location()
77 # -----------------
78 # Expansion of @$.
79 m4_define([b4_lhs_location],
80 [yylhs.location])
83 # b4_rhs_data(RULE-LENGTH, NUM)
84 # -----------------------------
85 # Return the data corresponding to the symbol #NUM, where the current
86 # rule has RULE-LENGTH symbols on RHS.
87 m4_define([b4_rhs_data],
88 [yystack_@{b4_subtract($@)@}])
91 # b4_rhs_state(RULE-LENGTH, NUM)
92 # -----------------------------
93 # The state corresponding to the symbol #NUM, where the current
94 # rule has RULE-LENGTH symbols on RHS.
95 m4_define([b4_rhs_state],
96 [b4_rhs_data([$1], [$2]).state])
99 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
100 # --------------------------------------
101 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
102 # symbols on RHS.
103 m4_define([b4_rhs_value],
104 [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
107 # b4_rhs_location(RULE-LENGTH, NUM)
108 # ---------------------------------
109 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
110 # on RHS.
111 m4_define([b4_rhs_location],
112 [b4_rhs_data([$1], [$2]).location])
115 # b4_symbol_(NUM, FIELD)
116 # ----------------------
117 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
118 # undefined.
119 m4_define([b4_symbol_],
120 [m4_indir([b4_symbol($1, $2)])])
123 # b4_symbol(NUM, FIELD)
124 # ---------------------
125 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
126 # undefined. If FIELD = id, prepend the prefix.
127 m4_define([b4_symbol],
128 [m4_case([$2],
129 [id], [m4_do([b4_percent_define_get([token.prefix])],
130 [b4_symbol_([$1], [id])])],
131 [b4_symbol_($@)])])
134 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
135 # -------------------------------------------
136 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
137 # Otherwise an error.
138 m4_define([b4_symbol_if],
139 [m4_case(b4_symbol([$1], [$2]),
140 [1], [$3],
141 [0], [$4],
142 [m4_fatal([$0: field $2 of $1 is not a Boolean:] b4_symbol([$1], [$2]))])])
145 # b4_symbol_actions(FILENAME, LINENO,
146 # SYMBOL-TAG, SYMBOL-NUM,
147 # SYMBOL-ACTION, SYMBOL-TYPENAME)
148 # -------------------------------------------------
149 # Same as in C, but using references instead of pointers.
150 m4_define([b4_symbol_actions],
151 [m4_pushdef([b4_dollar_dollar],
152 [b4_symbol_value_template([yysym.value], [$6])])dnl
153 m4_pushdef([b4_at_dollar], [yysym.location])dnl
154 case $4: // $3
155 b4_syncline([$2], [$1])
157 b4_syncline([@oline@], [@ofile@])
158 break;
159 m4_popdef([b4_at_dollar])dnl
160 m4_popdef([b4_dollar_dollar])dnl
164 # b4_symbol_case_(SYMBOL-NUM)
165 # ---------------------------
166 # Issue a "case NUM" for SYMBOL-NUM.
167 m4_define([b4_symbol_case_],
168 [ case b4_symbol([$1], [number]): // b4_symbol([$1], [tag])
172 # b4_type_action_(NUMS)
173 # ---------------------
174 # Run actions for the symbol NUMS that all have the same type-name.
175 # Skip NUMS that have no type-name.
176 m4_define([b4_type_action_],
177 [b4_symbol_if([$1], [has_type],
178 [m4_map([b4_symbol_case_], [$@])[]dnl
179 b4_dollar_dollar([b4_symbol([$1], [number])],
180 [b4_symbol([$1], [tag])],
181 [b4_symbol([$1], [type])]);
182 break;
184 ])])
187 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
188 # -------------------------------------------------
189 # Declare the overloaded version of make_symbol for the (common) type of
190 # these SYMBOL-NUMBERS. Use at class-level.
191 m4_define([b4_symbol_constructor_declaration_],
192 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
193 [ static inline
194 symbol_type
195 make_[]b4_symbol_([$1], [id]) (dnl
196 b4_args(b4_symbol_if([$1], [has_type],
197 [const b4_symbol([$1], [type])& v]),
198 b4_locations_if([const location_type& l])));
200 ])])])
203 # b4_symbol_constructor_declarations
204 # ----------------------------------
205 # Declare symbol constructors for all the value types.
206 # Use at class-level.
207 m4_define([b4_symbol_constructor_declarations],
208 [b4_variant_if([
209 // Symbol constructors declarations.
210 m4_map([b4_symbol_constructor_declaration_], m4_defn([b4_symbol_numbers]))])])
214 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
215 # ------------------------------------------------
216 # Define symbol constructor for this SYMBOL-NUMBER.
217 m4_define([b4_symbol_constructor_definition_],
218 [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
219 [ b4_parser_class_name::symbol_type
220 b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
221 b4_args(b4_symbol_if([$1], [has_type],
222 [const b4_symbol([$1], [type])& v]),
223 b4_locations_if([const location_type& l])))
225 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [id]))],
226 b4_symbol_if([$1], [has_type], [v]),
227 b4_locations_if([l])));
230 ])])])
233 # b4_symbol_constructor_definitions
234 # ----------------------------------
235 # Define the overloaded versions of make_symbol for all the value types.
236 m4_define([b4_symbol_constructor_definitions],
237 [[ // symbol_base_type.
238 template <typename Exact>
239 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type ()
240 : value()]b4_locations_if([
241 , location()])[
243 }]b4_locations_if([[
245 template <typename Exact>
246 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (const location_type& l)
247 : value()
248 , location(l)
250 }]])[
252 template <typename Exact>
253 ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (]b4_args(
254 [const semantic_type& v],
255 b4_locations_if([const location_type& l]))[)
256 : value(v)]b4_locations_if([
257 , location(l)])[
261 template <typename Exact>
262 const Exact&
263 ]b4_parser_class_name[::symbol_base_type<Exact>::self () const
265 return static_cast<const Exact&>(*this);
268 template <typename Exact>
269 Exact&
270 ]b4_parser_class_name[::symbol_base_type<Exact>::self ()
272 return static_cast<Exact&>(*this);
275 template <typename Exact>
277 ]b4_parser_class_name[::symbol_base_type<Exact>::type_get () const
279 return self ().type_get_ ();
282 // symbol_type.
283 ]b4_parser_class_name[::symbol_type::symbol_type ()
284 : super_type ()
285 , type ()
289 ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
290 [int t],
291 b4_locations_if([const location_type& l]))[)
292 : super_type (]b4_locations_if([l])[)
293 , type (t)
297 ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
298 [int t],
299 [const semantic_type& v],
300 b4_locations_if([const location_type& l]))[)
301 : super_type (v]b4_locations_if([, l])[)
302 , type (t)
307 ]b4_parser_class_name[::symbol_type::type_get_ () const
309 return type;
311 ]b4_lex_symbol_if([[
312 ]b4_parser_class_name[::token_type
313 ]b4_parser_class_name[::symbol_type::token () const
315 // YYTOKNUM[NUM] -- (External) token number corresponding to the
316 // (internal) symbol number NUM (which must be that of a token). */
317 static
318 const ]b4_int_type_for([b4_toknum])[
319 yytoken_number_[] =
321 ]b4_toknum[
323 return static_cast<token_type> (yytoken_number_[type]);
325 ]])[
327 ]b4_variant_if(
328 [ // Implementation of make_symbol for each symbol type.
329 m4_map([b4_symbol_constructor_definition_], m4_defn([b4_symbol_numbers]))])])
332 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
333 # ------------------------------------------------
334 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
335 # YYTYPE.
336 m4_define([b4_symbol_variant],
337 [m4_pushdef([b4_dollar_dollar],
338 [$2.$3< $][3 >(m4_shift3($@))])dnl
339 switch ($1)
341 m4_map([b4_type_action_], m4_defn([b4_type_names]))[]dnl
342 default:
343 break;
345 m4_popdef([b4_dollar_dollar])dnl
349 # _b4_char_sizeof_counter
350 # -----------------------
351 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
352 m4_define([_b4_char_sizeof_counter],
353 [0])
355 # _b4_char_sizeof_dummy
356 # ---------------------
357 # At each call return a new C++ identifier.
358 m4_define([_b4_char_sizeof_dummy],
359 [m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl
360 dummy[]_b4_char_sizeof_counter])
363 # b4_char_sizeof_(SYMBOL-NUM)
364 # ---------------------------
365 # A comment describing this symbol.
366 m4_define([b4_char_sizeof_],
367 [ // b4_symbol([$1], [tag])
370 # b4_char_sizeof(SYMBOL-NUMS)
371 # --------------------------
372 # To be mapped on the list of type names to produce:
374 # char dummy1[sizeof(type_name_1)];
375 # char dummy2[sizeof(type_name_2)];
377 # for defined type names.
378 m4_define([b4_char_sizeof],
379 [b4_symbol_if([$1], [has_type],
381 m4_map([b4_char_sizeof_], [$@])dnl
382 char _b4_char_sizeof_dummy@{sizeof([b4_symbol([$1], [type])])@};
383 ])])
386 # b4_yytranslate_definition
387 # -------------------------
388 # Define yytranslate_. Sometimes we want it in the header file,
389 # sometimes the cc file suffices.
390 m4_define([b4_yytranslate_definition],
391 [[ // Symbol number corresponding to token number t.
392 ]b4_parser_class_name[::token_number_type
393 ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type],
394 [int])[ t)
396 static
397 const token_number_type
398 translate_table[] =
400 ]b4_translate[
402 const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
403 const token_number_type undef_token_ = ]b4_undef_token_number[;
405 if (static_cast<int>(t) <= yyeof_)
406 return yyeof_;
407 else if (static_cast<unsigned int> (t) <= user_token_number_max_)
408 return translate_table[t];
409 else
410 return undef_token_;
415 m4_pushdef([b4_copyright_years],
416 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
418 m4_define([b4_parser_class_name],
419 [b4_percent_define_get([[parser_class_name]])])
421 # The header is mandatory.
422 b4_defines_if([],
423 [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
425 b4_locations_if(
426 [# Backward compatibility.
427 m4_define([b4_location_constructors])
428 m4_include(b4_pkgdatadir/[location.cc])])
430 # We do want M4 expansion after # for CPP macros.
431 m4_changecom()
432 m4_divert_push(0)dnl
433 @output(b4_spec_defines_file@)@
434 b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
435 dnl FIXME: This is wrong, we want computed header guards.
437 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
439 #ifndef PARSER_HEADER_H
440 # define PARSER_HEADER_H
442 ]b4_percent_code_get([[requires]])[
444 ]b4_assert_if([#include <cassert>])[
445 #include <string>
446 #include <iostream>
447 #include "stack.hh"
449 ]b4_namespace_open[
450 ]b4_locations_if([ class position;
451 class location;])[
452 ]b4_variant_if(
454 /// A char[S] buffer to store and retrieve objects.
456 /// Sort of a variant, but does not keep track of the nature
457 /// of the stored data, since that knowledge is available
458 /// via the current state.
459 template <size_t S>
460 struct variant
461 {]b4_assert_if([
462 /// Whether something is contained.
463 bool built;
465 /// Empty construction.
466 inline
467 variant ()]b4_assert_if([
468 : built(false)])[
471 /// Instantiate a \a T in here.
472 template <typename T>
473 inline T&
474 build()
475 {]b4_assert_if([
476 assert(!built);
477 built = true;])[
478 return *new (buffer) T;
481 /// Instantiate a \a T in here from \a t.
482 template <typename T>
483 inline T&
484 build(const T& t)
485 {]b4_assert_if([
486 assert(!built);
487 built = true;])[
488 return *new (buffer) T(t);
491 /// Construct and fill.
492 template <typename T>
493 inline
494 variant (const T& t)]b4_assert_if([
495 : built(true)])[
497 new (buffer) T(t);
500 /// Accessor to a built \a T.
501 template <typename T>
502 inline T&
503 as()
504 {]b4_assert_if([
505 assert(built);])[
506 return reinterpret_cast<T&>(buffer);
509 /// Const accessor to a built \a T (for %printer).
510 template <typename T>
511 inline const T&
512 as() const
513 {]b4_assert_if([
514 assert(built);])[
515 return reinterpret_cast<const T&>(buffer);
518 /// Swap the content with \a other.
519 template <typename T>
520 inline void
521 swap(variant<S>& other)
523 std::swap(as<T>(), other.as<T>());
526 /// Assign the content of \a other to this.
527 /// Destroys \a other.
528 template <typename T>
529 inline void
530 build(variant<S>& other)
532 build<T>();
533 swap<T>(other);
534 other.destroy<T>();
537 /// Destroy the stored \a T.
538 template <typename T>
539 inline void
540 destroy()
542 as<T>().~T();]b4_assert_if([
543 built = false;])[
546 /// A buffer large enough to store any of the semantic values.
547 char buffer[S];
549 ]])[
550 ]b4_namespace_close[
552 ]b4_locations_if([#include "location.hh"])[
554 /* Enabling traces. */
555 #ifndef YYDEBUG
556 # define YYDEBUG ]b4_debug_flag[
557 #endif
559 /* Enabling verbose error messages. */
560 #ifdef YYERROR_VERBOSE
561 # undef YYERROR_VERBOSE
562 # define YYERROR_VERBOSE 1
563 #else
564 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
565 #endif
567 /* Enabling the token table. */
568 #ifndef YYTOKEN_TABLE
569 # define YYTOKEN_TABLE ]b4_token_table[
570 #endif
572 ]b4_locations_if([dnl
573 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
574 If N is 0, then set CURRENT to the empty location which ends
575 the previous symbol: RHS[0] (always defined). */
577 #ifndef YYLLOC_DEFAULT
578 # define YYLLOC_DEFAULT(Current, Rhs, N) \
579 do { \
580 if (N) \
582 (Current).begin = (Rhs)[1].location.begin; \
583 (Current).end = (Rhs)[N].location.end; \
585 else \
587 (Current).begin = (Current).end = (Rhs)[0].location.end; \
589 } while (false)
590 #endif]])[
592 ]b4_namespace_open[
594 /// A Bison parser.
595 class ]b4_parser_class_name[
597 public:
598 #ifndef YYSTYPE
599 ]b4_variant_if(
600 [ /// An auxiliary type to compute the largest semantic type.
601 union union_type
602 {]m4_map([b4_char_sizeof], m4_defn([b4_type_names]))[};
604 /// Symbol semantic values.
605 typedef variant<sizeof(union_type)> semantic_type;],
606 [ /// Symbol semantic values.
607 m4_ifdef([b4_stype],
608 [ union semantic_type
609 {b4_user_stype
610 };],
611 [m4_if(b4_tag_seen_flag, 0,
612 [[ typedef int semantic_type;]],
613 [[ typedef YYSTYPE semantic_type;]])])])[
614 #else
615 typedef YYSTYPE semantic_type;
616 #endif]b4_locations_if([
617 /// Symbol locations.
618 typedef b4_percent_define_get([[location_type]]) location_type;])[
619 /// Tokens.
620 struct token
622 ]b4_token_enums(b4_tokens)[
624 /// Token type.
625 typedef token::yytokentype token_type;
627 /// Build a parser object.
628 ]b4_parser_class_name[ (]b4_parse_param_decl[);
629 virtual ~]b4_parser_class_name[ ();
631 /// Parse.
632 /// \returns 0 iff parsing succeeded.
633 virtual int parse ();
635 #if YYDEBUG
636 /// The current debugging stream.
637 std::ostream& debug_stream () const;
638 /// Set the current debugging stream.
639 void set_debug_stream (std::ostream &);
641 /// Type for debugging levels.
642 typedef int debug_level_type;
643 /// The current debugging level.
644 debug_level_type debug_level () const;
645 /// Set the current debugging level.
646 void set_debug_level (debug_level_type l);
647 #endif
649 private:
650 /// Report a syntax error.]b4_locations_if([
651 /// \param loc where the syntax error is found.])[
652 /// \param msg a description of the syntax error.
653 virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg);
655 /// Generate an error message.
656 /// \param state the state where the error occurred.
657 /// \param tok the lookahead token.
658 virtual std::string yysyntax_error_ (int yystate, int tok);
660 /// State numbers.
661 typedef int state_type;
663 /// Internal symbol numbers.
664 typedef ]b4_int_type_for([b4_translate])[ token_number_type;
665 /* Tables. */
666 /// For a state, the index in \a yytable_ of its portion.
667 static const ]b4_int_type_for([b4_pact])[ yypact_[];
668 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
670 /// For a state, default rule to reduce.
671 /// Unless\a yytable_ specifies something else to do.
672 /// Zero means the default is an error.
673 static const ]b4_int_type_for([b4_defact])[ yydefact_[];
675 static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
676 static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
678 /// What to do in a state.
679 /// \a yytable_[yypact_[s]]: what to do in state \a s.
680 /// - if positive, shift that token.
681 /// - if negative, reduce the rule which number is the opposite.
682 /// - if zero, do what YYDEFACT says.
683 static const ]b4_int_type_for([b4_table])[ yytable_[];
684 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
686 static const ]b4_int_type_for([b4_check])[ yycheck_[];
688 /// For a state, its accessing symbol.
689 static const ]b4_int_type_for([b4_stos])[ yystos_[];
691 /// For a rule, its LHS.
692 static const ]b4_int_type_for([b4_r1])[ yyr1_[];
693 /// For a rule, its RHS length.
694 static const ]b4_int_type_for([b4_r2])[ yyr2_[];
696 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
697 /// For a symbol, its name in clear.
698 static const char* const yytname_[];
699 #endif]b4_error_verbose_if([
701 /// Convert the symbol name \a n to a form suitable for a diagnostic.
702 static std::string yytnamerr_ (const char *n);])[
704 #if YYDEBUG
705 /// For each rule, its source line number.
706 static const ]b4_int_type_for([b4_rline])[ yyrline_[];
707 /// Report on the debug stream that the rule \a r is going to be reduced.
708 virtual void yy_reduce_print_ (int r);
709 /// Print the state stack on the debug stream.
710 virtual void yystack_print_ ();
712 /* Debugging. */
713 int yydebug_;
714 std::ostream* yycdebug_;
715 #endif
717 /// Convert a scanner token number \a t to a symbol number.
718 static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
720 /// A complete symbol, with its type.
721 template <typename Exact>
722 struct symbol_base_type
724 /// Default constructor.
725 inline symbol_base_type ();
727 /// Constructor.]b4_locations_if([
728 inline symbol_base_type (const location_type& l)])[;
729 inline symbol_base_type (]b4_args(
730 [const semantic_type& v],
731 b4_locations_if([const location_type& l]))[);
733 /// Return this with its exact type.
734 const Exact& self () const;
735 Exact& self ();
737 /// Return the type of this symbol.
738 int type_get () const;
740 /// The semantic value.
741 semantic_type value;]b4_locations_if([
743 /// The location.
744 location_type location;])[
747 #if YYDEBUG
748 /// \brief Display a symbol type, value and location.
749 /// \param yyo The output stream.
750 /// \param yysym The symbol.
751 template <typename Exact>
752 void yy_print_ (std::ostream& yyo,
753 const symbol_base_type<Exact>& yysym) const;
754 #endif
756 /// \brief Reclaim the memory associated to a symbol.
757 /// \param yymsg Why this token is reclaimed.
758 /// If null, print nothing.
759 /// \param s The symbol.
760 template <typename Exact>
761 inline void yy_destroy_ (const char* yymsg,
762 symbol_base_type<Exact>& yysym) const;
764 public:
765 /// Element of the stack: a state and its attributes.
766 struct symbol_type : symbol_base_type<symbol_type>
768 /// The parent class.
769 typedef symbol_base_type<symbol_type> super_type;
771 /// Default constructor.
772 inline symbol_type ();
774 /// Constructor.
775 inline symbol_type (]b4_args([int t],
776 [const semantic_type& v],
777 b4_locations_if([const location_type& l]))[);
779 inline symbol_type (]b4_args([int t],
780 b4_locations_if([const location_type& l]))[);
782 /// The symbol type.
783 int type;
785 /// Return the type corresponding to this state.
786 inline int type_get_ () const;
788 /// Its token.
789 inline token_type token () const;
792 ]b4_symbol_constructor_declarations[
794 private:
795 /// Element of the stack: a state and its attributes.
796 struct stack_symbol_type : symbol_base_type<stack_symbol_type>
798 /// The parent class.
799 typedef symbol_base_type<stack_symbol_type> super_type;
801 /// Default constructor.
802 inline stack_symbol_type ();
804 /// Constructor.
805 inline stack_symbol_type (]b4_args([state_type s],
806 [const semantic_type& v],
807 b4_locations_if([const location_type& l]))[);
809 /// The state.
810 state_type state;
812 /// Return the type corresponding to this state.
813 inline int type_get_ () const;
816 /// Stack type.
817 typedef stack<stack_symbol_type> stack_type;
819 /// The stack.
820 stack_type yystack_;
822 /// Push a new state on the stack.
823 /// \param m a debug message to display
824 /// if null, no trace is output.
825 /// \param s the symbol
826 /// \warning the contents of \a s.value is stolen.
827 inline void yypush_ (const char* m, stack_symbol_type& s);
829 /// Push a new look ahead token on the state on the stack.
830 /// \param m a debug message to display
831 /// if null, no trace is output.
832 /// \param s the state
833 /// \param sym the symbol (for its value and location).
834 /// \warning the contents of \a s.value is stolen.
835 inline void yypush_ (const char* m, state_type s, symbol_type& sym);
837 /// Pop \a n symbols the three stacks.
838 inline void yypop_ (unsigned int n = 1);
840 /* Constants. */
841 enum
843 yyeof_ = 0,
844 yylast_ = ]b4_last[, //< Last index in yytable_.
845 yynnts_ = ]b4_nterms_number[, //< Number of nonterminal symbols.
846 yyempty_ = -2,
847 yyfinal_ = ]b4_final_state_number[, //< Termination state number.
848 yyterror_ = 1,
849 yyerrcode_ = 256,
850 yyntokens_ = ]b4_tokens_number[, //< Number of tokens.
853 ]b4_parse_param_vars[
856 ]b4_lex_symbol_if([b4_yytranslate_definition])[
857 ]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
858 ]b4_namespace_close[
860 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
861 [b4_token_defines(b4_tokens)
863 #ifndef YYSTYPE
864 /* Redirection for backward compatibility. */
865 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
866 #endif
868 b4_percent_code_get([[provides]])[]dnl
870 [#endif /* ! defined PARSER_HEADER_H */]
871 @output(b4_parser_file_name@)@
872 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
873 b4_percent_code_get([[top]])[]dnl
874 m4_if(b4_prefix, [yy], [],
876 // Take the name prefix into account.
877 #define yylex b4_prefix[]lex])[
879 /* First part of user declarations. */
880 ]b4_user_pre_prologue[
882 #include "@basename(]b4_spec_defines_file[@)"
884 /* User implementation prologue. */
885 ]b4_user_post_prologue
886 b4_percent_code_get[]dnl
888 [#ifndef YY_
889 # if YYENABLE_NLS
890 # if ENABLE_NLS
891 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
892 # define YY_(msgid) dgettext ("bison-runtime", msgid)
893 # endif
894 # endif
895 # ifndef YY_
896 # define YY_(msgid) msgid
897 # endif
898 #endif
900 /* Suppress unused-variable warnings by "using" E. */
901 #define YYUSE(e) ((void) (e))
903 /* Enable debugging if requested. */
904 #if YYDEBUG
906 /* A pseudo ostream that takes yydebug_ into account. */
907 # define YYCDEBUG if (yydebug_) (*yycdebug_)
909 # define YY_SYMBOL_PRINT(Title, Symbol) \
910 do { \
911 if (yydebug_) \
913 *yycdebug_ << Title << ' '; \
914 yy_print_ (*yycdebug_, Symbol); \
915 *yycdebug_ << std::endl; \
917 } while (false)
919 # define YY_REDUCE_PRINT(Rule) \
920 do { \
921 if (yydebug_) \
922 yy_reduce_print_ (Rule); \
923 } while (false)
925 # define YY_STACK_PRINT() \
926 do { \
927 if (yydebug_) \
928 yystack_print_ (); \
929 } while (false)
931 #else /* !YYDEBUG */
933 # define YYCDEBUG if (false) std::cerr
934 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
935 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
936 # define YY_STACK_PRINT() static_cast<void>(0)
938 #endif /* !YYDEBUG */
940 #define yyerrok (yyerrstatus_ = 0)
941 #define yyclearin (yyempty = true)
943 #define YYACCEPT goto yyacceptlab
944 #define YYABORT goto yyabortlab
945 #define YYERROR goto yyerrorlab
946 #define YYRECOVERING() (!!yyerrstatus_)
948 ]b4_namespace_open[]b4_error_verbose_if([[
950 /* Return YYSTR after stripping away unnecessary quotes and
951 backslashes, so that it's suitable for yyerror. The heuristic is
952 that double-quoting is unnecessary unless the string contains an
953 apostrophe, a comma, or backslash (other than backslash-backslash).
954 YYSTR is taken from yytname. */
955 std::string
956 ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
958 if (*yystr == '"')
960 std::string yyr = "";
961 char const *yyp = yystr;
963 for (;;)
964 switch (*++yyp)
966 case '\'':
967 case ',':
968 goto do_not_strip_quotes;
970 case '\\':
971 if (*++yyp != '\\')
972 goto do_not_strip_quotes;
973 /* Fall through. */
974 default:
975 yyr += *yyp;
976 break;
978 case '"':
979 return yyr;
981 do_not_strip_quotes: ;
984 return yystr;
986 ]])[
988 /// Build a parser object.
989 ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [
990 :])[
991 #if YYDEBUG
992 ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
993 yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
994 #endif]b4_parse_param_cons[
998 ]b4_parser_class_name::~b4_parser_class_name[ ()
1003 /*---------------.
1004 | Symbol types. |
1005 `---------------*/
1007 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[
1009 // stack_symbol_type.
1010 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
1011 : super_type ()
1012 , state ()
1016 ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (]b4_args(
1017 [state_type s],
1018 [const semantic_type& v],
1019 b4_locations_if([const location_type& l]))[)
1020 : super_type (v]b4_locations_if([, l])[)
1021 , state (s)
1026 ]b4_parser_class_name[::stack_symbol_type::type_get_ () const
1028 return yystos_[state];
1032 template <typename Exact>
1033 void
1034 ]b4_parser_class_name[::yy_destroy_ (const char* yymsg,
1035 symbol_base_type<Exact>& yysym) const
1037 int yytype = yysym.type_get ();
1038 YYUSE (yymsg);
1039 if (yymsg)
1040 YY_SYMBOL_PRINT (yymsg, yysym);
1042 // User destructor.
1043 switch (yytype)
1045 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
1046 default:
1047 break;
1048 }]b4_variant_if([
1050 // Type destructor.
1051 b4_symbol_variant([[yytype]], [[yysym.value]], [[template destroy]])])[
1054 #if YYDEBUG
1055 template <typename Exact>
1056 void
1057 ]b4_parser_class_name[::yy_print_ (std::ostream& yyo,
1058 const symbol_base_type<Exact>& yysym) const
1060 int yytype = yysym.type_get ();
1061 yyo << (yytype < yyntokens_ ? "token" : "nterm")
1062 << ' ' << yytname_[yytype] << " ("]b4_locations_if([
1063 << yysym.location << ": "])[;
1064 switch (yytype)
1066 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))[
1067 default:
1068 break;
1070 yyo << ')';
1072 #endif
1074 void
1075 ]b4_parser_class_name[::yypush_ (const char* m, state_type s,
1076 symbol_type& sym)
1078 if (m)
1079 YY_SYMBOL_PRINT (m, sym);
1080 ]b4_variant_if(
1081 [[ yystack_.push (stack_symbol_type (]b4_args(
1082 [s],
1083 [semantic_type()],
1084 b4_locations_if([sym.location]))[));
1085 ]b4_symbol_variant([[yystos_[s]]], [[yystack_[0].value]],
1086 [build], [sym.value])],
1087 [[ yystack_.push (stack_symbol_type (]b4_args(
1088 [s],
1089 [sym.value],
1090 b4_locations_if([sym.location]))[));]])[
1093 void
1094 ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s)
1096 if (m)
1097 YY_SYMBOL_PRINT (m, s);
1098 ]b4_variant_if(
1099 [[ yystack_.push (stack_symbol_type (]b4_args(
1100 [s.state],
1101 [semantic_type()],
1102 b4_locations_if([s.location]))[));
1103 ]b4_symbol_variant([[yystos_[s.state]]], [[yystack_[0].value]],
1104 [build], [s.value])],
1105 [ yystack_.push (s);])[
1108 void
1109 ]b4_parser_class_name[::yypop_ (unsigned int n)
1111 yystack_.pop (n);
1114 #if YYDEBUG
1115 std::ostream&
1116 ]b4_parser_class_name[::debug_stream () const
1118 return *yycdebug_;
1121 void
1122 ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
1124 yycdebug_ = &o;
1128 ]b4_parser_class_name[::debug_level_type
1129 ]b4_parser_class_name[::debug_level () const
1131 return yydebug_;
1134 void
1135 ]b4_parser_class_name[::set_debug_level (debug_level_type l)
1137 yydebug_ = l;
1139 #endif
1142 ]b4_parser_class_name[::parse ()
1144 /// Whether yyla contains a lookahead.
1145 bool yyempty = true;
1147 /* State. */
1148 int yyn;
1149 int yylen = 0;
1150 int yystate = 0;
1152 /* Error handling. */
1153 int yynerrs_ = 0;
1154 int yyerrstatus_ = 0;
1156 /// The lookahead symbol.
1157 symbol_type yyla;]b4_locations_if([[
1159 /// The locations where the error started and ended.
1160 stack_symbol_type yyerror_range[2];]])[
1162 /// $$ and @@$.
1163 stack_symbol_type yylhs;
1165 /// The return value of parse().
1166 int yyresult;
1168 YYCDEBUG << "Starting parse" << std::endl;
1170 ]m4_ifdef([b4_initial_action], [
1171 m4_pushdef([b4_at_dollar], [yyla.location])dnl
1172 m4_pushdef([b4_dollar_dollar], [yyla.value])dnl
1173 /* User initialization code. */
1174 b4_user_initial_action
1175 m4_popdef([b4_dollar_dollar])dnl
1176 m4_popdef([b4_at_dollar])])dnl
1178 [ /* Initialize the stack. The initial state will be set in
1179 yynewstate, since the latter expects the semantical and the
1180 location values to have been already stored, initialize these
1181 stacks with a primary value. */
1182 yystack_ = stack_type (0);
1183 yypush_ (0, 0, yyla);
1185 // A new state was pushed on the stack.
1186 // Invariant: yystate == yystack_[0].state, i.e.,
1187 // yystate was just pushed onto the state stack.
1188 yynewstate:
1189 YYCDEBUG << "Entering state " << yystate << std::endl;
1191 /* Accept? */
1192 if (yystate == yyfinal_)
1193 goto yyacceptlab;
1195 goto yybackup;
1197 /* Backup. */
1198 yybackup:
1200 /* Try to take a decision without lookahead. */
1201 yyn = yypact_[yystate];
1202 if (yyn == yypact_ninf_)
1203 goto yydefault;
1205 /* Read a lookahead token. */
1206 if (yyempty)
1208 YYCDEBUG << "Reading a token: ";
1209 ]b4_lex_symbol_if(
1210 [ yyla = b4_c_function_call([yylex], [symbol_type],
1211 m4_ifdef([b4_lex_param], b4_lex_param));],
1212 [ yyla.type = yytranslate_ (b4_c_function_call([yylex], [int],
1213 [[YYSTYPE*], [&yyla.value]][]dnl
1214 b4_locations_if([, [[location*], [&yyla.location]]])dnl
1215 m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
1216 yyempty = false;
1218 YY_SYMBOL_PRINT ("Next token is", yyla);
1220 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1221 to detect an error, take that action. */
1222 yyn += yyla.type;
1223 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type)
1224 goto yydefault;
1226 /* Reduce or error. */
1227 yyn = yytable_[yyn];
1228 if (yyn <= 0)
1230 if (yyn == 0 || yyn == yytable_ninf_)
1231 goto yyerrlab;
1232 yyn = -yyn;
1233 goto yyreduce;
1236 /* Discard the token being shifted. */
1237 yyempty = true;
1239 /* Count tokens shifted since error; after three, turn off error
1240 status. */
1241 if (yyerrstatus_)
1242 --yyerrstatus_;
1244 /* Shift the lookahead token. */
1245 yystate = yyn;
1246 yypush_ ("Shifting", yystate, yyla);
1247 goto yynewstate;
1249 /*-----------------------------------------------------------.
1250 | yydefault -- do the default action for the current state. |
1251 `-----------------------------------------------------------*/
1252 yydefault:
1253 yyn = yydefact_[yystate];
1254 if (yyn == 0)
1255 goto yyerrlab;
1256 goto yyreduce;
1258 /*-----------------------------.
1259 | yyreduce -- Do a reduction. |
1260 `-----------------------------*/
1261 yyreduce:
1262 yylen = yyr2_[yyn];]b4_variant_if([
1263 /* Variants are always initialized to an empty instance of the
1264 correct type. The default $$=$1 rule is NOT applied when using
1265 variants */
1266 ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])[],[
1267 /* If YYLEN is nonzero, implement the default value of the action:
1268 `$$ = $1'. Otherwise, use the top of the stack.
1270 Otherwise, the following line sets YYLHS.VALUE to garbage.
1271 This behavior is undocumented and Bison
1272 users should not rely upon it. */
1273 if (yylen)
1274 yylhs.value = yystack_@{yylen - 1@}.value;
1275 else
1276 yylhs.value = yystack_@{0@}.value;])[
1277 ]b4_locations_if([dnl
1279 // Compute the default @@$.
1281 slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
1282 YYLLOC_DEFAULT (yylhs.location, slice, yylen);
1283 }]])[
1285 // Perform the reduction.
1286 YY_REDUCE_PRINT (yyn);
1287 switch (yyn)
1289 ]b4_user_actions[
1290 default:
1291 break;
1293 // Compute post-reduction state.
1294 yyn = yyr1_[yyn];
1295 yystate = yypgoto_[yyn - yyntokens_] + yystack_[yylen].state;
1296 if (0 <= yystate && yystate <= yylast_
1297 && yycheck_[yystate] == yystack_[yylen].state)
1298 yystate = yytable_[yystate];
1299 else
1300 yystate = yydefgoto_[yyn - yyntokens_];
1301 yylhs.state = yystate;
1302 YY_SYMBOL_PRINT ("-> $$ =", yylhs);
1303 ]b4_variant_if([[
1304 // Destroy the lhs symbols.
1305 for (int i = 0; i < yylen; ++i)
1306 // Destroy a variant which value may have be swapped with
1307 // yylhs.value. The value of yylhs.value (hence maybe one of
1308 // these lhs symbols) depends on what does the default
1309 // contruction for this type. In the case of pointers for
1310 // instance, nothing is done, so the value is junk. Therefore
1311 // do not try to report the content in the debug trace, it's
1312 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1313 // traces as with the other Bison skeletons.
1314 yy_destroy_ (0, yystack_[i]);]])[
1316 yypop_ (yylen);
1317 yylen = 0;
1318 YY_STACK_PRINT ();
1320 /* Shift the result of the reduction. */
1321 yypush_ (0, yylhs);
1322 goto yynewstate;
1324 /*------------------------------------.
1325 | yyerrlab -- here on detecting error |
1326 `------------------------------------*/
1327 yyerrlab:
1328 /* If not already recovering from an error, report this error. */
1329 if (!yyerrstatus_)
1331 ++yynerrs_;
1332 error (]b4_args(b4_locations_if([yyla.location]),
1333 [yysyntax_error_ (yystate, yyla.type)])[);
1336 ]b4_locations_if([[
1337 yyerror_range[0].location = yyla.location;]])[
1338 if (yyerrstatus_ == 3)
1340 /* If just tried and failed to reuse lookahead token after an
1341 error, discard it. */
1343 /* Return failure if at end of input. */
1344 if (yyla.type == yyeof_)
1345 YYABORT;
1346 else
1348 yy_destroy_ ("Error: discarding", yyla);
1349 yyempty = true;
1353 /* Else will try to reuse lookahead token after shifting the error
1354 token. */
1355 goto yyerrlab1;
1358 /*---------------------------------------------------.
1359 | yyerrorlab -- error raised explicitly by YYERROR. |
1360 `---------------------------------------------------*/
1361 yyerrorlab:
1363 /* Pacify compilers like GCC when the user code never invokes
1364 YYERROR and the label yyerrorlab therefore never appears in user
1365 code. */
1366 if (false)
1367 goto yyerrorlab;
1369 ]b4_locations_if([[
1370 yyerror_range[0].location = yystack_[yylen - 1].location;]])[
1371 /* Do not reclaim the symbols of the rule which action triggered
1372 this YYERROR. */
1373 yypop_ (yylen);
1374 yylen = 0;
1375 yystate = yystack_[0].state;
1376 goto yyerrlab1;
1378 /*-------------------------------------------------------------.
1379 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1380 `-------------------------------------------------------------*/
1381 yyerrlab1:
1382 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
1384 stack_symbol_type error_token;
1385 for (;;)
1387 yyn = yypact_[yystate];
1388 if (yyn != yypact_ninf_)
1390 yyn += yyterror_;
1391 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
1393 yyn = yytable_[yyn];
1394 if (0 < yyn)
1395 break;
1399 // Pop the current state because it cannot handle the error token.
1400 if (yystack_.size () == 1)
1401 YYABORT;
1402 ]b4_locations_if([[
1403 yyerror_range[0].location = yystack_[0].location;]])[
1404 yy_destroy_ ("Error: popping", yystack_[0]);
1405 yypop_ ();
1406 yystate = yystack_[0].state;
1407 YY_STACK_PRINT ();
1409 ]b4_locations_if([[
1410 yyerror_range[1].location = yyla.location;
1411 YYLLOC_DEFAULT (error_token.location, (yyerror_range - 1), 2);]])[
1413 /* Shift the error token. */
1414 error_token.state = yystate = yyn;
1415 yypush_ ("Shifting", error_token);
1417 goto yynewstate;
1419 /* Accept. */
1420 yyacceptlab:
1421 yyresult = 0;
1422 goto yyreturn;
1424 /* Abort. */
1425 yyabortlab:
1426 yyresult = 1;
1427 goto yyreturn;
1429 yyreturn:
1430 if (!yyempty)
1431 yy_destroy_ ("Cleanup: discarding lookahead", yyla);
1433 /* Do not reclaim the symbols of the rule which action triggered
1434 this YYABORT or YYACCEPT. */
1435 yypop_ (yylen);
1436 while (yystack_.size () != 1)
1438 yy_destroy_ ("Cleanup: popping", yystack_[0]);
1439 yypop_ ();
1442 return yyresult;
1445 // Generate an error message.
1446 std::string
1447 ]b4_parser_class_name[::yysyntax_error_ (]dnl
1448 b4_error_verbose_if([int yystate, int yytoken],
1449 [int, int])[)
1451 std::string yyres;]b4_error_verbose_if([[
1452 int yyn = yypact_[yystate];
1453 if (yypact_ninf_ < yyn && yyn <= yylast_)
1455 /* Start YYX at -YYN if negative to avoid negative indexes in
1456 YYCHECK. */
1457 int yyxbegin = yyn < 0 ? -yyn : 0;
1459 /* Stay within bounds of both yycheck and yytname. */
1460 int yychecklim = yylast_ - yyn + 1;
1461 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
1463 // Number of "expected" tokens.
1464 size_t yycount = 0;
1465 // Its maximum.
1466 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1467 // Arguments of yyformat.
1468 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1469 yyarg[yycount++] = yytname_[yytoken];
1470 for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
1471 if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_)
1473 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1475 yycount = 1;
1476 break;
1478 else
1479 yyarg[yycount++] = yytname_[yyx];
1482 char const* yyformat = 0;
1483 switch (yycount)
1485 #define YYCASE_(N, S) \
1486 case N: \
1487 yyformat = S; \
1488 break
1489 YYCASE_(1, YY_("syntax error, unexpected %s"));
1490 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1491 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1492 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1493 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1494 #undef YYCASE_
1496 // Argument number.
1497 size_t yyi = 0;
1498 for (char const* yyp = yyformat; *yyp; ++yyp)
1499 if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
1501 yyres += yytnamerr_ (yyarg[yyi++]);
1502 ++yyp;
1504 else
1505 yyres += *yyp;
1507 else
1508 ]])dnl
1509 [ yyres = YY_("syntax error");
1510 return yyres;
1514 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1515 STATE-NUM. */
1516 const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
1517 ]b4_table_define([pact], [b4_pact])[;
1519 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1520 doesn't specify something else to do. Zero means the default is an
1521 error. */
1522 ]b4_table_define([defact], [b4_defact])[;
1524 /* YYPGOTO[NTERM-NUM]. */
1525 ]b4_table_define([pgoto], [b4_pgoto])[;
1527 /* YYDEFGOTO[NTERM-NUM]. */
1528 ]b4_table_define([defgoto], [b4_defgoto])[;
1530 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1531 positive, shift that token. If negative, reduce the rule which
1532 number is the opposite. If zero, do what YYDEFACT says. */
1533 const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
1534 ]b4_table_define([table], [b4_table])[;
1536 /* YYCHECK. */
1537 ]b4_table_define([check], [b4_check])[;
1539 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1540 symbol of state STATE-NUM. */
1541 ]b4_table_define([stos], [b4_stos])[;
1543 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1544 ]b4_table_define([r1], [b4_r1])[;
1546 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1547 ]b4_table_define([r2], [b4_r2])[;
1549 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1550 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1551 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1552 const char*
1553 const ]b4_parser_class_name[::yytname_[] =
1555 ]b4_tname[
1557 #endif
1559 #if YYDEBUG
1560 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1561 ]b4_table_define([rline], [b4_rline])[;
1563 // Print the state stack on the debug stream.
1564 void
1565 ]b4_parser_class_name[::yystack_print_ ()
1567 *yycdebug_ << "Stack now";
1568 for (stack_type::const_iterator
1569 i = yystack_.begin (),
1570 i_end = yystack_.end ();
1571 i != i_end; ++i)
1572 *yycdebug_ << ' ' << i->state;
1573 *yycdebug_ << std::endl;
1576 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1577 void
1578 ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
1580 unsigned int yylno = yyrline_[yyrule];
1581 int yynrhs = yyr2_[yyrule];
1582 /* Print the symbols being reduced, and their result. */
1583 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1584 << " (line " << yylno << "):" << std::endl;
1585 /* The symbols being reduced. */
1586 for (int yyi = 0; yyi < yynrhs; yyi++)
1587 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
1588 ]b4_rhs_data(yynrhs, yyi + 1)[);
1590 #endif // YYDEBUG
1592 ]b4_lex_symbol_if([], [b4_yytranslate_definition])[
1593 ]b4_namespace_close[
1595 ]b4_epilogue[]dnl
1596 @output(b4_dir_prefix[]stack.hh@)@
1597 b4_copyright([Stack handling for Bison parsers in C++])[
1599 #ifndef BISON_STACK_HH
1600 # define BISON_STACK_HH
1602 #include <deque>
1604 ]b4_namespace_open[
1605 template <class T, class S = std::deque<T> >
1606 class stack
1608 public:
1610 // Hide our reversed order.
1611 typedef typename S::reverse_iterator iterator;
1612 typedef typename S::const_reverse_iterator const_iterator;
1614 stack () : seq_ ()
1618 stack (unsigned int n) : seq_ (n)
1622 inline
1624 operator [] (unsigned int i)
1626 return seq_[i];
1629 inline
1630 const T&
1631 operator [] (unsigned int i) const
1633 return seq_[i];
1636 inline
1637 void
1638 push (const T& t)
1640 seq_.push_front (t);
1643 inline
1644 void
1645 pop (unsigned int n = 1)
1647 for (; n; --n)
1648 seq_.pop_front ();
1651 inline
1652 typename S::size_type
1653 size () const
1655 return seq_.size ();
1658 inline const_iterator begin () const { return seq_.rbegin (); }
1659 inline const_iterator end () const { return seq_.rend (); }
1661 private:
1662 /// The wrapped container.
1663 S seq_;
1666 /// Present a slice of the top of a stack.
1667 template <class T, class S = stack<T> >
1668 class slice
1670 public:
1672 slice (const S& stack,
1673 unsigned int range) : stack_ (stack),
1674 range_ (range)
1678 inline
1679 const T&
1680 operator [] (unsigned int i) const
1682 return stack_[range_ - i];
1685 private:
1687 const S& stack_;
1688 unsigned int range_;
1690 ]b4_namespace_close[
1692 #endif // not BISON_STACK_HH[]dnl
1694 m4_divert_pop(0)
1695 m4_popdef([b4_copyright_years])dnl