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_actions(FILENAME, LINENO,
109 # SYMBOL-TAG, SYMBOL-NUM,
110 # SYMBOL-ACTION, SYMBOL-TYPENAME)
111 # -------------------------------------------------
112 # Same as in C, but using references instead of pointers.
113 m4_define([b4_symbol_actions
],
114 [m4_pushdef([b4_dollar_dollar
],
115 [b4_symbol_value_template([yysym
.value
], [$
6])])dnl
116 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
118 b4_syncline([$
2], [$
1])
120 b4_syncline([@oline@
], [@ofile@
])
122 m4_popdef([b4_at_dollar
])dnl
123 m4_popdef([b4_dollar_dollar
])dnl
127 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
128 # ----------------------------------------------------------
129 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
130 m4_define([b4_symbol_action_
],
133 b4_dollar_dollar($@
);
138 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
139 # ------------------------------------------------
140 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
142 m4_define([b4_symbol_variant
],
143 [m4_pushdef([b4_dollar_dollar
],
144 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
147 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
151 m4_popdef([b4_dollar_dollar
])dnl
155 # _b4_char_sizeof_counter
156 # -----------------------
157 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
158 m4_define([_b4_char_sizeof_counter
],
161 # _b4_char_sizeof_dummy
162 # ---------------------
163 # At each call return a new C++ identifier.
164 m4_define([_b4_char_sizeof_dummy
],
165 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
166 dummy
[]_b4_char_sizeof_counter
])
169 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
170 # -------------------------------------------------------
171 # To be mapped on the list of type names to produce:
173 # char dummy1[sizeof(type_name_1)];
174 # char dummy2[sizeof(type_name_2)];
176 # for defined type names.
177 # $3 is doubly-quoted, do not quote it again.
178 m4_define([b4_char_sizeof
],
181 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
185 m4_pushdef([b4_copyright_years
],
186 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
188 m4_define([b4_parser_class_name
],
189 [b4_percent_define_get([[parser_class_name]])])
191 # The header is mandatory.
193 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
195 # Backward compatibility.
196 m4_define([b4_location_constructors
])
197 m4_include(b4_pkgdatadir
/[location
.cc
])
199 # We do want M4 expansion after # for CPP macros.
203 [@
output(b4_spec_defines_file@
)@
204 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
205 dnl FIXME
: This is wrong
, we want computed header guards
.
207 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
209 #ifndef PARSER_HEADER_H
210 # define PARSER_HEADER_H
212 ]b4_percent_code_get([[requires]])[
214 ]b4_assert_if([#include <cassert>])[
224 /// A char[S] buffer to store and retrieve objects.
226 /// Sort of a variant, but does not keep track of the nature
227 /// of the stored data, since that knowledge is available
228 /// via the current state.
232 /// Whether something is contained.
235 /// Initially uninitialized.
240 /// Instantiate a \a T in here.
241 template <typename T
>
247 return *new (buffer
) T
;
250 /// Instantiate a \a T in here from \a t.
251 template <typename T
>
257 return *new (buffer
) T(t
);
260 /// Accessor to a built \a T.
261 template <typename T
>
266 return reinterpret_cast<T
&>(buffer
);
269 /// Const accessor to a built \a T (for %printer).
270 template <typename T
>
275 return reinterpret_cast<const T
&>(buffer
);
278 /// Swap the content with \a other.
279 template <typename T
>
281 swap(variant
<S
>& other
)
283 std::swap(as
<T
>(), other
.as
<T
>());
286 /// Assign the content of \a other to this.
287 /// Destroys \a other.
288 template <typename T
>
290 build(variant
<S
>& other
)
297 /// Destroy the stored \a T.
298 template <typename T
>
302 as
<T
>().~T();]b4_assert_if([
306 /// A buffer large enough to store any of the semantic values.
312 #include "location.hh"
314 /* Enabling traces. */
316 # define YYDEBUG ]b4_debug_flag[
319 /* Enabling verbose error messages. */
320 #ifdef YYERROR_VERBOSE
321 # undef YYERROR_VERBOSE
322 # define YYERROR_VERBOSE 1
324 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
327 /* Enabling the token table. */
328 #ifndef YYTOKEN_TABLE
329 # define YYTOKEN_TABLE ]b4_token_table[
332 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
333 If N is 0, then set CURRENT to the empty location which ends
334 the previous symbol: RHS[0] (always defined). */
336 #ifndef YYLLOC_DEFAULT
337 # define YYLLOC_DEFAULT(Current, Rhs, N) \
341 (Current).begin = (Rhs)[1].location.begin; \
342 (Current).end = (Rhs)[N].location.end; \
346 (Current).begin = (Current).end = (Rhs)[0].location.end; \
354 class ]b4_parser_class_name
[
359 [ /// An auxiliary type to compute the largest semantic type.
361 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
364 /// Symbol semantic values.
365 typedef variant
<sizeof(union_type
)> semantic_type
;],
366 [ /// Symbol semantic values.
368 [ union semantic_type
371 [m4_if(b4_tag_seen_flag
, 0,
372 [[ typedef int semantic_type
;]],
373 [[ typedef YYSTYPE semantic_type
;]])])])[
375 typedef YYSTYPE semantic_type
;
377 /// Symbol locations.
378 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
382 ]b4_token_enums(b4_tokens
)[
385 typedef token::yytokentype token_type
;
387 /// Build a parser object.
388 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
389 virtual ~]b4_parser_class_name
[ ();
392 /// \returns 0 iff parsing succeeded.
393 virtual int parse ();
396 /// The current debugging stream.
397 std::ostream
& debug_stream () const;
398 /// Set the current debugging stream.
399 void set_debug_stream (std::ostream
&);
401 /// Type for debugging levels.
402 typedef int debug_level_type
;
403 /// The current debugging level.
404 debug_level_type
debug_level () const;
405 /// Set the current debugging level.
406 void set_debug_level (debug_level_type l
);
410 /// Report a syntax error.
411 /// \param loc where the syntax error is found.
412 /// \param msg a description of the syntax error.
413 virtual void error (const location_type
& loc
, const std::string
& msg
);
415 /// Generate an error message.
416 /// \param state the state where the error occurred.
417 /// \param tok the lookahead token.
418 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
421 typedef int state_type
;
423 /// Internal symbol numbers.
424 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
426 /// For a state, the index in \a yytable_ of its portion.
427 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
428 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
430 /// For a state, default rule to reduce.
431 /// Unless\a yytable_ specifies something else to do.
432 /// Zero means the default is an error.
433 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
435 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
436 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
438 /// What to do in a state.
439 /// \a yytable_[yypact_[s]]: what to do in state \a s.
440 /// - if positive, shift that token.
441 /// - if negative, reduce the rule which number is the opposite.
442 /// - if zero, do what YYDEFACT says.
443 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
444 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
446 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
448 /// For a state, its accessing symbol.
449 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
451 /// For a rule, its LHS.
452 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
453 /// For a rule, its RHS length.
454 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
456 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
457 /// For a symbol, its name in clear.
458 static const char* const yytname_
[];
462 /// Convert the symbol name \a n to a form suitable for a diagnostic.
463 virtual std::string
yytnamerr_ (const char *n
);
467 /// For each rule, its source line number.
468 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
469 /// For each scanner token number, its symbol number.
470 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
471 /// Report on the debug stream that the rule \a r is going to be reduced.
472 virtual void yy_reduce_print_ (int r
);
473 /// Print the state stack on the debug stream.
474 virtual void yystack_print_ ();
478 std::ostream
* yycdebug_
;
481 /// Convert a scanner token number \a t to a symbol number.
482 token_number_type
yytranslate_ (int t
);
484 /// A complete symbol, with its type.
485 template <typename Exact
>
486 struct symbol_base_type
488 /// Default constructor.
489 inline symbol_base_type ();
492 inline symbol_base_type (const semantic_type
& v
, const location_type
& l
);
494 /// Return this with its exact type.
495 const Exact
& self () const;
498 /// Return the type of this symbol.
499 int type_get () const;
501 /// The semantic value.
505 location_type location
;
509 /// \brief Display a symbol type, value and location.
510 /// \param yyo The output stream.
511 /// \param yysym The symbol.
512 template <typename Exact
>
513 void yy_print_ (std::ostream
& yyo
,
514 const symbol_base_type
<Exact
>& yysym
) const;
517 /// \brief Reclaim the memory associated to a symbol.
518 /// \param yymsg Why this token is reclaimed.
519 /// If null, print nothing.
520 /// \param s The symbol.
521 template <typename Exact
>
522 inline void yy_destroy_ (const char* yymsg
,
523 symbol_base_type
<Exact
>& yysym
) const;
525 /// Element of the stack: a state and its attributes.
526 struct symbol_type
: symbol_base_type
<symbol_type
>
528 /// The parent class.
529 typedef symbol_base_type
<symbol_type
> super_type
;
531 /// Default constructor.
532 inline symbol_type ();
535 inline symbol_type (int t
,
536 const semantic_type
& v
, const location_type
& l
);
541 /// Return the type corresponding to this state.
542 inline int type_get_ () const;
545 /// Element of the stack: a state and its attributes.
546 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
548 /// The parent class.
549 typedef symbol_base_type
<stack_symbol_type
> super_type
;
551 /// Default constructor.
552 inline stack_symbol_type ();
555 inline stack_symbol_type (state_type s
,
556 const semantic_type
& v
, const location_type
& l
);
561 /// Return the type corresponding to this state.
562 inline int type_get_ () const;
566 typedef stack
<stack_symbol_type
> stack_type
;
571 /// Push a new state on the stack.
572 /// \param m a debug message to display
573 /// if null, no trace is output.
574 /// \param s the symbol
575 /// \warning the contents of \a s.value is stolen.
576 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
578 /// Push a new look ahead token on the state on the stack.
579 /// \param m a debug message to display
580 /// if null, no trace is output.
581 /// \param s the state
582 /// \param sym the symbol (for its value and location).
583 /// \warning the contents of \a s.value is stolen.
584 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
586 /// Pop \a n symbols the three stacks.
587 inline void yypop_ (unsigned int n
= 1);
590 static const int yyeof_
;
591 /* LAST_ -- Last index in TABLE_. */
592 static const int yylast_
;
593 static const int yynnts_
;
594 static const int yyempty_
;
595 static const int yyfinal_
;
596 static const int yyterror_
;
597 static const int yyerrcode_
;
598 static const int yyntokens_
;
599 static const unsigned int yyuser_token_number_max_
;
600 static const token_number_type yyundef_token_
;
601 ]b4_parse_param_vars
[
606 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
607 [b4_token_defines(b4_tokens
)
610 /* Redirection for backward compatibility. */
611 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
614 b4_percent_code_get([[provides]])[]dnl
616 [#endif /* ! defined PARSER_HEADER_H */]
618 @
output(b4_parser_file_name@
)@
619 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
620 b4_percent_code_get([[top]])[]dnl
621 m4_if(b4_prefix
, [yy
], [],
623 // Take the name prefix into account.
624 #define yylex b4_prefix[]lex])[
626 /* First part of user declarations. */
627 ]b4_user_pre_prologue
630 #include "@basename(]b4_spec_defines_file[@)"]])[
632 /* User implementation prologue. */
633 ]b4_user_post_prologue
634 b4_percent_code_get
[]dnl
639 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
640 # define YY_(msgid) dgettext ("bison-runtime", msgid)
644 # define YY_(msgid) msgid
648 /* Suppress unused-variable warnings by "using" E. */
649 #define YYUSE(e) ((void) (e))
651 /* Enable debugging if requested. */
654 /* A pseudo ostream that takes yydebug_ into account. */
655 # define YYCDEBUG if (yydebug_) (*yycdebug_)
657 # define YY_SYMBOL_PRINT(Title, Symbol) \
661 *yycdebug_ << Title << ' '; \
662 yy_print_ (*yycdebug_, Symbol); \
663 *yycdebug_ << std::endl; \
667 # define YY_REDUCE_PRINT(Rule) \
670 yy_reduce_print_ (Rule); \
673 # define YY_STACK_PRINT() \
681 # define YYCDEBUG if (false) std::cerr
682 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
683 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
684 # define YY_STACK_PRINT() static_cast<void>(0)
686 #endif /* !YYDEBUG */
688 #define yyerrok (yyerrstatus_ = 0)
689 #define yyclearin (yychar = yyempty_)
691 #define YYACCEPT goto yyacceptlab
692 #define YYABORT goto yyabortlab
693 #define YYERROR goto yyerrorlab
694 #define YYRECOVERING() (!!yyerrstatus_)
699 /* Return YYSTR after stripping away unnecessary quotes and
700 backslashes, so that it's suitable for yyerror. The heuristic is
701 that double-quoting is unnecessary unless the string contains an
702 apostrophe, a comma, or backslash (other than backslash-backslash).
703 YYSTR is taken from yytname. */
705 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
709 std::string yyr
= "";
710 char const *yyp
= yystr
;
717 goto do_not_strip_quotes
;
721 goto do_not_strip_quotes
;
730 do_not_strip_quotes
: ;
738 /// Build a parser object.
739 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
742 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
743 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
744 #endif]b4_parse_param_cons[
748 ]b4_parser_class_name::~b4_parser_class_name
[ ()
758 template <typename Exact
>
759 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
765 template <typename Exact
>
766 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const semantic_type
& v
, const location_type
& l
)
772 template <typename Exact
>
774 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
776 return static_cast<const Exact
&>(*this);
779 template <typename Exact
>
781 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
783 return static_cast<Exact
&>(*this);
786 template <typename Exact
>
788 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
790 return self ().type_get_ ();
794 ]b4_parser_class_name
[::symbol_type::symbol_type ()
800 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
801 const semantic_type
& v
, const location_type
& l
)
808 ]b4_parser_class_name
[::symbol_type::type_get_ () const
813 // stack_symbol_type.
814 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
820 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (state_type s
,
821 const semantic_type
& v
, const location_type
& l
)
828 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
830 return yystos_
[state
];
834 template <typename Exact
>
836 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
837 symbol_base_type
<Exact
>& yysym
) const
839 int yytype
= yysym
.type_get ();
842 YY_SYMBOL_PRINT (yymsg
, yysym
);
847 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
853 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
857 template <typename Exact
>
859 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
860 const symbol_base_type
<Exact
>& yysym
) const
862 int yytype
= yysym
.type_get ();
863 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
864 << ' ' << yytname_
[yytype
] << " ("
865 << yysym
.location
<< ": ";
868 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
877 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
881 YY_SYMBOL_PRINT (m
, sym
);
883 [[ yystack_
.push (stack_symbol_type (s
, semantic_type(), sym
.location
));
884 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
885 [build
], [sym
.value
])],
886 [ yystack_
.push (stack_symbol_type (s
, sym
.value
, sym
.location
));])[
890 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
893 YY_SYMBOL_PRINT (m
, s
);
895 [[ yystack_
.push (stack_symbol_type (s
.state
, semantic_type(), s
.location
));
896 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
897 [build
], [s
.value
])],
898 [ yystack_
.push (s
);])[
902 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
909 ]b4_parser_class_name
[::debug_stream () const
915 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
921 ]b4_parser_class_name
[::debug_level_type
922 ]b4_parser_class_name
[::debug_level () const
928 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
935 ]b4_parser_class_name
[::parse ()
937 /// Coded type of the lookahead.
938 int yychar
= yyempty_
;
945 /* Error handling. */
947 int yyerrstatus_
= 0;
949 /// The lookahead symbol.
952 /// The locations where the error started and ended.
953 stack_symbol_type yyerror_range
[2];
956 stack_symbol_type yylhs
;
958 /// The return value of parse().
961 YYCDEBUG
<< "Starting parse" << std::endl
;
963 ]m4_ifdef([b4_initial_action
], [
964 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
965 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
966 /* User initialization code. */
967 b4_user_initial_action
968 m4_popdef([b4_dollar_dollar
])dnl
969 m4_popdef([b4_at_dollar
])])dnl
971 [ /* Initialize the stack. The initial state will be set in
972 yynewstate, since the latter expects the semantical and the
973 location values to have been already stored, initialize these
974 stacks with a primary value. */
975 yystack_
= stack_type (0);
976 yypush_ (0, 0, yyla
);
978 // A new state was pushed on the stack.
979 // Invariant: yystate == yystack_[0].state, i.e.,
980 // yystate was just pushed onto the state stack.
982 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
985 if (yystate
== yyfinal_
)
993 /* Try to take a decision without lookahead. */
994 yyn
= yypact_
[yystate
];
995 if (yyn
== yypact_ninf_
)
998 /* Read a lookahead token. */
999 if (yychar
== yyempty_
)
1001 YYCDEBUG
<< "Reading a token: ";
1002 yychar
= ]b4_c_function_call([yylex
], [int],
1003 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1004 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1005 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
1009 /* Convert token to internal form. */
1010 if (yychar
<= yyeof_
)
1012 yychar
= yyla
.type
= yyeof_
;
1013 YYCDEBUG
<< "Now at end of input." << std::endl
;
1017 yyla
.type
= yytranslate_ (yychar
);
1018 YY_SYMBOL_PRINT ("Next token is", yyla
);
1021 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1022 to detect an error, take that action. */
1024 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1027 /* Reduce or error. */
1028 yyn
= yytable_
[yyn
];
1031 if (yyn
== 0 || yyn
== yytable_ninf_
)
1037 /* Discard the token being shifted. */
1040 /* Count tokens shifted since error; after three, turn off error
1045 /* Shift the lookahead token. */
1047 yypush_ ("Shifting", yystate
, yyla
);
1050 /*-----------------------------------------------------------.
1051 | yydefault -- do the default action for the current state. |
1052 `-----------------------------------------------------------*/
1054 yyn
= yydefact_
[yystate
];
1059 /*-----------------------------.
1060 | yyreduce -- Do a reduction. |
1061 `-----------------------------*/
1063 yylen
= yyr2_
[yyn
];]b4_variant_if([
1064 /* Variants are always initialized to an empty instance of the
1065 correct type. The default $$=$1 rule is NOT applied when using
1067 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1068 /* If YYLEN is nonzero, implement the default value of the action:
1069 `$$ = $1'. Otherwise, use the top of the stack.
1071 Otherwise, the following line sets YYLHS.VALUE to garbage.
1072 This behavior is undocumented and Bison
1073 users should not rely upon it. */
1075 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1077 yylhs
.value
= yystack_@
{0@
}.value
;])[
1079 // Compute the default @@$.
1081 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1082 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1085 // Perform the reduction.
1086 YY_REDUCE_PRINT (yyn
);
1093 // Compute post-reduction state.
1095 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1096 if (0 <= yystate
&& yystate
<= yylast_
1097 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1098 yystate
= yytable_
[yystate
];
1100 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1101 yylhs
.state
= yystate
;
1102 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1104 // Destroy the lhs symbols.
1105 for (int i
= 0; i
< yylen
; ++i
)
1106 // Destroy a variant which value may have be swapped with
1107 // yylhs.value. The value of yylhs.value (hence maybe one of
1108 // these lhs symbols) depends on what does the default
1109 // contruction for this type. In the case of pointers for
1110 // instance, nothing is done, so the value is junk. Therefore
1111 // do not try to report the content in the debug trace, it's
1112 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1113 // traces as with the other Bison skeletons.
1114 yy_destroy_ (0, yystack_
[i
]);]])[
1120 /* Shift the result of the reduction. */
1124 /*------------------------------------.
1125 | yyerrlab -- here on detecting error |
1126 `------------------------------------*/
1128 /* If not already recovering from an error, report this error. */
1132 error (yyla
.location
, yysyntax_error_ (yystate
, yyla
.type
));
1135 yyerror_range
[0].location
= yyla
.location
;
1136 if (yyerrstatus_
== 3)
1138 /* If just tried and failed to reuse lookahead token after an
1139 error, discard it. */
1141 if (yychar
<= yyeof_
)
1143 /* Return failure if at end of input. */
1144 if (yychar
== yyeof_
)
1149 yy_destroy_ ("Error: discarding", yyla
);
1154 /* Else will try to reuse lookahead token after shifting the error
1159 /*---------------------------------------------------.
1160 | yyerrorlab -- error raised explicitly by YYERROR. |
1161 `---------------------------------------------------*/
1164 /* Pacify compilers like GCC when the user code never invokes
1165 YYERROR and the label yyerrorlab therefore never appears in user
1170 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1171 /* Do not reclaim the symbols of the rule which action triggered
1175 yystate
= yystack_
[0].state
;
1178 /*-------------------------------------------------------------.
1179 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1180 `-------------------------------------------------------------*/
1182 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1184 stack_symbol_type error_token
;
1187 yyn
= yypact_
[yystate
];
1188 if (yyn
!= yypact_ninf_
)
1191 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1193 yyn
= yytable_
[yyn
];
1199 // Pop the current state because it cannot handle the error token.
1200 if (yystack_
.size () == 1)
1203 yyerror_range
[0].location
= yystack_
[0].location
;
1204 yy_destroy_ ("Error: popping", yystack_
[0]);
1206 yystate
= yystack_
[0].state
;
1210 yyerror_range
[1].location
= yyla
.location
;
1211 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1213 /* Shift the error token. */
1214 error_token
.state
= yystate
= yyn
;
1215 yypush_ ("Shifting", error_token
);
1230 if (yychar
!= yyempty_
)
1231 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1233 /* Do not reclaim the symbols of the rule which action triggered
1234 this YYABORT or YYACCEPT. */
1236 while (yystack_
.size () != 1)
1238 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1245 // Generate an error message.
1247 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1248 b4_error_verbose_if([ tok
])[)
1253 int yyn
= yypact_
[yystate
];
1254 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1256 /* Start YYX at -YYN if negative to avoid negative indexes in
1258 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1260 /* Stay within bounds of both yycheck and yytname. */
1261 int yychecklim
= yylast_
- yyn
+ 1;
1262 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1264 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1265 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1268 // FIXME: This method of building the message is not compatible
1269 // with internationalization. It should work like yacc.c does it.
1270 // That is, first build a string that looks like this:
1271 // "syntax error, unexpected %s or %s or %s"
1272 // Then, invoke YY_ on this string.
1273 // Finally, use the string as a format to output
1274 // yytname_[tok], etc.
1275 // Until this gets fixed, this message appears in English only.
1276 res
= "syntax error, unexpected ";
1277 res
+= yytnamerr_ (yytname_
[tok
]);
1281 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1282 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1284 res
+= (!count
++) ? ", expecting " : " or ";
1285 res
+= yytnamerr_ (yytname_
[x
]);
1291 res
= YY_("syntax error");
1296 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1298 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1299 ]b4_table_define([pact
], [b4_pact
])[;
1301 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1302 doesn't specify something else to do. Zero means the default is an
1304 ]b4_table_define([defact
], [b4_defact
])[;
1306 /* YYPGOTO[NTERM-NUM]. */
1307 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1309 /* YYDEFGOTO[NTERM-NUM]. */
1310 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1312 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1313 positive, shift that token. If negative, reduce the rule which
1314 number is the opposite. If zero, do what YYDEFACT says. */
1315 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1316 ]b4_table_define([table
], [b4_table
])[;
1319 ]b4_table_define([check
], [b4_check
])[;
1321 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1322 symbol of state STATE-NUM. */
1323 ]b4_table_define([stos
], [b4_stos
])[;
1326 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1328 ]b4_table_define([token_number
], [b4_toknum
])[;
1331 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1332 ]b4_table_define([r1
], [b4_r1
])[;
1334 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1335 ]b4_table_define([r2
], [b4_r2
])[;
1337 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1338 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1339 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1341 const ]b4_parser_class_name
[::yytname_
[] =
1348 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1349 ]b4_table_define([rline
], [b4_rline
])[;
1351 // Print the state stack on the debug stream.
1353 ]b4_parser_class_name
[::yystack_print_ ()
1355 *yycdebug_
<< "Stack now";
1356 for (stack_type::const_iterator
1357 i
= yystack_
.begin (),
1358 i_end
= yystack_
.end ();
1360 *yycdebug_
<< ' ' << i
->state
;
1361 *yycdebug_
<< std::endl
;
1364 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1366 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1368 unsigned int yylno
= yyrline_
[yyrule
];
1369 int yynrhs
= yyr2_
[yyrule
];
1370 /* Print the symbols being reduced, and their result. */
1371 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1372 << " (line " << yylno
<< "):" << std::endl
;
1373 /* The symbols being reduced. */
1374 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1375 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1376 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1380 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1381 ]b4_parser_class_name
[::token_number_type
1382 ]b4_parser_class_name
[::yytranslate_ (int t
)
1385 const token_number_type
1390 if ((unsigned int) t
<= yyuser_token_number_max_
)
1391 return translate_table
[t
];
1393 return yyundef_token_
;
1396 const int ]b4_parser_class_name
[::yyeof_
= 0;
1397 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1398 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1399 const int ]b4_parser_class_name
[::yyempty_
= -2;
1400 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1401 const int ]b4_parser_class_name
[::yyterror_
= 1;
1402 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1403 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1405 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1406 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1408 ]b4_namespace_close
[
1411 @
output(b4_dir_prefix
[]stack
.hh@
)@
1412 b4_copyright([Stack handling
for Bison parsers in C
++])[
1414 #ifndef BISON_STACK_HH
1415 # define BISON_STACK_HH
1420 template <class T
, class S
= std::deque
<T
> >
1425 // Hide our reversed order.
1426 typedef typename
S::reverse_iterator iterator
;
1427 typedef typename
S::const_reverse_iterator const_iterator
;
1433 stack (unsigned int n
) : seq_ (n
)
1439 operator [] (unsigned int i
)
1446 operator [] (unsigned int i
) const
1455 seq_
.push_front (t
);
1460 pop (unsigned int n
= 1)
1467 typename
S::size_type
1470 return seq_
.size ();
1473 inline const_iterator
begin () const { return seq_
.rbegin (); }
1474 inline const_iterator
end () const { return seq_
.rend (); }
1477 /// The wrapped container.
1481 /// Present a slice of the top of a stack.
1482 template <class T
, class S
= stack
<T
> >
1487 slice (const S
& stack
,
1488 unsigned int range
) : stack_ (stack
),
1495 operator [] (unsigned int i
) const
1497 return stack_
[range_
- i
];
1503 unsigned int range_
;
1505 ]b4_namespace_close
[
1507 #endif // not BISON_STACK_HH[]dnl
1510 m4_popdef([b4_copyright_years
])dnl