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
])
21 # b4_table_define(TABLE-NAME, CONTENT)
22 # ------------------------------------
23 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
24 m4_define([b4_table_define
],
25 [const b4_int_type_for([$
2])
26 b4_parser_class_name::yy$
1_
[[]] =
32 # b4_symbol_value_template(VAL, [TYPE])
33 # -------------------------------------
34 # Same as b4_symbol_value, but used in a template method.
35 m4_copy([b4_symbol_value
], [b4_symbol_value_template
])
37 # How the semantic value is extracted when using variants.
39 # b4_symbol_value(VAL, [TYPE])
40 # ----------------------------
41 m4_define([b4_symbol_value
],
46 # b4_symbol_value_template(VAL, [TYPE])
47 # -------------------------------------
48 # Same as b4_symbol_value, but used in a template method.
49 m4_define([b4_symbol_value_template
],
51 [$
1.template as
<$
2>()],
56 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
57 # ----------------------------------------------------------------
58 m4_define([b4_lex_symbol_if
],
59 [b4_percent_define_ifdef([[lex_symbol]], [$
1], [$
2])])
62 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
63 # ------------------------------------------------
64 m4_define([b4_assert_if
],
65 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
68 # b4_lhs_value([TYPE])
69 # --------------------
70 # Expansion of $<TYPE>$.
71 m4_define([b4_lhs_value
],
72 [b4_symbol_value([yylhs
.value
], [$
1])])
78 m4_define([b4_lhs_location
],
82 # b4_rhs_data(RULE-LENGTH, NUM)
83 # -----------------------------
84 # Return the data corresponding to the symbol #NUM, where the current
85 # rule has RULE-LENGTH symbols on RHS.
86 m4_define([b4_rhs_data
],
87 [yystack_@
{($
1) - ($
2)@
}])
90 # b4_rhs_state(RULE-LENGTH, NUM)
91 # -----------------------------
92 # The state corresponding to the symbol #NUM, where the current
93 # rule has RULE-LENGTH symbols on RHS.
94 m4_define([b4_rhs_state
],
95 [b4_rhs_data([$
1], [$
2]).state
])
98 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
99 # --------------------------------------
100 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
102 m4_define([b4_rhs_value
],
103 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
106 # b4_rhs_location(RULE-LENGTH, NUM)
107 # ---------------------------------
108 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
110 m4_define([b4_rhs_location
],
111 [b4_rhs_data([$
1], [$
2]).location
])
114 # b4_symbol(NUM, FIELD)
115 # ---------------------
116 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
118 m4_define([b4_symbol
],
119 [m4_indir([b4_symbol($
1, $
2)])])
122 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
123 # -------------------------------------------
124 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
125 # Otherwise an error.
126 m4_define([b4_symbol_if
],
127 [m4_case(b4_symbol([$
1], [$
2]),
130 [m4_fatal([$
0: field $
2 of $
1 is
not a Boolean
:] b4_symbol([$
1], [$
2]))])])
133 # b4_symbol_actions(FILENAME, LINENO,
134 # SYMBOL-TAG, SYMBOL-NUM,
135 # SYMBOL-ACTION, SYMBOL-TYPENAME)
136 # -------------------------------------------------
137 # Same as in C, but using references instead of pointers.
138 m4_define([b4_symbol_actions
],
139 [m4_pushdef([b4_dollar_dollar
],
140 [b4_symbol_value_template([yysym
.value
], [$
6])])dnl
141 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
143 b4_syncline([$
2], [$
1])
145 b4_syncline([@oline@
], [@ofile@
])
147 m4_popdef([b4_at_dollar
])dnl
148 m4_popdef([b4_dollar_dollar
])dnl
152 # b4_symbol_case_(SYMBOL-NUM)
153 # ---------------------------
154 # Issue a "case NUM" for SYMBOL-NUM.
155 m4_define([b4_symbol_case_
],
156 [ case b4_symbol([$
1], [number
]): // b4_symbol([$1], [tag])
160 # b4_type_action_(NUMS)
161 # ---------------------
162 # Run actions for the symbol NUMS that all have the same type-name.
163 # Skip NUMS that have no type-name.
164 m4_define([b4_type_action_
],
165 [b4_symbol_if([$
1], [has_type_name
],
166 [m4_map([b4_symbol_case_
], [$@
])[]dnl
167 b4_dollar_dollar([b4_symbol([$
1], [number
])],
168 [b4_symbol([$
1], [tag
])],
169 [b4_symbol([$
1], [type_name
])]);
175 # b4_symbol_constructor_declaration_(SYMBOL-NUMBERS)
176 # ----------------------------------------------------
177 # Declare the overloaded version of make_symbol for the (common) type of
178 # these SYMBOL-NUMBERS. Use at class-level.
179 m4_define([b4_symbol_constructor_declaration_
],
180 [ template <token_type
>
181 static inline symbol_type
182 make_symbol (b4_symbol_if([$
1], [has_type_name
],
183 [const b4_symbol([$
1], [type_name
])& v
, ])dnl
184 const location_type
& l
);
188 # b4_symbol_constructor_declarations
189 # ----------------------------------
190 # Declare the overloaded versions of make_symbol for all the value types.
191 # Use at class-level.
192 m4_define([b4_symbol_constructor_declarations
],
194 // Declaration of make_symbol for each value type.
195 m4_map([b4_symbol_constructor_declaration_
], m4_defn([b4_type_names
]))])])
199 # b4_symbol_constructor_specialization_(SYMBOL-NUMBER)
200 # ----------------------------------------------------
201 # Declare the specialization of make_symbol for this each SYMBOL-NUMBER.
202 # Specializations cannot be declared at class-level, this must be done
203 # at namespace-level.
204 m4_define([b4_symbol_constructor_specialization_
],
205 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [tag_is_id
],
208 b4_parser_class_name::symbol_type
209 b4_parser_class_name::make_symbol
<b4_parser_class_name::token::b4_symbol([$
1], [tag
])> (dnl
210 b4_symbol_if([$
1], [has_type_name
],
211 [const b4_symbol([$
1], [type_name
])& v
, ])dnl
212 const b4_parser_class_name::location_type
& l
);
215 # b4_symbol_constructor_specializations
216 # -------------------------------------
217 # Declare specializations of make_symbol.
218 m4_define([b4_symbol_constructor_specializations
],
220 // Specializations of make_symbol for each symbol type.
221 m4_map([b4_symbol_constructor_specialization_
],
222 m4_defn([b4_symbol_numbers
]))])dnl
227 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
228 # ------------------------------------------------
229 # Define make_symbol for this SYMBOL-NUMBER.
230 m4_define([b4_symbol_constructor_definition_
],
231 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [tag_is_id
],
233 b4_parser_class_name::symbol_type
234 b4_parser_class_name::make_symbol
<b4_parser_class_name::token::b4_symbol([$
1], [tag
])> (dnl
235 b4_symbol_if([$
1], [has_type_name
],
236 [const b4_symbol([$
1], [type_name
])& v
, ])dnl
237 const location_type
& l
)
239 return symbol_type (yytranslate_ (token::b4_symbol([$
1], [tag
])),dnl
240 b4_symbol_if([$
1], [has_type_name
], [v
, ])l
);
246 # b4_symbol_constructor_declarations
247 # ----------------------------------
248 # Define the overloaded versions of make_symbol for all the value types.
249 m4_define([b4_symbol_constructor_definitions
],
251 [ // Implementation of make_symbol for each symbol type.
252 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
255 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
256 # ------------------------------------------------
257 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
259 m4_define([b4_symbol_variant
],
260 [m4_pushdef([b4_dollar_dollar
],
261 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
264 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
268 m4_popdef([b4_dollar_dollar
])dnl
272 # _b4_char_sizeof_counter
273 # -----------------------
274 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
275 m4_define([_b4_char_sizeof_counter
],
278 # _b4_char_sizeof_dummy
279 # ---------------------
280 # At each call return a new C++ identifier.
281 m4_define([_b4_char_sizeof_dummy
],
282 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
283 dummy
[]_b4_char_sizeof_counter
])
286 # b4_char_sizeof(SYMBOL-NUM)
287 # --------------------------
288 # To be mapped on the list of type names to produce:
290 # char dummy1[sizeof(type_name_1)];
291 # char dummy2[sizeof(type_name_2)];
293 # for defined type names.
294 # $3 is doubly-quoted, do not quote it again.
295 m4_define([b4_char_sizeof
],
296 [m4_ifval(b4_symbol([$
1], [type_name
]),
298 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type_name
])])@
}; // b4_symbol([$1], [tag])])dnl
302 m4_pushdef([b4_copyright_years
],
303 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
305 m4_define([b4_parser_class_name
],
306 [b4_percent_define_get([[parser_class_name]])])
308 # The header is mandatory.
310 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
312 # Backward compatibility.
313 m4_define([b4_location_constructors
])
314 m4_include(b4_pkgdatadir
/[location
.cc
])
316 # We do want M4 expansion after # for CPP macros.
320 [@
output(b4_spec_defines_file@
)@
321 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
322 dnl FIXME
: This is wrong
, we want computed header guards
.
324 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
326 #ifndef PARSER_HEADER_H
327 # define PARSER_HEADER_H
329 ]b4_percent_code_get([[requires]])[
331 ]b4_assert_if([#include <cassert>])[
341 /// A char[S] buffer to store and retrieve objects.
343 /// Sort of a variant, but does not keep track of the nature
344 /// of the stored data, since that knowledge is available
345 /// via the current state.
349 /// Whether something is contained.
352 /// Empty construction.
354 variant ()]b4_assert_if([
358 /// Instantiate a \a T in here.
359 template <typename T
>
365 return *new (buffer
) T
;
368 /// Instantiate a \a T in here from \a t.
369 template <typename T
>
375 return *new (buffer
) T(t
);
378 /// Construct and fill.
379 template <typename T
>
381 variant (const T
& t
)]b4_assert_if([
387 /// Accessor to a built \a T.
388 template <typename T
>
393 return reinterpret_cast<T
&>(buffer
);
396 /// Const accessor to a built \a T (for %printer).
397 template <typename T
>
402 return reinterpret_cast<const T
&>(buffer
);
405 /// Swap the content with \a other.
406 template <typename T
>
408 swap(variant
<S
>& other
)
410 std::swap(as
<T
>(), other
.as
<T
>());
413 /// Assign the content of \a other to this.
414 /// Destroys \a other.
415 template <typename T
>
417 build(variant
<S
>& other
)
424 /// Destroy the stored \a T.
425 template <typename T
>
429 as
<T
>().~T();]b4_assert_if([
433 /// A buffer large enough to store any of the semantic values.
439 #include "location.hh"
441 /* Enabling traces. */
443 # define YYDEBUG ]b4_debug_flag[
446 /* Enabling verbose error messages. */
447 #ifdef YYERROR_VERBOSE
448 # undef YYERROR_VERBOSE
449 # define YYERROR_VERBOSE 1
451 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
454 /* Enabling the token table. */
455 #ifndef YYTOKEN_TABLE
456 # define YYTOKEN_TABLE ]b4_token_table[
459 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
460 If N is 0, then set CURRENT to the empty location which ends
461 the previous symbol: RHS[0] (always defined). */
463 #ifndef YYLLOC_DEFAULT
464 # define YYLLOC_DEFAULT(Current, Rhs, N) \
468 (Current).begin = (Rhs)[1].location.begin; \
469 (Current).end = (Rhs)[N].location.end; \
473 (Current).begin = (Current).end = (Rhs)[0].location.end; \
481 class ]b4_parser_class_name
[
486 [ /// An auxiliary type to compute the largest semantic type.
488 {]m4_map([b4_char_sizeof
], m4_defn([b4_symbol_numbers
]))[
491 /// Symbol semantic values.
492 typedef variant
<sizeof(union_type
)> semantic_type
;],
493 [ /// Symbol semantic values.
495 [ union semantic_type
498 [m4_if(b4_tag_seen_flag
, 0,
499 [[ typedef int semantic_type
;]],
500 [[ typedef YYSTYPE semantic_type
;]])])])[
502 typedef YYSTYPE semantic_type
;
504 /// Symbol locations.
505 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
509 ]b4_token_enums(b4_tokens
)[
512 typedef token::yytokentype token_type
;
514 /// Build a parser object.
515 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
516 virtual ~]b4_parser_class_name
[ ();
519 /// \returns 0 iff parsing succeeded.
520 virtual int parse ();
523 /// The current debugging stream.
524 std::ostream
& debug_stream () const;
525 /// Set the current debugging stream.
526 void set_debug_stream (std::ostream
&);
528 /// Type for debugging levels.
529 typedef int debug_level_type
;
530 /// The current debugging level.
531 debug_level_type
debug_level () const;
532 /// Set the current debugging level.
533 void set_debug_level (debug_level_type l
);
537 /// Report a syntax error.
538 /// \param loc where the syntax error is found.
539 /// \param msg a description of the syntax error.
540 virtual void error (const location_type
& loc
, const std::string
& msg
);
542 /// Generate an error message.
543 /// \param state the state where the error occurred.
544 /// \param tok the lookahead token.
545 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
548 typedef int state_type
;
550 /// Internal symbol numbers.
551 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
553 /// For a state, the index in \a yytable_ of its portion.
554 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
555 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
557 /// For a state, default rule to reduce.
558 /// Unless\a yytable_ specifies something else to do.
559 /// Zero means the default is an error.
560 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
562 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
563 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
565 /// What to do in a state.
566 /// \a yytable_[yypact_[s]]: what to do in state \a s.
567 /// - if positive, shift that token.
568 /// - if negative, reduce the rule which number is the opposite.
569 /// - if zero, do what YYDEFACT says.
570 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
571 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
573 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
575 /// For a state, its accessing symbol.
576 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
578 /// For a rule, its LHS.
579 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
580 /// For a rule, its RHS length.
581 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
583 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
584 /// For a symbol, its name in clear.
585 static const char* const yytname_
[];
586 #endif]b4_error_verbose_if([
588 /// Convert the symbol name \a n to a form suitable for a diagnostic.
589 static std::string
yytnamerr_ (const char *n
);])[
592 /// For each rule, its source line number.
593 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
594 /// For each scanner token number, its symbol number.
595 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
596 /// Report on the debug stream that the rule \a r is going to be reduced.
597 virtual void yy_reduce_print_ (int r
);
598 /// Print the state stack on the debug stream.
599 virtual void yystack_print_ ();
603 std::ostream
* yycdebug_
;
606 /// Convert a scanner token number \a t to a symbol number.
607 static inline token_number_type
yytranslate_ (int t
);
609 /// A complete symbol, with its type.
610 template <typename Exact
>
611 struct symbol_base_type
613 /// Default constructor.
614 inline symbol_base_type ();
617 inline symbol_base_type (const location_type
& l
);
618 inline symbol_base_type (const semantic_type
& v
, const location_type
& l
);
620 /// Return this with its exact type.
621 const Exact
& self () const;
624 /// Return the type of this symbol.
625 int type_get () const;
627 /// The semantic value.
631 location_type location
;
635 /// \brief Display a symbol type, value and location.
636 /// \param yyo The output stream.
637 /// \param yysym The symbol.
638 template <typename Exact
>
639 void yy_print_ (std::ostream
& yyo
,
640 const symbol_base_type
<Exact
>& yysym
) const;
643 /// \brief Reclaim the memory associated to a symbol.
644 /// \param yymsg Why this token is reclaimed.
645 /// If null, print nothing.
646 /// \param s The symbol.
647 template <typename Exact
>
648 inline void yy_destroy_ (const char* yymsg
,
649 symbol_base_type
<Exact
>& yysym
) const;
652 /// Element of the stack: a state and its attributes.
653 struct symbol_type
: symbol_base_type
<symbol_type
>
655 /// The parent class.
656 typedef symbol_base_type
<symbol_type
> super_type
;
658 /// Default constructor.
659 inline symbol_type ();
662 inline symbol_type (int t
,
663 const semantic_type
& v
, const location_type
& l
);
665 inline symbol_type (int t
,
666 const location_type
& l
);
671 /// Return the type corresponding to this state.
672 inline int type_get_ () const;
675 ]b4_symbol_constructor_declarations
[
678 /// Element of the stack: a state and its attributes.
679 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
681 /// The parent class.
682 typedef symbol_base_type
<stack_symbol_type
> super_type
;
684 /// Default constructor.
685 inline stack_symbol_type ();
688 inline stack_symbol_type (state_type s
,
689 const semantic_type
& v
, const location_type
& l
);
694 /// Return the type corresponding to this state.
695 inline int type_get_ () const;
699 typedef stack
<stack_symbol_type
> stack_type
;
704 /// Push a new state on the stack.
705 /// \param m a debug message to display
706 /// if null, no trace is output.
707 /// \param s the symbol
708 /// \warning the contents of \a s.value is stolen.
709 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
711 /// Push a new look ahead token on the state on the stack.
712 /// \param m a debug message to display
713 /// if null, no trace is output.
714 /// \param s the state
715 /// \param sym the symbol (for its value and location).
716 /// \warning the contents of \a s.value is stolen.
717 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
719 /// Pop \a n symbols the three stacks.
720 inline void yypop_ (unsigned int n
= 1);
726 yylast_
= ]b4_last
[, //< Last index in yytable_.
727 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
729 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
732 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
735 ]b4_parse_param_vars
[
737 ]b4_symbol_constructor_specializations
[
740 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
741 [b4_token_defines(b4_tokens
)
744 /* Redirection for backward compatibility. */
745 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
748 b4_percent_code_get([[provides]])[]dnl
750 [#endif /* ! defined PARSER_HEADER_H */]
752 @
output(b4_parser_file_name@
)@
753 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
754 b4_percent_code_get([[top]])[]dnl
755 m4_if(b4_prefix
, [yy
], [],
757 // Take the name prefix into account.
758 #define yylex b4_prefix[]lex])[
760 /* First part of user declarations. */
761 ]b4_user_pre_prologue
764 #include "@basename(]b4_spec_defines_file[@)"]])[
766 /* User implementation prologue. */
767 ]b4_user_post_prologue
768 b4_percent_code_get
[]dnl
773 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
774 # define YY_(msgid) dgettext ("bison-runtime", msgid)
778 # define YY_(msgid) msgid
782 /* Suppress unused-variable warnings by "using" E. */
783 #define YYUSE(e) ((void) (e))
785 /* Enable debugging if requested. */
788 /* A pseudo ostream that takes yydebug_ into account. */
789 # define YYCDEBUG if (yydebug_) (*yycdebug_)
791 # define YY_SYMBOL_PRINT(Title, Symbol) \
795 *yycdebug_ << Title << ' '; \
796 yy_print_ (*yycdebug_, Symbol); \
797 *yycdebug_ << std::endl; \
801 # define YY_REDUCE_PRINT(Rule) \
804 yy_reduce_print_ (Rule); \
807 # define YY_STACK_PRINT() \
815 # define YYCDEBUG if (false) std::cerr
816 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
817 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
818 # define YY_STACK_PRINT() static_cast<void>(0)
820 #endif /* !YYDEBUG */
822 #define yyerrok (yyerrstatus_ = 0)
823 #define yyclearin (yyempty = true)
825 #define YYACCEPT goto yyacceptlab
826 #define YYABORT goto yyabortlab
827 #define YYERROR goto yyerrorlab
828 #define YYRECOVERING() (!!yyerrstatus_)
830 ]b4_namespace_open
[]b4_error_verbose_if([[
832 /* Return YYSTR after stripping away unnecessary quotes and
833 backslashes, so that it's suitable for yyerror. The heuristic is
834 that double-quoting is unnecessary unless the string contains an
835 apostrophe, a comma, or backslash (other than backslash-backslash).
836 YYSTR is taken from yytname. */
838 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
842 std::string yyr
= "";
843 char const *yyp
= yystr
;
850 goto do_not_strip_quotes
;
854 goto do_not_strip_quotes
;
863 do_not_strip_quotes
: ;
870 /// Build a parser object.
871 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
874 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
875 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
876 #endif]b4_parse_param_cons[
880 ]b4_parser_class_name::~b4_parser_class_name
[ ()
890 template <typename Exact
>
891 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
897 template <typename Exact
>
898 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
904 template <typename Exact
>
905 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const semantic_type
& v
, const location_type
& l
)
911 template <typename Exact
>
913 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
915 return static_cast<const Exact
&>(*this);
918 template <typename Exact
>
920 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
922 return static_cast<Exact
&>(*this);
925 template <typename Exact
>
927 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
929 return self ().type_get_ ();
933 ]b4_parser_class_name
[::symbol_type::symbol_type ()
939 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
940 const location_type
& l
)
946 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
947 const semantic_type
& v
, const location_type
& l
)
954 ]b4_parser_class_name
[::symbol_type::type_get_ () const
959 ]b4_symbol_constructor_definitions
[
961 // stack_symbol_type.
962 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
968 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (state_type s
,
969 const semantic_type
& v
, const location_type
& l
)
976 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
978 return yystos_
[state
];
982 template <typename Exact
>
984 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
985 symbol_base_type
<Exact
>& yysym
) const
987 int yytype
= yysym
.type_get ();
990 YY_SYMBOL_PRINT (yymsg
, yysym
);
995 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
1001 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1005 template <typename Exact
>
1007 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1008 const symbol_base_type
<Exact
>& yysym
) const
1010 int yytype
= yysym
.type_get ();
1011 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1012 << ' ' << yytname_
[yytype
] << " ("
1013 << yysym
.location
<< ": ";
1016 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1025 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1029 YY_SYMBOL_PRINT (m
, sym
);
1031 [[ yystack_
.push (stack_symbol_type (s
, semantic_type(), sym
.location
));
1032 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1033 [build
], [sym
.value
])],
1034 [ yystack_
.push (stack_symbol_type (s
, sym
.value
, sym
.location
));])[
1038 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1041 YY_SYMBOL_PRINT (m
, s
);
1043 [[ yystack_
.push (stack_symbol_type (s
.state
, semantic_type(), s
.location
));
1044 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1045 [build
], [s
.value
])],
1046 [ yystack_
.push (s
);])[
1050 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1057 ]b4_parser_class_name
[::debug_stream () const
1063 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1069 ]b4_parser_class_name
[::debug_level_type
1070 ]b4_parser_class_name
[::debug_level () const
1076 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1083 ]b4_parser_class_name
[::parse ()
1085 /// Whether yyla contains a lookahead.
1086 bool yyempty
= true;
1093 /* Error handling. */
1095 int yyerrstatus_
= 0;
1097 /// The lookahead symbol.
1100 /// The locations where the error started and ended.
1101 stack_symbol_type yyerror_range
[2];
1104 stack_symbol_type yylhs
;
1106 /// The return value of parse().
1109 YYCDEBUG
<< "Starting parse" << std::endl
;
1111 ]m4_ifdef([b4_initial_action
], [
1112 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1113 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1114 /* User initialization code. */
1115 b4_user_initial_action
1116 m4_popdef([b4_dollar_dollar
])dnl
1117 m4_popdef([b4_at_dollar
])])dnl
1119 [ /* Initialize the stack. The initial state will be set in
1120 yynewstate, since the latter expects the semantical and the
1121 location values to have been already stored, initialize these
1122 stacks with a primary value. */
1123 yystack_
= stack_type (0);
1124 yypush_ (0, 0, yyla
);
1126 // A new state was pushed on the stack.
1127 // Invariant: yystate == yystack_[0].state, i.e.,
1128 // yystate was just pushed onto the state stack.
1130 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1133 if (yystate
== yyfinal_
)
1141 /* Try to take a decision without lookahead. */
1142 yyn
= yypact_
[yystate
];
1143 if (yyn
== yypact_ninf_
)
1146 /* Read a lookahead token. */
1149 YYCDEBUG
<< "Reading a token: ";
1152 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1153 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1154 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1155 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1158 YY_SYMBOL_PRINT ("Next token is", yyla
);
1160 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1161 to detect an error, take that action. */
1163 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1166 /* Reduce or error. */
1167 yyn
= yytable_
[yyn
];
1170 if (yyn
== 0 || yyn
== yytable_ninf_
)
1176 /* Discard the token being shifted. */
1179 /* Count tokens shifted since error; after three, turn off error
1184 /* Shift the lookahead token. */
1186 yypush_ ("Shifting", yystate
, yyla
);
1189 /*-----------------------------------------------------------.
1190 | yydefault -- do the default action for the current state. |
1191 `-----------------------------------------------------------*/
1193 yyn
= yydefact_
[yystate
];
1198 /*-----------------------------.
1199 | yyreduce -- Do a reduction. |
1200 `-----------------------------*/
1202 yylen
= yyr2_
[yyn
];]b4_variant_if([
1203 /* Variants are always initialized to an empty instance of the
1204 correct type. The default $$=$1 rule is NOT applied when using
1206 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1207 /* If YYLEN is nonzero, implement the default value of the action:
1208 `$$ = $1'. Otherwise, use the top of the stack.
1210 Otherwise, the following line sets YYLHS.VALUE to garbage.
1211 This behavior is undocumented and Bison
1212 users should not rely upon it. */
1214 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1216 yylhs
.value
= yystack_@
{0@
}.value
;])[
1218 // Compute the default @@$.
1220 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1221 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1224 // Perform the reduction.
1225 YY_REDUCE_PRINT (yyn
);
1232 // Compute post-reduction state.
1234 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1235 if (0 <= yystate
&& yystate
<= yylast_
1236 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1237 yystate
= yytable_
[yystate
];
1239 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1240 yylhs
.state
= yystate
;
1241 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1243 // Destroy the lhs symbols.
1244 for (int i
= 0; i
< yylen
; ++i
)
1245 // Destroy a variant which value may have be swapped with
1246 // yylhs.value. The value of yylhs.value (hence maybe one of
1247 // these lhs symbols) depends on what does the default
1248 // contruction for this type. In the case of pointers for
1249 // instance, nothing is done, so the value is junk. Therefore
1250 // do not try to report the content in the debug trace, it's
1251 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1252 // traces as with the other Bison skeletons.
1253 yy_destroy_ (0, yystack_
[i
]);]])[
1259 /* Shift the result of the reduction. */
1263 /*------------------------------------.
1264 | yyerrlab -- here on detecting error |
1265 `------------------------------------*/
1267 /* If not already recovering from an error, report this error. */
1271 error (yyla
.location
, yysyntax_error_ (yystate
, yyla
.type
));
1274 yyerror_range
[0].location
= yyla
.location
;
1275 if (yyerrstatus_
== 3)
1277 /* If just tried and failed to reuse lookahead token after an
1278 error, discard it. */
1280 /* Return failure if at end of input. */
1281 if (yyla
.type
== yyeof_
)
1285 yy_destroy_ ("Error: discarding", yyla
);
1290 /* Else will try to reuse lookahead token after shifting the error
1295 /*---------------------------------------------------.
1296 | yyerrorlab -- error raised explicitly by YYERROR. |
1297 `---------------------------------------------------*/
1300 /* Pacify compilers like GCC when the user code never invokes
1301 YYERROR and the label yyerrorlab therefore never appears in user
1306 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1307 /* Do not reclaim the symbols of the rule which action triggered
1311 yystate
= yystack_
[0].state
;
1314 /*-------------------------------------------------------------.
1315 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1316 `-------------------------------------------------------------*/
1318 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1320 stack_symbol_type error_token
;
1323 yyn
= yypact_
[yystate
];
1324 if (yyn
!= yypact_ninf_
)
1327 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1329 yyn
= yytable_
[yyn
];
1335 // Pop the current state because it cannot handle the error token.
1336 if (yystack_
.size () == 1)
1339 yyerror_range
[0].location
= yystack_
[0].location
;
1340 yy_destroy_ ("Error: popping", yystack_
[0]);
1342 yystate
= yystack_
[0].state
;
1346 yyerror_range
[1].location
= yyla
.location
;
1347 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1349 /* Shift the error token. */
1350 error_token
.state
= yystate
= yyn
;
1351 yypush_ ("Shifting", error_token
);
1367 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1369 /* Do not reclaim the symbols of the rule which action triggered
1370 this YYABORT or YYACCEPT. */
1372 while (yystack_
.size () != 1)
1374 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1381 // Generate an error message.
1383 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1384 b4_error_verbose_if([int yystate
, int yytoken
],
1387 std::string yyres
;]b4_error_verbose_if([[
1388 int yyn
= yypact_
[yystate
];
1389 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1391 /* Start YYX at -YYN if negative to avoid negative indexes in
1393 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1395 /* Stay within bounds of both yycheck and yytname. */
1396 int yychecklim
= yylast_
- yyn
+ 1;
1397 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1399 // Number of "expected" tokens.
1402 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1403 // Arguments of yyformat.
1404 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1405 yyarg
[yycount
++] = yytname_
[yytoken
];
1406 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1407 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1409 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1415 yyarg
[yycount
++] = yytname_
[yyx
];
1418 char const* yyformat
= 0;
1421 #define YYCASE_(N, S) \
1425 YYCASE_(1, YY_("syntax error, unexpected %s"));
1426 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1427 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1428 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1429 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1434 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1435 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1437 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1445 [ yyres
= YY_("syntax error");
1450 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1452 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1453 ]b4_table_define([pact
], [b4_pact
])[;
1455 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1456 doesn't specify something else to do. Zero means the default is an
1458 ]b4_table_define([defact
], [b4_defact
])[;
1460 /* YYPGOTO[NTERM-NUM]. */
1461 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1463 /* YYDEFGOTO[NTERM-NUM]. */
1464 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1466 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1467 positive, shift that token. If negative, reduce the rule which
1468 number is the opposite. If zero, do what YYDEFACT says. */
1469 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1470 ]b4_table_define([table
], [b4_table
])[;
1473 ]b4_table_define([check
], [b4_check
])[;
1475 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1476 symbol of state STATE-NUM. */
1477 ]b4_table_define([stos
], [b4_stos
])[;
1480 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1482 ]b4_table_define([token_number
], [b4_toknum
])[;
1485 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1486 ]b4_table_define([r1
], [b4_r1
])[;
1488 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1489 ]b4_table_define([r2
], [b4_r2
])[;
1491 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1492 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1493 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1495 const ]b4_parser_class_name
[::yytname_
[] =
1502 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1503 ]b4_table_define([rline
], [b4_rline
])[;
1505 // Print the state stack on the debug stream.
1507 ]b4_parser_class_name
[::yystack_print_ ()
1509 *yycdebug_
<< "Stack now";
1510 for (stack_type::const_iterator
1511 i
= yystack_
.begin (),
1512 i_end
= yystack_
.end ();
1514 *yycdebug_
<< ' ' << i
->state
;
1515 *yycdebug_
<< std::endl
;
1518 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1520 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1522 unsigned int yylno
= yyrline_
[yyrule
];
1523 int yynrhs
= yyr2_
[yyrule
];
1524 /* Print the symbols being reduced, and their result. */
1525 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1526 << " (line " << yylno
<< "):" << std::endl
;
1527 /* The symbols being reduced. */
1528 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1529 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1530 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1534 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1535 ]b4_parser_class_name
[::token_number_type
1536 ]b4_parser_class_name
[::yytranslate_ (int t
)
1539 const token_number_type
1544 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
1545 const token_number_type undef_token_
= ]b4_undef_token_number
[;
1549 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
1550 return translate_table
[t
];
1552 return undef_token_
;
1555 ]b4_namespace_close
[
1558 @
output(b4_dir_prefix
[]stack
.hh@
)@
1559 b4_copyright([Stack handling
for Bison parsers in C
++])[
1561 #ifndef BISON_STACK_HH
1562 # define BISON_STACK_HH
1567 template <class T
, class S
= std::deque
<T
> >
1572 // Hide our reversed order.
1573 typedef typename
S::reverse_iterator iterator
;
1574 typedef typename
S::const_reverse_iterator const_iterator
;
1580 stack (unsigned int n
) : seq_ (n
)
1586 operator [] (unsigned int i
)
1593 operator [] (unsigned int i
) const
1602 seq_
.push_front (t
);
1607 pop (unsigned int n
= 1)
1614 typename
S::size_type
1617 return seq_
.size ();
1620 inline const_iterator
begin () const { return seq_
.rbegin (); }
1621 inline const_iterator
end () const { return seq_
.rend (); }
1624 /// The wrapped container.
1628 /// Present a slice of the top of a stack.
1629 template <class T
, class S
= stack
<T
> >
1634 slice (const S
& stack
,
1635 unsigned int range
) : stack_ (stack
),
1642 operator [] (unsigned int i
) const
1644 return stack_
[range_
- i
];
1650 unsigned int range_
;
1652 ]b4_namespace_close
[
1654 #endif // not BISON_STACK_HH[]dnl
1657 m4_popdef([b4_copyright_years
])dnl