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_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
57 # ------------------------------------------------
58 m4_define([b4_assert_if
],
59 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
62 # b4_lhs_value([TYPE])
63 # --------------------
64 # Expansion of $<TYPE>$.
65 m4_define([b4_lhs_value
],
66 [b4_symbol_value([yylhs
.value
], [$
1])])
72 m4_define([b4_lhs_location
],
76 # b4_rhs_data(RULE-LENGTH, NUM)
77 # -----------------------------
78 # Return the data corresponding to the symbol #NUM, where the current
79 # rule has RULE-LENGTH symbols on RHS.
80 m4_define([b4_rhs_data
],
81 [yystack_@
{($
1) - ($
2)@
}])
84 # b4_rhs_state(RULE-LENGTH, NUM)
85 # -----------------------------
86 # The state corresponding to the symbol #NUM, where the current
87 # rule has RULE-LENGTH symbols on RHS.
88 m4_define([b4_rhs_state
],
89 [b4_rhs_data([$
1], [$
2]).state
])
92 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
93 # --------------------------------------
94 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
96 m4_define([b4_rhs_value
],
97 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
100 # b4_rhs_location(RULE-LENGTH, NUM)
101 # ---------------------------------
102 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
104 m4_define([b4_rhs_location
],
105 [b4_rhs_data([$
1], [$
2]).location
])
108 # b4_symbol(NUM, FIELD)
109 # ---------------------
110 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
112 m4_define([b4_symbol
],
113 [m4_indir([b4_symbol($
1, $
2)])])
116 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
117 # -------------------------------------------
118 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
119 # Otherwise an error.
120 m4_define([b4_symbol_if
],
121 [m4_case(b4_symbol([$
1], [$
2]),
124 [m4_fatal([$
0: field $
2 of $
1 is
not a Boolean
:] b4_symbol([$
1], [$
2]))])])
127 # b4_symbol_actions(FILENAME, LINENO,
128 # SYMBOL-TAG, SYMBOL-NUM,
129 # SYMBOL-ACTION, SYMBOL-TYPENAME)
130 # -------------------------------------------------
131 # Same as in C, but using references instead of pointers.
132 m4_define([b4_symbol_actions
],
133 [m4_pushdef([b4_dollar_dollar
],
134 [b4_symbol_value_template([yysym
.value
], [$
6])])dnl
135 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
137 b4_syncline([$
2], [$
1])
139 b4_syncline([@oline@
], [@ofile@
])
141 m4_popdef([b4_at_dollar
])dnl
142 m4_popdef([b4_dollar_dollar
])dnl
146 # b4_symbol_case_(SYMBOL-NUM)
147 # ---------------------------
148 # Issue a "case NUM" for SYMBOL-NUM.
149 m4_define([b4_symbol_case_
],
150 [ case b4_symbol([$
1], [number
]): // b4_symbol([$1], [tag])
154 # b4_type_action_(NUMS)
155 # ---------------------
156 # Run actions for the symbol NUMS that all have the same type-name.
157 # Skip NUMS that have no type-name.
158 m4_define([b4_type_action_
],
159 [b4_symbol_if([$
1], [has_type_name
],
160 [m4_map([b4_symbol_case_
], [$@
])[]dnl
161 b4_dollar_dollar([b4_symbol([$
1], [number
])],
162 [b4_symbol([$
1], [tag
])],
163 [b4_symbol([$
1], [type_name
])]);
169 # b4_symbol_constructor_declaration_(SYMBOL-NUMBERS)
170 # ----------------------------------------------------
171 # Declare the overloaded version of make_symbol for the (common) type of
172 # these SYMBOL-NUMBERS. Use at class-level.
173 m4_define([b4_symbol_constructor_declaration_
],
174 [ template <token_type
>
175 static inline symbol_type
176 make_symbol (b4_symbol_if([$
1], [has_type_name
],
177 [const b4_symbol([$
1], [type_name
])& v
, ])dnl
178 const location_type
& l
);
182 # b4_symbol_constructor_declarations
183 # ----------------------------------
184 # Declare the overloaded versions of make_symbol for all the value types.
185 # Use at class-level.
186 m4_define([b4_symbol_constructor_declarations
],
188 // Declaration of make_symbol for each value type.
189 m4_map([b4_symbol_constructor_declaration_
], m4_defn([b4_type_names
]))])])
193 # b4_symbol_constructor_specialization_(SYMBOL-NUMBER)
194 # ----------------------------------------------------
195 # Declare the specialization of make_symbol for this each SYMBOL-NUMBER.
196 # Specializations cannot be declared at class-level, this must be done
197 # at namespace-level.
198 m4_define([b4_symbol_constructor_specialization_
],
199 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [tag_is_id
],
202 b4_parser_class_name::symbol_type
203 b4_parser_class_name::make_symbol
<b4_parser_class_name::token::b4_symbol([$
1], [tag
])> (dnl
204 b4_symbol_if([$
1], [has_type_name
],
205 [const b4_symbol([$
1], [type_name
])& v
, ])dnl
206 const b4_parser_class_name::location_type
& l
);
209 # b4_symbol_constructor_specializations
210 # -------------------------------------
211 # Declare specializations of make_symbol.
212 m4_define([b4_symbol_constructor_specializations
],
214 // Specializations of make_symbol for each symbol type.
215 m4_map([b4_symbol_constructor_specialization_
],
216 m4_defn([b4_symbol_numbers
]))])dnl
221 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
222 # ------------------------------------------------
223 # Define make_symbol for this SYMBOL-NUMBER.
224 m4_define([b4_symbol_constructor_definition_
],
225 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [tag_is_id
],
227 b4_parser_class_name::symbol_type
228 b4_parser_class_name::make_symbol
<b4_parser_class_name::token::b4_symbol([$
1], [tag
])> (dnl
229 b4_symbol_if([$
1], [has_type_name
],
230 [const b4_symbol([$
1], [type_name
])& v
, ])dnl
231 const location_type
& l
)
233 return symbol_type (yytranslate_ (token::b4_symbol([$
1], [tag
])),dnl
234 b4_symbol_if([$
1], [has_type_name
], [v
, ])l
);
240 # b4_symbol_constructor_declarations
241 # ----------------------------------
242 # Define the overloaded versions of make_symbol for all the value types.
243 m4_define([b4_symbol_constructor_definitions
],
245 [ // Implementation of make_symbol for each symbol type.
246 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
249 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
250 # ------------------------------------------------
251 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
253 m4_define([b4_symbol_variant
],
254 [m4_pushdef([b4_dollar_dollar
],
255 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
258 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
262 m4_popdef([b4_dollar_dollar
])dnl
266 # _b4_char_sizeof_counter
267 # -----------------------
268 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
269 m4_define([_b4_char_sizeof_counter
],
272 # _b4_char_sizeof_dummy
273 # ---------------------
274 # At each call return a new C++ identifier.
275 m4_define([_b4_char_sizeof_dummy
],
276 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
277 dummy
[]_b4_char_sizeof_counter
])
280 # b4_char_sizeof(SYMBOL-NUM)
281 # --------------------------
282 # To be mapped on the list of type names to produce:
284 # char dummy1[sizeof(type_name_1)];
285 # char dummy2[sizeof(type_name_2)];
287 # for defined type names.
288 # $3 is doubly-quoted, do not quote it again.
289 m4_define([b4_char_sizeof
],
290 [m4_ifval(b4_symbol([$
1], [type_name
]),
292 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type_name
])])@
}; // b4_symbol([$1], [tag])])dnl
296 m4_pushdef([b4_copyright_years
],
297 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
299 m4_define([b4_parser_class_name
],
300 [b4_percent_define_get([[parser_class_name]])])
302 # The header is mandatory.
304 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
306 # Backward compatibility.
307 m4_define([b4_location_constructors
])
308 m4_include(b4_pkgdatadir
/[location
.cc
])
310 # We do want M4 expansion after # for CPP macros.
314 [@
output(b4_spec_defines_file@
)@
315 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
316 dnl FIXME
: This is wrong
, we want computed header guards
.
318 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
320 #ifndef PARSER_HEADER_H
321 # define PARSER_HEADER_H
323 ]b4_percent_code_get([[requires]])[
325 ]b4_assert_if([#include <cassert>])[
335 /// A char[S] buffer to store and retrieve objects.
337 /// Sort of a variant, but does not keep track of the nature
338 /// of the stored data, since that knowledge is available
339 /// via the current state.
343 /// Whether something is contained.
346 /// Empty construction.
348 variant ()]b4_assert_if([
352 /// Instantiate a \a T in here.
353 template <typename T
>
359 return *new (buffer
) T
;
362 /// Instantiate a \a T in here from \a t.
363 template <typename T
>
369 return *new (buffer
) T(t
);
372 /// Construct and fill.
373 template <typename T
>
375 variant (const T
& t
)]b4_assert_if([
381 /// Accessor to a built \a T.
382 template <typename T
>
387 return reinterpret_cast<T
&>(buffer
);
390 /// Const accessor to a built \a T (for %printer).
391 template <typename T
>
396 return reinterpret_cast<const T
&>(buffer
);
399 /// Swap the content with \a other.
400 template <typename T
>
402 swap(variant
<S
>& other
)
404 std::swap(as
<T
>(), other
.as
<T
>());
407 /// Assign the content of \a other to this.
408 /// Destroys \a other.
409 template <typename T
>
411 build(variant
<S
>& other
)
418 /// Destroy the stored \a T.
419 template <typename T
>
423 as
<T
>().~T();]b4_assert_if([
427 /// A buffer large enough to store any of the semantic values.
433 #include "location.hh"
435 /* Enabling traces. */
437 # define YYDEBUG ]b4_debug_flag[
440 /* Enabling verbose error messages. */
441 #ifdef YYERROR_VERBOSE
442 # undef YYERROR_VERBOSE
443 # define YYERROR_VERBOSE 1
445 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
448 /* Enabling the token table. */
449 #ifndef YYTOKEN_TABLE
450 # define YYTOKEN_TABLE ]b4_token_table[
453 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
454 If N is 0, then set CURRENT to the empty location which ends
455 the previous symbol: RHS[0] (always defined). */
457 #ifndef YYLLOC_DEFAULT
458 # define YYLLOC_DEFAULT(Current, Rhs, N) \
462 (Current).begin = (Rhs)[1].location.begin; \
463 (Current).end = (Rhs)[N].location.end; \
467 (Current).begin = (Current).end = (Rhs)[0].location.end; \
475 class ]b4_parser_class_name
[
480 [ /// An auxiliary type to compute the largest semantic type.
482 {]m4_map([b4_char_sizeof
], m4_defn([b4_symbol_numbers
]))[
485 /// Symbol semantic values.
486 typedef variant
<sizeof(union_type
)> semantic_type
;],
487 [ /// Symbol semantic values.
489 [ union semantic_type
492 [m4_if(b4_tag_seen_flag
, 0,
493 [[ typedef int semantic_type
;]],
494 [[ typedef YYSTYPE semantic_type
;]])])])[
496 typedef YYSTYPE semantic_type
;
498 /// Symbol locations.
499 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
503 ]b4_token_enums(b4_tokens
)[
506 typedef token::yytokentype token_type
;
508 /// Build a parser object.
509 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
510 virtual ~]b4_parser_class_name
[ ();
513 /// \returns 0 iff parsing succeeded.
514 virtual int parse ();
517 /// The current debugging stream.
518 std::ostream
& debug_stream () const;
519 /// Set the current debugging stream.
520 void set_debug_stream (std::ostream
&);
522 /// Type for debugging levels.
523 typedef int debug_level_type
;
524 /// The current debugging level.
525 debug_level_type
debug_level () const;
526 /// Set the current debugging level.
527 void set_debug_level (debug_level_type l
);
531 /// Report a syntax error.
532 /// \param loc where the syntax error is found.
533 /// \param msg a description of the syntax error.
534 virtual void error (const location_type
& loc
, const std::string
& msg
);
536 /// Generate an error message.
537 /// \param state the state where the error occurred.
538 /// \param tok the lookahead token.
539 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
542 typedef int state_type
;
544 /// Internal symbol numbers.
545 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
547 /// For a state, the index in \a yytable_ of its portion.
548 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
549 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
551 /// For a state, default rule to reduce.
552 /// Unless\a yytable_ specifies something else to do.
553 /// Zero means the default is an error.
554 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
556 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
557 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
559 /// What to do in a state.
560 /// \a yytable_[yypact_[s]]: what to do in state \a s.
561 /// - if positive, shift that token.
562 /// - if negative, reduce the rule which number is the opposite.
563 /// - if zero, do what YYDEFACT says.
564 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
565 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
567 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
569 /// For a state, its accessing symbol.
570 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
572 /// For a rule, its LHS.
573 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
574 /// For a rule, its RHS length.
575 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
577 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
578 /// For a symbol, its name in clear.
579 static const char* const yytname_
[];
583 /// Convert the symbol name \a n to a form suitable for a diagnostic.
584 virtual std::string
yytnamerr_ (const char *n
);
588 /// For each rule, its source line number.
589 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
590 /// For each scanner token number, its symbol number.
591 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
592 /// Report on the debug stream that the rule \a r is going to be reduced.
593 virtual void yy_reduce_print_ (int r
);
594 /// Print the state stack on the debug stream.
595 virtual void yystack_print_ ();
599 std::ostream
* yycdebug_
;
602 /// Convert a scanner token number \a t to a symbol number.
603 static inline token_number_type
yytranslate_ (int t
);
605 /// A complete symbol, with its type.
606 template <typename Exact
>
607 struct symbol_base_type
609 /// Default constructor.
610 inline symbol_base_type ();
613 inline symbol_base_type (const location_type
& l
);
614 inline symbol_base_type (const semantic_type
& v
, const location_type
& l
);
616 /// Return this with its exact type.
617 const Exact
& self () const;
620 /// Return the type of this symbol.
621 int type_get () const;
623 /// The semantic value.
627 location_type location
;
631 /// \brief Display a symbol type, value and location.
632 /// \param yyo The output stream.
633 /// \param yysym The symbol.
634 template <typename Exact
>
635 void yy_print_ (std::ostream
& yyo
,
636 const symbol_base_type
<Exact
>& yysym
) const;
639 /// \brief Reclaim the memory associated to a symbol.
640 /// \param yymsg Why this token is reclaimed.
641 /// If null, print nothing.
642 /// \param s The symbol.
643 template <typename Exact
>
644 inline void yy_destroy_ (const char* yymsg
,
645 symbol_base_type
<Exact
>& yysym
) const;
648 /// Element of the stack: a state and its attributes.
649 struct symbol_type
: symbol_base_type
<symbol_type
>
651 /// The parent class.
652 typedef symbol_base_type
<symbol_type
> super_type
;
654 /// Default constructor.
655 inline symbol_type ();
658 inline symbol_type (int t
,
659 const semantic_type
& v
, const location_type
& l
);
661 inline symbol_type (int t
,
662 const location_type
& l
);
667 /// Return the type corresponding to this state.
668 inline int type_get_ () const;
671 ]b4_symbol_constructor_declarations
[
674 /// Element of the stack: a state and its attributes.
675 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
677 /// The parent class.
678 typedef symbol_base_type
<stack_symbol_type
> super_type
;
680 /// Default constructor.
681 inline stack_symbol_type ();
684 inline stack_symbol_type (state_type s
,
685 const semantic_type
& v
, const location_type
& l
);
690 /// Return the type corresponding to this state.
691 inline int type_get_ () const;
695 typedef stack
<stack_symbol_type
> stack_type
;
700 /// Push a new state on the stack.
701 /// \param m a debug message to display
702 /// if null, no trace is output.
703 /// \param s the symbol
704 /// \warning the contents of \a s.value is stolen.
705 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
707 /// Push a new look ahead token on the state on the stack.
708 /// \param m a debug message to display
709 /// if null, no trace is output.
710 /// \param s the state
711 /// \param sym the symbol (for its value and location).
712 /// \warning the contents of \a s.value is stolen.
713 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
715 /// Pop \a n symbols the three stacks.
716 inline void yypop_ (unsigned int n
= 1);
722 yylast_
= ]b4_last
[, //< Last index in yytable_.
723 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
725 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
728 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
731 ]b4_parse_param_vars
[
733 ]b4_symbol_constructor_specializations
[
736 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
737 [b4_token_defines(b4_tokens
)
740 /* Redirection for backward compatibility. */
741 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
744 b4_percent_code_get([[provides]])[]dnl
746 [#endif /* ! defined PARSER_HEADER_H */]
748 @
output(b4_parser_file_name@
)@
749 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
750 b4_percent_code_get([[top]])[]dnl
751 m4_if(b4_prefix
, [yy
], [],
753 // Take the name prefix into account.
754 #define yylex b4_prefix[]lex])[
756 /* First part of user declarations. */
757 ]b4_user_pre_prologue
760 #include "@basename(]b4_spec_defines_file[@)"]])[
762 /* User implementation prologue. */
763 ]b4_user_post_prologue
764 b4_percent_code_get
[]dnl
769 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
770 # define YY_(msgid) dgettext ("bison-runtime", msgid)
774 # define YY_(msgid) msgid
778 /* Suppress unused-variable warnings by "using" E. */
779 #define YYUSE(e) ((void) (e))
781 /* Enable debugging if requested. */
784 /* A pseudo ostream that takes yydebug_ into account. */
785 # define YYCDEBUG if (yydebug_) (*yycdebug_)
787 # define YY_SYMBOL_PRINT(Title, Symbol) \
791 *yycdebug_ << Title << ' '; \
792 yy_print_ (*yycdebug_, Symbol); \
793 *yycdebug_ << std::endl; \
797 # define YY_REDUCE_PRINT(Rule) \
800 yy_reduce_print_ (Rule); \
803 # define YY_STACK_PRINT() \
811 # define YYCDEBUG if (false) std::cerr
812 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
813 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
814 # define YY_STACK_PRINT() static_cast<void>(0)
816 #endif /* !YYDEBUG */
818 #define yyerrok (yyerrstatus_ = 0)
819 #define yyclearin (yychar = yyempty_)
821 #define YYACCEPT goto yyacceptlab
822 #define YYABORT goto yyabortlab
823 #define YYERROR goto yyerrorlab
824 #define YYRECOVERING() (!!yyerrstatus_)
829 /* Return YYSTR after stripping away unnecessary quotes and
830 backslashes, so that it's suitable for yyerror. The heuristic is
831 that double-quoting is unnecessary unless the string contains an
832 apostrophe, a comma, or backslash (other than backslash-backslash).
833 YYSTR is taken from yytname. */
835 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
839 std::string yyr
= "";
840 char const *yyp
= yystr
;
847 goto do_not_strip_quotes
;
851 goto do_not_strip_quotes
;
860 do_not_strip_quotes
: ;
868 /// Build a parser object.
869 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
872 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
873 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
874 #endif]b4_parse_param_cons[
878 ]b4_parser_class_name::~b4_parser_class_name
[ ()
888 template <typename Exact
>
889 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
895 template <typename Exact
>
896 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
902 template <typename Exact
>
903 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const semantic_type
& v
, const location_type
& l
)
909 template <typename Exact
>
911 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
913 return static_cast<const Exact
&>(*this);
916 template <typename Exact
>
918 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
920 return static_cast<Exact
&>(*this);
923 template <typename Exact
>
925 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
927 return self ().type_get_ ();
931 ]b4_parser_class_name
[::symbol_type::symbol_type ()
937 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
938 const location_type
& l
)
944 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
945 const semantic_type
& v
, const location_type
& l
)
952 ]b4_parser_class_name
[::symbol_type::type_get_ () const
957 ]b4_symbol_constructor_definitions
[
959 // stack_symbol_type.
960 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
966 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (state_type s
,
967 const semantic_type
& v
, const location_type
& l
)
974 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
976 return yystos_
[state
];
980 template <typename Exact
>
982 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
983 symbol_base_type
<Exact
>& yysym
) const
985 int yytype
= yysym
.type_get ();
988 YY_SYMBOL_PRINT (yymsg
, yysym
);
993 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
999 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1003 template <typename Exact
>
1005 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1006 const symbol_base_type
<Exact
>& yysym
) const
1008 int yytype
= yysym
.type_get ();
1009 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1010 << ' ' << yytname_
[yytype
] << " ("
1011 << yysym
.location
<< ": ";
1014 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1023 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1027 YY_SYMBOL_PRINT (m
, sym
);
1029 [[ yystack_
.push (stack_symbol_type (s
, semantic_type(), sym
.location
));
1030 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1031 [build
], [sym
.value
])],
1032 [ yystack_
.push (stack_symbol_type (s
, sym
.value
, sym
.location
));])[
1036 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1039 YY_SYMBOL_PRINT (m
, s
);
1041 [[ yystack_
.push (stack_symbol_type (s
.state
, semantic_type(), s
.location
));
1042 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1043 [build
], [s
.value
])],
1044 [ yystack_
.push (s
);])[
1048 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1055 ]b4_parser_class_name
[::debug_stream () const
1061 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1067 ]b4_parser_class_name
[::debug_level_type
1068 ]b4_parser_class_name
[::debug_level () const
1074 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1081 ]b4_parser_class_name
[::parse ()
1083 /// Coded type of the lookahead.
1084 int yychar
= yyempty_
;
1091 /* Error handling. */
1093 int yyerrstatus_
= 0;
1095 /// The lookahead symbol.
1098 /// The locations where the error started and ended.
1099 stack_symbol_type yyerror_range
[2];
1102 stack_symbol_type yylhs
;
1104 /// The return value of parse().
1107 YYCDEBUG
<< "Starting parse" << std::endl
;
1109 ]m4_ifdef([b4_initial_action
], [
1110 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1111 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1112 /* User initialization code. */
1113 b4_user_initial_action
1114 m4_popdef([b4_dollar_dollar
])dnl
1115 m4_popdef([b4_at_dollar
])])dnl
1117 [ /* Initialize the stack. The initial state will be set in
1118 yynewstate, since the latter expects the semantical and the
1119 location values to have been already stored, initialize these
1120 stacks with a primary value. */
1121 yystack_
= stack_type (0);
1122 yypush_ (0, 0, yyla
);
1124 // A new state was pushed on the stack.
1125 // Invariant: yystate == yystack_[0].state, i.e.,
1126 // yystate was just pushed onto the state stack.
1128 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1131 if (yystate
== yyfinal_
)
1139 /* Try to take a decision without lookahead. */
1140 yyn
= yypact_
[yystate
];
1141 if (yyn
== yypact_ninf_
)
1144 /* Read a lookahead token. */
1145 if (yychar
== yyempty_
)
1147 YYCDEBUG
<< "Reading a token: ";
1148 yychar
= ]b4_c_function_call([yylex
], [int],
1149 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1150 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1151 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
1154 /* Convert token to internal form. */
1155 if (yychar
<= yyeof_
)
1157 yychar
= yyla
.type
= yyeof_
;
1158 YYCDEBUG
<< "Now at end of input." << std::endl
;
1162 yyla
.type
= yytranslate_ (yychar
);
1163 YY_SYMBOL_PRINT ("Next token is", yyla
);
1166 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1167 to detect an error, take that action. */
1169 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1172 /* Reduce or error. */
1173 yyn
= yytable_
[yyn
];
1176 if (yyn
== 0 || yyn
== yytable_ninf_
)
1182 /* Discard the token being shifted. */
1185 /* Count tokens shifted since error; after three, turn off error
1190 /* Shift the lookahead token. */
1192 yypush_ ("Shifting", yystate
, yyla
);
1195 /*-----------------------------------------------------------.
1196 | yydefault -- do the default action for the current state. |
1197 `-----------------------------------------------------------*/
1199 yyn
= yydefact_
[yystate
];
1204 /*-----------------------------.
1205 | yyreduce -- Do a reduction. |
1206 `-----------------------------*/
1208 yylen
= yyr2_
[yyn
];]b4_variant_if([
1209 /* Variants are always initialized to an empty instance of the
1210 correct type. The default $$=$1 rule is NOT applied when using
1212 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1213 /* If YYLEN is nonzero, implement the default value of the action:
1214 `$$ = $1'. Otherwise, use the top of the stack.
1216 Otherwise, the following line sets YYLHS.VALUE to garbage.
1217 This behavior is undocumented and Bison
1218 users should not rely upon it. */
1220 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1222 yylhs
.value
= yystack_@
{0@
}.value
;])[
1224 // Compute the default @@$.
1226 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1227 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1230 // Perform the reduction.
1231 YY_REDUCE_PRINT (yyn
);
1238 // Compute post-reduction state.
1240 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1241 if (0 <= yystate
&& yystate
<= yylast_
1242 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1243 yystate
= yytable_
[yystate
];
1245 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1246 yylhs
.state
= yystate
;
1247 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1249 // Destroy the lhs symbols.
1250 for (int i
= 0; i
< yylen
; ++i
)
1251 // Destroy a variant which value may have be swapped with
1252 // yylhs.value. The value of yylhs.value (hence maybe one of
1253 // these lhs symbols) depends on what does the default
1254 // contruction for this type. In the case of pointers for
1255 // instance, nothing is done, so the value is junk. Therefore
1256 // do not try to report the content in the debug trace, it's
1257 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1258 // traces as with the other Bison skeletons.
1259 yy_destroy_ (0, yystack_
[i
]);]])[
1265 /* Shift the result of the reduction. */
1269 /*------------------------------------.
1270 | yyerrlab -- here on detecting error |
1271 `------------------------------------*/
1273 /* If not already recovering from an error, report this error. */
1277 error (yyla
.location
, yysyntax_error_ (yystate
, yyla
.type
));
1280 yyerror_range
[0].location
= yyla
.location
;
1281 if (yyerrstatus_
== 3)
1283 /* If just tried and failed to reuse lookahead token after an
1284 error, discard it. */
1286 /* Return failure if at end of input. */
1287 if (yychar
== yyeof_
)
1291 // Previous version of this code was ready to handle
1292 // yychar == yyempty_ (actually yychar <= yyeof_). Can it
1293 // really be triggered?
1294 assert (yychar
!= yyempty_
);])[
1295 yy_destroy_ ("Error: discarding", yyla
);
1300 /* Else will try to reuse lookahead token after shifting the error
1305 /*---------------------------------------------------.
1306 | yyerrorlab -- error raised explicitly by YYERROR. |
1307 `---------------------------------------------------*/
1310 /* Pacify compilers like GCC when the user code never invokes
1311 YYERROR and the label yyerrorlab therefore never appears in user
1316 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1317 /* Do not reclaim the symbols of the rule which action triggered
1321 yystate
= yystack_
[0].state
;
1324 /*-------------------------------------------------------------.
1325 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1326 `-------------------------------------------------------------*/
1328 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1330 stack_symbol_type error_token
;
1333 yyn
= yypact_
[yystate
];
1334 if (yyn
!= yypact_ninf_
)
1337 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1339 yyn
= yytable_
[yyn
];
1345 // Pop the current state because it cannot handle the error token.
1346 if (yystack_
.size () == 1)
1349 yyerror_range
[0].location
= yystack_
[0].location
;
1350 yy_destroy_ ("Error: popping", yystack_
[0]);
1352 yystate
= yystack_
[0].state
;
1356 yyerror_range
[1].location
= yyla
.location
;
1357 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1359 /* Shift the error token. */
1360 error_token
.state
= yystate
= yyn
;
1361 yypush_ ("Shifting", error_token
);
1376 if (yychar
!= yyempty_
)
1377 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1379 /* Do not reclaim the symbols of the rule which action triggered
1380 this YYABORT or YYACCEPT. */
1382 while (yystack_
.size () != 1)
1384 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1391 // Generate an error message.
1393 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1394 b4_error_verbose_if([ tok
])[)
1399 int yyn
= yypact_
[yystate
];
1400 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1402 /* Start YYX at -YYN if negative to avoid negative indexes in
1404 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1406 /* Stay within bounds of both yycheck and yytname. */
1407 int yychecklim
= yylast_
- yyn
+ 1;
1408 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1410 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1411 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1414 // FIXME: This method of building the message is not compatible
1415 // with internationalization. It should work like yacc.c does it.
1416 // That is, first build a string that looks like this:
1417 // "syntax error, unexpected %s or %s or %s"
1418 // Then, invoke YY_ on this string.
1419 // Finally, use the string as a format to output
1420 // yytname_[tok], etc.
1421 // Until this gets fixed, this message appears in English only.
1422 res
= "syntax error, unexpected ";
1423 res
+= yytnamerr_ (yytname_
[tok
]);
1427 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1428 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1430 res
+= (!count
++) ? ", expecting " : " or ";
1431 res
+= yytnamerr_ (yytname_
[x
]);
1437 res
= YY_("syntax error");
1442 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1444 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1445 ]b4_table_define([pact
], [b4_pact
])[;
1447 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1448 doesn't specify something else to do. Zero means the default is an
1450 ]b4_table_define([defact
], [b4_defact
])[;
1452 /* YYPGOTO[NTERM-NUM]. */
1453 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1455 /* YYDEFGOTO[NTERM-NUM]. */
1456 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1458 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1459 positive, shift that token. If negative, reduce the rule which
1460 number is the opposite. If zero, do what YYDEFACT says. */
1461 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1462 ]b4_table_define([table
], [b4_table
])[;
1465 ]b4_table_define([check
], [b4_check
])[;
1467 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1468 symbol of state STATE-NUM. */
1469 ]b4_table_define([stos
], [b4_stos
])[;
1472 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1474 ]b4_table_define([token_number
], [b4_toknum
])[;
1477 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1478 ]b4_table_define([r1
], [b4_r1
])[;
1480 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1481 ]b4_table_define([r2
], [b4_r2
])[;
1483 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1484 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1485 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1487 const ]b4_parser_class_name
[::yytname_
[] =
1494 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1495 ]b4_table_define([rline
], [b4_rline
])[;
1497 // Print the state stack on the debug stream.
1499 ]b4_parser_class_name
[::yystack_print_ ()
1501 *yycdebug_
<< "Stack now";
1502 for (stack_type::const_iterator
1503 i
= yystack_
.begin (),
1504 i_end
= yystack_
.end ();
1506 *yycdebug_
<< ' ' << i
->state
;
1507 *yycdebug_
<< std::endl
;
1510 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1512 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1514 unsigned int yylno
= yyrline_
[yyrule
];
1515 int yynrhs
= yyr2_
[yyrule
];
1516 /* Print the symbols being reduced, and their result. */
1517 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1518 << " (line " << yylno
<< "):" << std::endl
;
1519 /* The symbols being reduced. */
1520 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1521 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1522 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1526 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1527 ]b4_parser_class_name
[::token_number_type
1528 ]b4_parser_class_name
[::yytranslate_ (int t
)
1531 const token_number_type
1536 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
1537 const token_number_type undef_token_
= ]b4_undef_token_number
[;
1539 if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
1540 return translate_table
[t
];
1542 return undef_token_
;
1545 ]b4_namespace_close
[
1548 @
output(b4_dir_prefix
[]stack
.hh@
)@
1549 b4_copyright([Stack handling
for Bison parsers in C
++])[
1551 #ifndef BISON_STACK_HH
1552 # define BISON_STACK_HH
1557 template <class T
, class S
= std::deque
<T
> >
1562 // Hide our reversed order.
1563 typedef typename
S::reverse_iterator iterator
;
1564 typedef typename
S::const_reverse_iterator const_iterator
;
1570 stack (unsigned int n
) : seq_ (n
)
1576 operator [] (unsigned int i
)
1583 operator [] (unsigned int i
) const
1592 seq_
.push_front (t
);
1597 pop (unsigned int n
= 1)
1604 typename
S::size_type
1607 return seq_
.size ();
1610 inline const_iterator
begin () const { return seq_
.rbegin (); }
1611 inline const_iterator
end () const { return seq_
.rend (); }
1614 /// The wrapped container.
1618 /// Present a slice of the top of a stack.
1619 template <class T
, class S
= stack
<T
> >
1624 slice (const S
& stack
,
1625 unsigned int range
) : stack_ (stack
),
1632 operator [] (unsigned int i
) const
1634 return stack_
[range_
- i
];
1640 unsigned int range_
;
1642 ]b4_namespace_close
[
1644 #endif // not BISON_STACK_HH[]dnl
1647 m4_popdef([b4_copyright_years
])dnl