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
])
124 # b4_symbol_action(SYMBOL-NUM, KIND)
125 # ----------------------------------
126 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
127 # Same as in C, but using references instead of pointers.
128 m4_define([b4_symbol_action
],
129 [b4_symbol_if([$
1], [has_$
2],
130 [m4_pushdef([b4_dollar_dollar
],
131 [b4_symbol_value_template([yysym
.value
],
132 b4_symbol_if([$
1], [has_type
],
133 [b4_symbol([$
1], [type
])]))])dnl
134 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
135 b4_symbol_case_([$
1])
136 b4_syncline([b4_symbol([$
1], [$
2_line
])], ["b4_symbol([$1], [$2_file])"])
137 b4_symbol([$
1], [$
2])
138 b4_syncline([@oline@
], [@ofile@
])
141 m4_popdef([b4_at_dollar
])dnl
142 m4_popdef([b4_dollar_dollar
])dnl
145 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
146 # -------------------------------------------------
147 # Declare the overloaded version of make_symbol for the (common) type of
148 # these SYMBOL-NUMBERS. Use at class-level.
149 m4_define([b4_symbol_constructor_declaration_
],
150 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
153 make_
[]b4_symbol_([$
1], [id
]) (dnl
154 b4_args(b4_symbol_if([$
1], [has_type
],
155 [const b4_symbol([$
1], [type
])& v
]),
156 b4_locations_if([const location_type
& l
])));
161 # b4_symbol_constructor_declarations
162 # ----------------------------------
163 # Declare symbol constructors for all the value types.
164 # Use at class-level.
165 m4_define([b4_symbol_constructor_declarations
],
167 // Symbol constructors declarations.
168 b4_symbol_foreach([b4_symbol_constructor_declaration_
])])])
172 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
173 # ------------------------------------------------
174 # Define symbol constructor for this SYMBOL-NUMBER.
175 m4_define([b4_symbol_constructor_definition_
],
176 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
177 [ b4_parser_class_name::symbol_type
178 b4_parser_class_name::make_
[]b4_symbol_([$
1], [id
]) (dnl
179 b4_args(b4_symbol_if([$
1], [has_type
],
180 [const b4_symbol([$
1], [type
])& v
]),
181 b4_locations_if([const location_type
& l
])))
183 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$
1], [id
]))],
184 b4_symbol_if([$
1], [has_type
], [v
]),
185 b4_locations_if([l
])));
191 # b4_symbol_constructor_definitions
192 # ----------------------------------
193 # Define the overloaded versions of make_symbol for all the value types.
194 m4_define([b4_symbol_constructor_definitions
],
195 [[ // symbol_base_type.
196 template <typename Exact
>
197 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
198 : value()]b4_locations_if([
203 template <typename Exact
>
204 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
210 template <typename Exact
>
211 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
212 [const semantic_type
& v
],
213 b4_locations_if([const location_type
& l
]))[)
214 : value(v
)]b4_locations_if([
219 template <typename Exact
>
221 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
223 return static_cast<const Exact
&>(*this);
226 template <typename Exact
>
228 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
230 return static_cast<Exact
&>(*this);
233 template <typename Exact
>
235 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
237 return self ().type_get_ ();
241 ]b4_parser_class_name
[::symbol_type::symbol_type ()
247 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
249 b4_locations_if([const location_type
& l
]))[)
250 : super_type (]b4_locations_if([l
])[)
255 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
257 [const semantic_type
& v
],
258 b4_locations_if([const location_type
& l
]))[)
259 : super_type (v
]b4_locations_if([, l
])[)
265 ]b4_parser_class_name
[::symbol_type::type_get_ () const
270 ]b4_parser_class_name
[::token_type
271 ]b4_parser_class_name
[::symbol_type::token () const
273 // YYTOKNUM[NUM] -- (External) token number corresponding to the
274 // (internal) symbol number NUM (which must be that of a token). */
276 const ]b4_int_type_for([b4_toknum
])[
281 return static_cast<token_type
> (yytoken_number_
[type
]);
286 [ // Implementation of make_symbol for each symbol type.
287 b4_symbol_foreach([b4_symbol_constructor_definition_
])])])
290 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
291 # ------------------------------------------------
292 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
294 m4_define([b4_symbol_variant
],
295 [m4_pushdef([b4_dollar_dollar
],
296 [$
2.$
3< $
][3 >(m4_shift3($@
))])dnl
299 b4_type_foreach([b4_type_action_
])[]dnl
303 m4_popdef([b4_dollar_dollar
])dnl
307 # _b4_char_sizeof_counter
308 # -----------------------
309 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
310 m4_define([_b4_char_sizeof_counter
],
313 # _b4_char_sizeof_dummy
314 # ---------------------
315 # At each call return a new C++ identifier.
316 m4_define([_b4_char_sizeof_dummy
],
317 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
318 dummy
[]_b4_char_sizeof_counter
])
321 # b4_char_sizeof_(SYMBOL-NUM)
322 # ---------------------------
323 # A comment describing this symbol.
324 m4_define([b4_char_sizeof_
],
325 [ // b4_symbol([$1], [tag])
328 # b4_char_sizeof(SYMBOL-NUMS)
329 # --------------------------
330 # To be mapped on the list of type names to produce:
332 # char dummy1[sizeof(type_name_1)];
333 # char dummy2[sizeof(type_name_2)];
335 # for defined type names.
336 m4_define([b4_char_sizeof
],
337 [b4_symbol_if([$
1], [has_type
],
339 m4_map([b4_char_sizeof_
], [$@
])dnl
340 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type
])])@
};
344 # b4_yytranslate_definition
345 # -------------------------
346 # Define yytranslate_. Sometimes we want it in the header file,
347 # sometimes the cc file suffices.
348 m4_define([b4_yytranslate_definition
],
349 [[ // Symbol number corresponding to token number t.
350 ]b4_parser_class_name
[::token_number_type
351 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
355 const token_number_type
360 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
361 const token_number_type undef_token_
= ]b4_undef_token_number
[;
363 if (static_cast<int>(t
) <= yyeof_
)
365 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
366 return translate_table
[t
];
373 m4_pushdef([b4_copyright_years
],
374 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
376 m4_define([b4_parser_class_name
],
377 [b4_percent_define_get([[parser_class_name]])])
379 # The header is mandatory.
381 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
384 [# Backward compatibility.
385 m4_define([b4_location_constructors
])
386 m4_include(b4_pkgdatadir
/[location
.cc
])])
388 # We do want M4 expansion after # for CPP macros.
391 @
output(b4_spec_defines_file@
)@
392 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
393 dnl FIXME
: This is wrong
, we want computed header guards
.
395 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
397 #ifndef PARSER_HEADER_H
398 # define PARSER_HEADER_H
400 ]b4_percent_code_get([[requires]])[
402 ]b4_assert_if([#include <cassert>])[
408 ]b4_locations_if([ class position
;
412 /// A char[S] buffer to store and retrieve objects.
414 /// Sort of a variant, but does not keep track of the nature
415 /// of the stored data, since that knowledge is available
416 /// via the current state.
420 /// Whether something is contained.
423 /// Empty construction.
425 variant ()]b4_assert_if([
429 /// Instantiate a \a T in here.
430 template <typename T
>
436 return *new (buffer
.raw
) T
;
439 /// Instantiate a \a T in here from \a t.
440 template <typename T
>
446 return *new (buffer
.raw
) T(t
);
449 /// Construct and fill.
450 template <typename T
>
452 variant (const T
& t
)]b4_assert_if([
455 new (buffer
.raw
) T(t
);
458 /// Accessor to a built \a T.
459 template <typename T
>
464 return reinterpret_cast<T
&>(buffer
.raw
);
467 /// Const accessor to a built \a T (for %printer).
468 template <typename T
>
473 return reinterpret_cast<const T
&>(buffer
.raw
);
476 /// Swap the content with \a other.
477 template <typename T
>
479 swap(variant
<S
>& other
)
481 std::swap(as
<T
>(), other
.as
<T
>());
484 /// Assign the content of \a other to this.
485 /// Destroys \a other.
486 template <typename T
>
488 build(variant
<S
>& other
)
495 /// Destroy the stored \a T.
496 template <typename T
>
500 as
<T
>().~T();]b4_assert_if([
504 /// A buffer large enough to store any of the semantic values.
505 /// Long double is chosen as it has the strongest alignment
508 long double align_me
;
515 ]b4_locations_if([#include "location.hh"])[
517 /* Enabling traces. */
519 # define YYDEBUG ]b4_debug_flag[
522 /* Enabling verbose error messages. */
523 #ifdef YYERROR_VERBOSE
524 # undef YYERROR_VERBOSE
525 # define YYERROR_VERBOSE 1
527 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
530 /* Enabling the token table. */
531 #ifndef YYTOKEN_TABLE
532 # define YYTOKEN_TABLE ]b4_token_table[
535 ]b4_locations_if([dnl
536 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
537 If N is 0, then set CURRENT to the empty location which ends
538 the previous symbol: RHS[0] (always defined). */
540 #ifndef YYLLOC_DEFAULT
541 # define YYLLOC_DEFAULT(Current, Rhs, N) \
545 (Current).begin = (Rhs)[1].location.begin; \
546 (Current).end = (Rhs)[N].location.end; \
550 (Current).begin = (Current).end = (Rhs)[0].location.end; \
558 class ]b4_parser_class_name
[
563 [ /// An auxiliary type to compute the largest semantic type.
565 {]b4_type_foreach([b4_char_sizeof
])[};
567 /// Symbol semantic values.
568 typedef variant
<sizeof(union_type
)> semantic_type
;],
569 [ /// Symbol semantic values.
571 [ union semantic_type
574 [m4_if(b4_tag_seen_flag
, 0,
575 [[ typedef int semantic_type
;]],
576 [[ typedef YYSTYPE semantic_type
;]])])])[
578 typedef YYSTYPE semantic_type
;
579 #endif]b4_locations_if([
580 /// Symbol locations.
581 typedef b4_percent_define_get([[location_type]]) location_type
;])[
585 ]b4_token_enums(b4_tokens
)[
588 typedef token::yytokentype token_type
;
590 /// Build a parser object.
591 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
592 virtual ~]b4_parser_class_name
[ ();
595 /// \returns 0 iff parsing succeeded.
596 virtual int parse ();
599 /// The current debugging stream.
600 std::ostream
& debug_stream () const;
601 /// Set the current debugging stream.
602 void set_debug_stream (std::ostream
&);
604 /// Type for debugging levels.
605 typedef int debug_level_type
;
606 /// The current debugging level.
607 debug_level_type
debug_level () const;
608 /// Set the current debugging level.
609 void set_debug_level (debug_level_type l
);
613 /// Report a syntax error.]b4_locations_if([
614 /// \param loc where the syntax error is found.])[
615 /// \param msg a description of the syntax error.
616 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
618 /// Generate an error message.
619 /// \param state the state where the error occurred.
620 /// \param tok the lookahead token.
621 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
624 typedef int state_type
;
626 /// Internal symbol numbers.
627 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
628 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
629 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
632 ]b4_parser_tables_declare
[
634 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
635 /// For a symbol, its name in clear.
636 static const char* const yytname_
[];
637 #endif]b4_error_verbose_if([
639 /// Convert the symbol name \a n to a form suitable for a diagnostic.
640 static std::string
yytnamerr_ (const char *n
);])[
643 ]b4_integral_parser_table_declare([rline
], [b4_rline
],
644 [YYRLINE
[YYN
] -- Source line where rule number YYN was defined
.])[
645 /// Report on the debug stream that the rule \a r is going to be reduced.
646 virtual void yy_reduce_print_ (int r
);
647 /// Print the state stack on the debug stream.
648 virtual void yystack_print_ ();
652 std::ostream
* yycdebug_
;
655 /// Convert a scanner token number \a t to a symbol number.
656 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
658 /// A complete symbol, with its type.
659 template <typename Exact
>
660 struct symbol_base_type
662 /// Default constructor.
663 inline symbol_base_type ();
665 /// Constructor.]b4_locations_if([
666 inline symbol_base_type (const location_type
& l
)])[;
667 inline symbol_base_type (]b4_args(
668 [const semantic_type
& v
],
669 b4_locations_if([const location_type
& l
]))[);
671 /// Return this with its exact type.
672 const Exact
& self () const;
675 /// Return the type of this symbol.
676 int type_get () const;
678 /// The semantic value.
679 semantic_type value
;]b4_locations_if([
682 location_type location
;])[
686 /// \brief Display a symbol type, value and location.
687 /// \param yyo The output stream.
688 /// \param yysym The symbol.
689 template <typename Exact
>
690 void yy_print_ (std::ostream
& yyo
,
691 const symbol_base_type
<Exact
>& yysym
) const;
694 /// \brief Reclaim the memory associated to a symbol.
695 /// \param yymsg Why this token is reclaimed.
696 /// If null, print nothing.
697 /// \param s The symbol.
698 template <typename Exact
>
699 inline void yy_destroy_ (const char* yymsg
,
700 symbol_base_type
<Exact
>& yysym
) const;
703 /// Element of the stack: a state and its attributes.
704 struct symbol_type
: symbol_base_type
<symbol_type
>
706 /// The parent class.
707 typedef symbol_base_type
<symbol_type
> super_type
;
709 /// Default constructor.
710 inline symbol_type ();
713 inline symbol_type (]b4_args([int t
],
714 [const semantic_type
& v
],
715 b4_locations_if([const location_type
& l
]))[);
717 inline symbol_type (]b4_args([int t
],
718 b4_locations_if([const location_type
& l
]))[);
723 /// Return the type corresponding to this state.
724 inline int type_get_ () const;
727 inline token_type
token () const;
730 ]b4_symbol_constructor_declarations
[
733 /// Element of the stack: a state and its attributes.
734 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
736 /// The parent class.
737 typedef symbol_base_type
<stack_symbol_type
> super_type
;
739 /// Default constructor.
740 inline stack_symbol_type ();
743 inline stack_symbol_type (]b4_args([state_type s
],
744 [const semantic_type
& v
],
745 b4_locations_if([const location_type
& l
]))[);
750 /// Return the type corresponding to this state.
751 inline int type_get_ () const;
755 typedef stack
<stack_symbol_type
> stack_type
;
760 /// Push a new state on the stack.
761 /// \param m a debug message to display
762 /// if null, no trace is output.
763 /// \param s the symbol
764 /// \warning the contents of \a s.value is stolen.
765 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
767 /// Push a new look ahead token on the state on the stack.
768 /// \param m a debug message to display
769 /// if null, no trace is output.
770 /// \param s the state
771 /// \param sym the symbol (for its value and location).
772 /// \warning the contents of \a s.value is stolen.
773 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
775 /// Pop \a n symbols the three stacks.
776 inline void yypop_ (unsigned int n
= 1);
782 yylast_
= ]b4_last
[, //< Last index in yytable_.
783 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
785 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
788 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
791 ]b4_parse_param_vars
[
794 ]b4_lex_symbol_if([b4_yytranslate_definition
])[
795 ]b4_lex_symbol_if([b4_symbol_constructor_definitions
])[
798 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
799 [b4_token_defines(b4_tokens
)
802 /* Redirection for backward compatibility. */
803 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
806 b4_percent_code_get([[provides]])[]dnl
808 [#endif /* ! defined PARSER_HEADER_H */]
809 @
output(b4_parser_file_name@
)@
810 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
811 b4_percent_code_get([[top]])[]dnl
812 m4_if(b4_prefix
, [yy
], [],
814 // Take the name prefix into account.
815 #define yylex b4_prefix[]lex])[
817 /* First part of user declarations. */
818 ]b4_user_pre_prologue
[
820 #include "@basename(]b4_spec_defines_file[@)"
822 /* User implementation prologue. */
823 ]b4_user_post_prologue
824 b4_percent_code_get
[]dnl
829 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
830 # define YY_(msgid) dgettext ("bison-runtime", msgid)
834 # define YY_(msgid) msgid
838 /* Suppress unused-variable warnings by "using" E. */
839 #define YYUSE(e) ((void) (e))
841 /* Enable debugging if requested. */
844 /* A pseudo ostream that takes yydebug_ into account. */
845 # define YYCDEBUG if (yydebug_) (*yycdebug_)
847 # define YY_SYMBOL_PRINT(Title, Symbol) \
851 *yycdebug_ << Title << ' '; \
852 yy_print_ (*yycdebug_, Symbol); \
853 *yycdebug_ << std::endl; \
857 # define YY_REDUCE_PRINT(Rule) \
860 yy_reduce_print_ (Rule); \
863 # define YY_STACK_PRINT() \
871 # define YYCDEBUG if (false) std::cerr
872 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
873 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
874 # define YY_STACK_PRINT() static_cast<void>(0)
876 #endif /* !YYDEBUG */
878 #define yyerrok (yyerrstatus_ = 0)
879 #define yyclearin (yyempty = true)
881 #define YYACCEPT goto yyacceptlab
882 #define YYABORT goto yyabortlab
883 #define YYERROR goto yyerrorlab
884 #define YYRECOVERING() (!!yyerrstatus_)
886 ]b4_namespace_open
[]b4_error_verbose_if([[
888 /* Return YYSTR after stripping away unnecessary quotes and
889 backslashes, so that it's suitable for yyerror. The heuristic is
890 that double-quoting is unnecessary unless the string contains an
891 apostrophe, a comma, or backslash (other than backslash-backslash).
892 YYSTR is taken from yytname. */
894 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
898 std::string yyr
= "";
899 char const *yyp
= yystr
;
906 goto do_not_strip_quotes
;
910 goto do_not_strip_quotes
;
919 do_not_strip_quotes
: ;
926 /// Build a parser object.
927 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
930 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
931 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
932 #endif]b4_parse_param_cons[
936 ]b4_parser_class_name::~b4_parser_class_name
[ ()
945 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions
])[
947 // stack_symbol_type.
948 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
954 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
956 [const semantic_type
& v
],
957 b4_locations_if([const location_type
& l
]))[)
958 : super_type (v
]b4_locations_if([, l
])[)
964 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
966 return yystos_
[state
];
970 template <typename Exact
>
972 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
973 symbol_base_type
<Exact
>& yysym
) const
975 int yytype
= yysym
.type_get ();
978 YY_SYMBOL_PRINT (yymsg
, yysym
);
983 ]b4_symbol_foreach([b4_symbol_destructor
])dnl
989 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
993 template <typename Exact
>
995 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
996 const symbol_base_type
<Exact
>& yysym
) const
998 int yytype
= yysym
.type_get ();
999 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1000 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1001 << yysym
.location
<< ": "])[;
1004 ]b4_symbol_foreach([b4_symbol_printer
])dnl
1013 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1017 YY_SYMBOL_PRINT (m
, sym
);
1019 [[ yystack_
.push (stack_symbol_type (]b4_args(
1022 b4_locations_if([sym
.location
]))[));
1023 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1024 [build
], [sym
.value
])],
1025 [[ yystack_
.push (stack_symbol_type (]b4_args(
1028 b4_locations_if([sym
.location
]))[));]])[
1032 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1035 YY_SYMBOL_PRINT (m
, s
);
1037 [[ yystack_
.push (stack_symbol_type (]b4_args(
1040 b4_locations_if([s
.location
]))[));
1041 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1042 [build
], [s
.value
])],
1043 [ yystack_
.push (s
);])[
1047 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1054 ]b4_parser_class_name
[::debug_stream () const
1060 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1066 ]b4_parser_class_name
[::debug_level_type
1067 ]b4_parser_class_name
[::debug_level () const
1073 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1080 ]b4_parser_class_name
[::parse ()
1082 /// Whether yyla contains a lookahead.
1083 bool yyempty
= true;
1090 /* Error handling. */
1092 int yyerrstatus_
= 0;
1094 /// The lookahead symbol.
1095 symbol_type yyla
;]b4_locations_if([[
1097 /// The locations where the error started and ended.
1098 stack_symbol_type yyerror_range
[2];]])[
1101 stack_symbol_type yylhs
;
1103 /// The return value of parse().
1106 YYCDEBUG
<< "Starting parse" << std::endl
;
1108 ]m4_ifdef([b4_initial_action
], [
1109 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1110 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1111 /* User initialization code. */
1112 b4_user_initial_action
1113 m4_popdef([b4_dollar_dollar
])dnl
1114 m4_popdef([b4_at_dollar
])])dnl
1116 [ /* Initialize the stack. The initial state will be set in
1117 yynewstate, since the latter expects the semantical and the
1118 location values to have been already stored, initialize these
1119 stacks with a primary value. */
1120 yystack_
= stack_type (0);
1121 yypush_ (0, 0, yyla
);
1123 // A new state was pushed on the stack.
1124 // Invariant: yystate == yystack_[0].state, i.e.,
1125 // yystate was just pushed onto the state stack.
1127 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1130 if (yystate
== yyfinal_
)
1138 /* Try to take a decision without lookahead. */
1139 yyn
= yypact_
[yystate
];
1140 if (yyn
== yypact_ninf_
)
1143 /* Read a lookahead token. */
1146 YYCDEBUG
<< "Reading a token: ";
1148 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1149 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1150 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1151 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1152 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1153 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1156 YY_SYMBOL_PRINT ("Next token is", yyla
);
1158 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1159 to detect an error, take that action. */
1161 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1164 /* Reduce or error. */
1165 yyn
= yytable_
[yyn
];
1168 if (yyn
== 0 || yyn
== yytable_ninf_
)
1174 /* Discard the token being shifted. */
1177 /* Count tokens shifted since error; after three, turn off error
1182 /* Shift the lookahead token. */
1184 yypush_ ("Shifting", yystate
, yyla
);
1187 /*-----------------------------------------------------------.
1188 | yydefault -- do the default action for the current state. |
1189 `-----------------------------------------------------------*/
1191 yyn
= yydefact_
[yystate
];
1196 /*-----------------------------.
1197 | yyreduce -- Do a reduction. |
1198 `-----------------------------*/
1200 yylen
= yyr2_
[yyn
];]b4_variant_if([
1201 /* Variants are always initialized to an empty instance of the
1202 correct type. The default $$=$1 rule is NOT applied when using
1204 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1205 /* If YYLEN is nonzero, implement the default value of the action:
1206 `$$ = $1'. Otherwise, use the top of the stack.
1208 Otherwise, the following line sets YYLHS.VALUE to garbage.
1209 This behavior is undocumented and Bison
1210 users should not rely upon it. */
1212 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1214 yylhs
.value
= yystack_@
{0@
}.value
;])[
1215 ]b4_locations_if([dnl
1217 // Compute the default @@$.
1219 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1220 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1223 // Perform the reduction.
1224 YY_REDUCE_PRINT (yyn
);
1231 // Compute post-reduction state.
1233 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1234 if (0 <= yystate
&& yystate
<= yylast_
1235 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1236 yystate
= yytable_
[yystate
];
1238 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1239 yylhs
.state
= yystate
;
1240 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1242 // Destroy the lhs symbols.
1243 for (int i
= 0; i
< yylen
; ++i
)
1244 // Destroy a variant which value may have be swapped with
1245 // yylhs.value. The value of yylhs.value (hence maybe one of
1246 // these lhs symbols) depends on what does the default
1247 // contruction for this type. In the case of pointers for
1248 // instance, nothing is done, so the value is junk. Therefore
1249 // do not try to report the content in the debug trace, it's
1250 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1251 // traces as with the other Bison skeletons.
1252 yy_destroy_ (0, yystack_
[i
]);]])[
1258 /* Shift the result of the reduction. */
1262 /*------------------------------------.
1263 | yyerrlab -- here on detecting error |
1264 `------------------------------------*/
1266 /* If not already recovering from an error, report this error. */
1270 error (]b4_args(b4_locations_if([yyla
.location
]),
1271 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1275 yyerror_range
[0].location
= yyla
.location
;]])[
1276 if (yyerrstatus_
== 3)
1278 /* If just tried and failed to reuse lookahead token after an
1279 error, discard it. */
1281 /* Return failure if at end of input. */
1282 if (yyla
.type
== yyeof_
)
1286 yy_destroy_ ("Error: discarding", yyla
);
1291 /* Else will try to reuse lookahead token after shifting the error
1296 /*---------------------------------------------------.
1297 | yyerrorlab -- error raised explicitly by YYERROR. |
1298 `---------------------------------------------------*/
1301 /* Pacify compilers like GCC when the user code never invokes
1302 YYERROR and the label yyerrorlab therefore never appears in user
1308 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1309 /* Do not reclaim the symbols of the rule which action triggered
1313 yystate
= yystack_
[0].state
;
1316 /*-------------------------------------------------------------.
1317 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1318 `-------------------------------------------------------------*/
1320 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1322 stack_symbol_type error_token
;
1325 yyn
= yypact_
[yystate
];
1326 if (yyn
!= yypact_ninf_
)
1329 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1331 yyn
= yytable_
[yyn
];
1337 // Pop the current state because it cannot handle the error token.
1338 if (yystack_
.size () == 1)
1341 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1342 yy_destroy_ ("Error: popping", yystack_
[0]);
1344 yystate
= yystack_
[0].state
;
1348 yyerror_range
[1].location
= yyla
.location
;
1349 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1351 /* Shift the error token. */
1352 error_token
.state
= yystate
= yyn
;
1353 yypush_ ("Shifting", error_token
);
1369 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1371 /* Do not reclaim the symbols of the rule which action triggered
1372 this YYABORT or YYACCEPT. */
1374 while (yystack_
.size () != 1)
1376 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1383 // Generate an error message.
1385 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1386 b4_error_verbose_if([int yystate
, int yytoken
],
1389 std::string yyres
;]b4_error_verbose_if([[
1390 int yyn
= yypact_
[yystate
];
1391 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1393 /* Start YYX at -YYN if negative to avoid negative indexes in
1395 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1397 /* Stay within bounds of both yycheck and yytname. */
1398 int yychecklim
= yylast_
- yyn
+ 1;
1399 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1401 // Number of reported tokens (one for the "unexpected", one per
1405 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1406 // Arguments of yyformat.
1407 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1408 yyarg
[yycount
++] = yytname_
[yytoken
];
1409 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1410 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1412 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1418 yyarg
[yycount
++] = yytname_
[yyx
];
1421 char const* yyformat
= 0;
1424 #define YYCASE_(N, S) \
1428 YYCASE_(1, YY_("syntax error, unexpected %s"));
1429 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1430 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1431 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1432 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1437 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1438 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1440 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1448 [ yyres
= YY_("syntax error");
1453 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1455 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1457 ]b4_parser_tables_define
[
1459 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1460 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1461 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1463 const ]b4_parser_class_name
[::yytname_
[] =
1470 ]b4_integral_parser_table_define([rline
], [b4_rline
])[
1472 // Print the state stack on the debug stream.
1474 ]b4_parser_class_name
[::yystack_print_ ()
1476 *yycdebug_
<< "Stack now";
1477 for (stack_type::const_iterator
1478 i
= yystack_
.begin (),
1479 i_end
= yystack_
.end ();
1481 *yycdebug_
<< ' ' << i
->state
;
1482 *yycdebug_
<< std::endl
;
1485 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1487 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1489 unsigned int yylno
= yyrline_
[yyrule
];
1490 int yynrhs
= yyr2_
[yyrule
];
1491 /* Print the symbols being reduced, and their result. */
1492 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1493 << " (line " << yylno
<< "):" << std::endl
;
1494 /* The symbols being reduced. */
1495 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1496 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1497 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1501 ]b4_lex_symbol_if([], [b4_yytranslate_definition
])[
1502 ]b4_namespace_close
[
1505 @
output(b4_dir_prefix
[]stack
.hh@
)@
1506 b4_copyright([Stack handling
for Bison parsers in C
++])[
1508 #ifndef BISON_STACK_HH
1509 # define BISON_STACK_HH
1514 template <class T
, class S
= std::deque
<T
> >
1519 // Hide our reversed order.
1520 typedef typename
S::reverse_iterator iterator
;
1521 typedef typename
S::const_reverse_iterator const_iterator
;
1527 stack (unsigned int n
) : seq_ (n
)
1533 operator [] (unsigned int i
)
1540 operator [] (unsigned int i
) const
1549 seq_
.push_front (t
);
1554 pop (unsigned int n
= 1)
1561 typename
S::size_type
1564 return seq_
.size ();
1567 inline const_iterator
begin () const { return seq_
.rbegin (); }
1568 inline const_iterator
end () const { return seq_
.rend (); }
1571 /// The wrapped container.
1575 /// Present a slice of the top of a stack.
1576 template <class T
, class S
= stack
<T
> >
1581 slice (const S
& stack
,
1582 unsigned int range
) : stack_ (stack
),
1589 operator [] (unsigned int i
) const
1591 return stack_
[range_
- i
];
1597 unsigned int range_
;
1599 ]b4_namespace_close
[
1601 #endif // not BISON_STACK_HH[]dnl
1604 m4_popdef([b4_copyright_years
])dnl