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_variant(YYTYPE, YYVAL, ACTION, [ARGS])
170 # ------------------------------------------------
171 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
173 m4_define([b4_symbol_variant
],
174 [m4_pushdef([b4_dollar_dollar
],
175 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
178 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
182 m4_popdef([b4_dollar_dollar
])dnl
186 # _b4_char_sizeof_counter
187 # -----------------------
188 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
189 m4_define([_b4_char_sizeof_counter
],
192 # _b4_char_sizeof_dummy
193 # ---------------------
194 # At each call return a new C++ identifier.
195 m4_define([_b4_char_sizeof_dummy
],
196 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
197 dummy
[]_b4_char_sizeof_counter
])
200 # b4_char_sizeof(SYMBOL-NUM)
201 # --------------------------
202 # To be mapped on the list of type names to produce:
204 # char dummy1[sizeof(type_name_1)];
205 # char dummy2[sizeof(type_name_2)];
207 # for defined type names.
208 # $3 is doubly-quoted, do not quote it again.
209 m4_define([b4_char_sizeof
],
210 [m4_ifval(b4_symbol([$
1], [type_name
]),
212 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type_name
])])@
}; // b4_symbol([$1], [tag])])dnl
216 m4_pushdef([b4_copyright_years
],
217 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
219 m4_define([b4_parser_class_name
],
220 [b4_percent_define_get([[parser_class_name]])])
222 # The header is mandatory.
224 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
226 # Backward compatibility.
227 m4_define([b4_location_constructors
])
228 m4_include(b4_pkgdatadir
/[location
.cc
])
230 # We do want M4 expansion after # for CPP macros.
234 [@
output(b4_spec_defines_file@
)@
235 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
236 dnl FIXME
: This is wrong
, we want computed header guards
.
238 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
240 #ifndef PARSER_HEADER_H
241 # define PARSER_HEADER_H
243 ]b4_percent_code_get([[requires]])[
245 ]b4_assert_if([#include <cassert>])[
255 /// A char[S] buffer to store and retrieve objects.
257 /// Sort of a variant, but does not keep track of the nature
258 /// of the stored data, since that knowledge is available
259 /// via the current state.
263 /// Whether something is contained.
266 /// Initially uninitialized.
271 /// Instantiate a \a T in here.
272 template <typename T
>
278 return *new (buffer
) T
;
281 /// Instantiate a \a T in here from \a t.
282 template <typename T
>
288 return *new (buffer
) T(t
);
291 /// Accessor to a built \a T.
292 template <typename T
>
297 return reinterpret_cast<T
&>(buffer
);
300 /// Const accessor to a built \a T (for %printer).
301 template <typename T
>
306 return reinterpret_cast<const T
&>(buffer
);
309 /// Swap the content with \a other.
310 template <typename T
>
312 swap(variant
<S
>& other
)
314 std::swap(as
<T
>(), other
.as
<T
>());
317 /// Assign the content of \a other to this.
318 /// Destroys \a other.
319 template <typename T
>
321 build(variant
<S
>& other
)
328 /// Destroy the stored \a T.
329 template <typename T
>
333 as
<T
>().~T();]b4_assert_if([
337 /// A buffer large enough to store any of the semantic values.
343 #include "location.hh"
345 /* Enabling traces. */
347 # define YYDEBUG ]b4_debug_flag[
350 /* Enabling verbose error messages. */
351 #ifdef YYERROR_VERBOSE
352 # undef YYERROR_VERBOSE
353 # define YYERROR_VERBOSE 1
355 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
358 /* Enabling the token table. */
359 #ifndef YYTOKEN_TABLE
360 # define YYTOKEN_TABLE ]b4_token_table[
363 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
364 If N is 0, then set CURRENT to the empty location which ends
365 the previous symbol: RHS[0] (always defined). */
367 #ifndef YYLLOC_DEFAULT
368 # define YYLLOC_DEFAULT(Current, Rhs, N) \
372 (Current).begin = (Rhs)[1].location.begin; \
373 (Current).end = (Rhs)[N].location.end; \
377 (Current).begin = (Current).end = (Rhs)[0].location.end; \
385 class ]b4_parser_class_name
[
390 [ /// An auxiliary type to compute the largest semantic type.
392 {]m4_map([b4_char_sizeof
], m4_defn([b4_symbol_numbers
]))[
395 /// Symbol semantic values.
396 typedef variant
<sizeof(union_type
)> semantic_type
;],
397 [ /// Symbol semantic values.
399 [ union semantic_type
402 [m4_if(b4_tag_seen_flag
, 0,
403 [[ typedef int semantic_type
;]],
404 [[ typedef YYSTYPE semantic_type
;]])])])[
406 typedef YYSTYPE semantic_type
;
408 /// Symbol locations.
409 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
413 ]b4_token_enums(b4_tokens
)[
416 typedef token::yytokentype token_type
;
418 /// Build a parser object.
419 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
420 virtual ~]b4_parser_class_name
[ ();
423 /// \returns 0 iff parsing succeeded.
424 virtual int parse ();
427 /// The current debugging stream.
428 std::ostream
& debug_stream () const;
429 /// Set the current debugging stream.
430 void set_debug_stream (std::ostream
&);
432 /// Type for debugging levels.
433 typedef int debug_level_type
;
434 /// The current debugging level.
435 debug_level_type
debug_level () const;
436 /// Set the current debugging level.
437 void set_debug_level (debug_level_type l
);
441 /// Report a syntax error.
442 /// \param loc where the syntax error is found.
443 /// \param msg a description of the syntax error.
444 virtual void error (const location_type
& loc
, const std::string
& msg
);
446 /// Generate an error message.
447 /// \param state the state where the error occurred.
448 /// \param tok the lookahead token.
449 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
452 typedef int state_type
;
454 /// Internal symbol numbers.
455 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
457 /// For a state, the index in \a yytable_ of its portion.
458 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
459 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
461 /// For a state, default rule to reduce.
462 /// Unless\a yytable_ specifies something else to do.
463 /// Zero means the default is an error.
464 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
466 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
467 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
469 /// What to do in a state.
470 /// \a yytable_[yypact_[s]]: what to do in state \a s.
471 /// - if positive, shift that token.
472 /// - if negative, reduce the rule which number is the opposite.
473 /// - if zero, do what YYDEFACT says.
474 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
475 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
477 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
479 /// For a state, its accessing symbol.
480 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
482 /// For a rule, its LHS.
483 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
484 /// For a rule, its RHS length.
485 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
487 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
488 /// For a symbol, its name in clear.
489 static const char* const yytname_
[];
493 /// Convert the symbol name \a n to a form suitable for a diagnostic.
494 virtual std::string
yytnamerr_ (const char *n
);
498 /// For each rule, its source line number.
499 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
500 /// For each scanner token number, its symbol number.
501 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
502 /// Report on the debug stream that the rule \a r is going to be reduced.
503 virtual void yy_reduce_print_ (int r
);
504 /// Print the state stack on the debug stream.
505 virtual void yystack_print_ ();
509 std::ostream
* yycdebug_
;
512 /// Convert a scanner token number \a t to a symbol number.
513 static inline token_number_type
yytranslate_ (int t
);
515 /// A complete symbol, with its type.
516 template <typename Exact
>
517 struct symbol_base_type
519 /// Default constructor.
520 inline symbol_base_type ();
523 inline symbol_base_type (const semantic_type
& v
, const location_type
& l
);
525 /// Return this with its exact type.
526 const Exact
& self () const;
529 /// Return the type of this symbol.
530 int type_get () const;
532 /// The semantic value.
536 location_type location
;
540 /// \brief Display a symbol type, value and location.
541 /// \param yyo The output stream.
542 /// \param yysym The symbol.
543 template <typename Exact
>
544 void yy_print_ (std::ostream
& yyo
,
545 const symbol_base_type
<Exact
>& yysym
) const;
548 /// \brief Reclaim the memory associated to a symbol.
549 /// \param yymsg Why this token is reclaimed.
550 /// If null, print nothing.
551 /// \param s The symbol.
552 template <typename Exact
>
553 inline void yy_destroy_ (const char* yymsg
,
554 symbol_base_type
<Exact
>& yysym
) const;
556 /// Element of the stack: a state and its attributes.
557 struct symbol_type
: symbol_base_type
<symbol_type
>
559 /// The parent class.
560 typedef symbol_base_type
<symbol_type
> super_type
;
562 /// Default constructor.
563 inline symbol_type ();
566 inline symbol_type (int t
,
567 const semantic_type
& v
, const location_type
& l
);
572 /// Return the type corresponding to this state.
573 inline int type_get_ () const;
576 /// Element of the stack: a state and its attributes.
577 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
579 /// The parent class.
580 typedef symbol_base_type
<stack_symbol_type
> super_type
;
582 /// Default constructor.
583 inline stack_symbol_type ();
586 inline stack_symbol_type (state_type s
,
587 const semantic_type
& v
, const location_type
& l
);
592 /// Return the type corresponding to this state.
593 inline int type_get_ () const;
597 typedef stack
<stack_symbol_type
> stack_type
;
602 /// Push a new state on the stack.
603 /// \param m a debug message to display
604 /// if null, no trace is output.
605 /// \param s the symbol
606 /// \warning the contents of \a s.value is stolen.
607 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
609 /// Push a new look ahead token on the state on the stack.
610 /// \param m a debug message to display
611 /// if null, no trace is output.
612 /// \param s the state
613 /// \param sym the symbol (for its value and location).
614 /// \warning the contents of \a s.value is stolen.
615 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
617 /// Pop \a n symbols the three stacks.
618 inline void yypop_ (unsigned int n
= 1);
624 yylast_
= ]b4_last
[, //< Last index in yytable_.
625 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
627 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
630 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
633 ]b4_parse_param_vars
[
638 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
639 [b4_token_defines(b4_tokens
)
642 /* Redirection for backward compatibility. */
643 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
646 b4_percent_code_get([[provides]])[]dnl
648 [#endif /* ! defined PARSER_HEADER_H */]
650 @
output(b4_parser_file_name@
)@
651 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
652 b4_percent_code_get([[top]])[]dnl
653 m4_if(b4_prefix
, [yy
], [],
655 // Take the name prefix into account.
656 #define yylex b4_prefix[]lex])[
658 /* First part of user declarations. */
659 ]b4_user_pre_prologue
662 #include "@basename(]b4_spec_defines_file[@)"]])[
664 /* User implementation prologue. */
665 ]b4_user_post_prologue
666 b4_percent_code_get
[]dnl
671 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
672 # define YY_(msgid) dgettext ("bison-runtime", msgid)
676 # define YY_(msgid) msgid
680 /* Suppress unused-variable warnings by "using" E. */
681 #define YYUSE(e) ((void) (e))
683 /* Enable debugging if requested. */
686 /* A pseudo ostream that takes yydebug_ into account. */
687 # define YYCDEBUG if (yydebug_) (*yycdebug_)
689 # define YY_SYMBOL_PRINT(Title, Symbol) \
693 *yycdebug_ << Title << ' '; \
694 yy_print_ (*yycdebug_, Symbol); \
695 *yycdebug_ << std::endl; \
699 # define YY_REDUCE_PRINT(Rule) \
702 yy_reduce_print_ (Rule); \
705 # define YY_STACK_PRINT() \
713 # define YYCDEBUG if (false) std::cerr
714 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
715 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
716 # define YY_STACK_PRINT() static_cast<void>(0)
718 #endif /* !YYDEBUG */
720 #define yyerrok (yyerrstatus_ = 0)
721 #define yyclearin (yychar = yyempty_)
723 #define YYACCEPT goto yyacceptlab
724 #define YYABORT goto yyabortlab
725 #define YYERROR goto yyerrorlab
726 #define YYRECOVERING() (!!yyerrstatus_)
731 /* Return YYSTR after stripping away unnecessary quotes and
732 backslashes, so that it's suitable for yyerror. The heuristic is
733 that double-quoting is unnecessary unless the string contains an
734 apostrophe, a comma, or backslash (other than backslash-backslash).
735 YYSTR is taken from yytname. */
737 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
741 std::string yyr
= "";
742 char const *yyp
= yystr
;
749 goto do_not_strip_quotes
;
753 goto do_not_strip_quotes
;
762 do_not_strip_quotes
: ;
770 /// Build a parser object.
771 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
774 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
775 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
776 #endif]b4_parse_param_cons[
780 ]b4_parser_class_name::~b4_parser_class_name
[ ()
790 template <typename Exact
>
791 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
797 template <typename Exact
>
798 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const semantic_type
& v
, const location_type
& l
)
804 template <typename Exact
>
806 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
808 return static_cast<const Exact
&>(*this);
811 template <typename Exact
>
813 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
815 return static_cast<Exact
&>(*this);
818 template <typename Exact
>
820 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
822 return self ().type_get_ ();
826 ]b4_parser_class_name
[::symbol_type::symbol_type ()
832 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
833 const semantic_type
& v
, const location_type
& l
)
840 ]b4_parser_class_name
[::symbol_type::type_get_ () const
845 // stack_symbol_type.
846 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
852 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (state_type s
,
853 const semantic_type
& v
, const location_type
& l
)
860 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
862 return yystos_
[state
];
866 template <typename Exact
>
868 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
869 symbol_base_type
<Exact
>& yysym
) const
871 int yytype
= yysym
.type_get ();
874 YY_SYMBOL_PRINT (yymsg
, yysym
);
879 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
885 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
889 template <typename Exact
>
891 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
892 const symbol_base_type
<Exact
>& yysym
) const
894 int yytype
= yysym
.type_get ();
895 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
896 << ' ' << yytname_
[yytype
] << " ("
897 << yysym
.location
<< ": ";
900 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
909 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
913 YY_SYMBOL_PRINT (m
, sym
);
915 [[ yystack_
.push (stack_symbol_type (s
, semantic_type(), sym
.location
));
916 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
917 [build
], [sym
.value
])],
918 [ yystack_
.push (stack_symbol_type (s
, sym
.value
, sym
.location
));])[
922 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
925 YY_SYMBOL_PRINT (m
, s
);
927 [[ yystack_
.push (stack_symbol_type (s
.state
, semantic_type(), s
.location
));
928 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
929 [build
], [s
.value
])],
930 [ yystack_
.push (s
);])[
934 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
941 ]b4_parser_class_name
[::debug_stream () const
947 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
953 ]b4_parser_class_name
[::debug_level_type
954 ]b4_parser_class_name
[::debug_level () const
960 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
967 ]b4_parser_class_name
[::parse ()
969 /// Coded type of the lookahead.
970 int yychar
= yyempty_
;
977 /* Error handling. */
979 int yyerrstatus_
= 0;
981 /// The lookahead symbol.
984 /// The locations where the error started and ended.
985 stack_symbol_type yyerror_range
[2];
988 stack_symbol_type yylhs
;
990 /// The return value of parse().
993 YYCDEBUG
<< "Starting parse" << std::endl
;
995 ]m4_ifdef([b4_initial_action
], [
996 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
997 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
998 /* User initialization code. */
999 b4_user_initial_action
1000 m4_popdef([b4_dollar_dollar
])dnl
1001 m4_popdef([b4_at_dollar
])])dnl
1003 [ /* Initialize the stack. The initial state will be set in
1004 yynewstate, since the latter expects the semantical and the
1005 location values to have been already stored, initialize these
1006 stacks with a primary value. */
1007 yystack_
= stack_type (0);
1008 yypush_ (0, 0, yyla
);
1010 // A new state was pushed on the stack.
1011 // Invariant: yystate == yystack_[0].state, i.e.,
1012 // yystate was just pushed onto the state stack.
1014 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1017 if (yystate
== yyfinal_
)
1025 /* Try to take a decision without lookahead. */
1026 yyn
= yypact_
[yystate
];
1027 if (yyn
== yypact_ninf_
)
1030 /* Read a lookahead token. */
1031 if (yychar
== yyempty_
)
1033 YYCDEBUG
<< "Reading a token: ";
1034 yychar
= ]b4_c_function_call([yylex
], [int],
1035 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1036 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1037 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
1041 /* Convert token to internal form. */
1042 if (yychar
<= yyeof_
)
1044 yychar
= yyla
.type
= yyeof_
;
1045 YYCDEBUG
<< "Now at end of input." << std::endl
;
1049 yyla
.type
= yytranslate_ (yychar
);
1050 YY_SYMBOL_PRINT ("Next token is", yyla
);
1053 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1054 to detect an error, take that action. */
1056 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1059 /* Reduce or error. */
1060 yyn
= yytable_
[yyn
];
1063 if (yyn
== 0 || yyn
== yytable_ninf_
)
1069 /* Discard the token being shifted. */
1072 /* Count tokens shifted since error; after three, turn off error
1077 /* Shift the lookahead token. */
1079 yypush_ ("Shifting", yystate
, yyla
);
1082 /*-----------------------------------------------------------.
1083 | yydefault -- do the default action for the current state. |
1084 `-----------------------------------------------------------*/
1086 yyn
= yydefact_
[yystate
];
1091 /*-----------------------------.
1092 | yyreduce -- Do a reduction. |
1093 `-----------------------------*/
1095 yylen
= yyr2_
[yyn
];]b4_variant_if([
1096 /* Variants are always initialized to an empty instance of the
1097 correct type. The default $$=$1 rule is NOT applied when using
1099 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1100 /* If YYLEN is nonzero, implement the default value of the action:
1101 `$$ = $1'. Otherwise, use the top of the stack.
1103 Otherwise, the following line sets YYLHS.VALUE to garbage.
1104 This behavior is undocumented and Bison
1105 users should not rely upon it. */
1107 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1109 yylhs
.value
= yystack_@
{0@
}.value
;])[
1111 // Compute the default @@$.
1113 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1114 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1117 // Perform the reduction.
1118 YY_REDUCE_PRINT (yyn
);
1125 // Compute post-reduction state.
1127 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1128 if (0 <= yystate
&& yystate
<= yylast_
1129 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1130 yystate
= yytable_
[yystate
];
1132 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1133 yylhs
.state
= yystate
;
1134 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1136 // Destroy the lhs symbols.
1137 for (int i
= 0; i
< yylen
; ++i
)
1138 // Destroy a variant which value may have be swapped with
1139 // yylhs.value. The value of yylhs.value (hence maybe one of
1140 // these lhs symbols) depends on what does the default
1141 // contruction for this type. In the case of pointers for
1142 // instance, nothing is done, so the value is junk. Therefore
1143 // do not try to report the content in the debug trace, it's
1144 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1145 // traces as with the other Bison skeletons.
1146 yy_destroy_ (0, yystack_
[i
]);]])[
1152 /* Shift the result of the reduction. */
1156 /*------------------------------------.
1157 | yyerrlab -- here on detecting error |
1158 `------------------------------------*/
1160 /* If not already recovering from an error, report this error. */
1164 error (yyla
.location
, yysyntax_error_ (yystate
, yyla
.type
));
1167 yyerror_range
[0].location
= yyla
.location
;
1168 if (yyerrstatus_
== 3)
1170 /* If just tried and failed to reuse lookahead token after an
1171 error, discard it. */
1173 if (yychar
<= yyeof_
)
1175 /* Return failure if at end of input. */
1176 if (yychar
== yyeof_
)
1181 yy_destroy_ ("Error: discarding", yyla
);
1186 /* Else will try to reuse lookahead token after shifting the error
1191 /*---------------------------------------------------.
1192 | yyerrorlab -- error raised explicitly by YYERROR. |
1193 `---------------------------------------------------*/
1196 /* Pacify compilers like GCC when the user code never invokes
1197 YYERROR and the label yyerrorlab therefore never appears in user
1202 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1203 /* Do not reclaim the symbols of the rule which action triggered
1207 yystate
= yystack_
[0].state
;
1210 /*-------------------------------------------------------------.
1211 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1212 `-------------------------------------------------------------*/
1214 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1216 stack_symbol_type error_token
;
1219 yyn
= yypact_
[yystate
];
1220 if (yyn
!= yypact_ninf_
)
1223 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1225 yyn
= yytable_
[yyn
];
1231 // Pop the current state because it cannot handle the error token.
1232 if (yystack_
.size () == 1)
1235 yyerror_range
[0].location
= yystack_
[0].location
;
1236 yy_destroy_ ("Error: popping", yystack_
[0]);
1238 yystate
= yystack_
[0].state
;
1242 yyerror_range
[1].location
= yyla
.location
;
1243 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1245 /* Shift the error token. */
1246 error_token
.state
= yystate
= yyn
;
1247 yypush_ ("Shifting", error_token
);
1262 if (yychar
!= yyempty_
)
1263 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1265 /* Do not reclaim the symbols of the rule which action triggered
1266 this YYABORT or YYACCEPT. */
1268 while (yystack_
.size () != 1)
1270 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1277 // Generate an error message.
1279 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1280 b4_error_verbose_if([ tok
])[)
1285 int yyn
= yypact_
[yystate
];
1286 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1288 /* Start YYX at -YYN if negative to avoid negative indexes in
1290 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1292 /* Stay within bounds of both yycheck and yytname. */
1293 int yychecklim
= yylast_
- yyn
+ 1;
1294 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1296 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1297 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1300 // FIXME: This method of building the message is not compatible
1301 // with internationalization. It should work like yacc.c does it.
1302 // That is, first build a string that looks like this:
1303 // "syntax error, unexpected %s or %s or %s"
1304 // Then, invoke YY_ on this string.
1305 // Finally, use the string as a format to output
1306 // yytname_[tok], etc.
1307 // Until this gets fixed, this message appears in English only.
1308 res
= "syntax error, unexpected ";
1309 res
+= yytnamerr_ (yytname_
[tok
]);
1313 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1314 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1316 res
+= (!count
++) ? ", expecting " : " or ";
1317 res
+= yytnamerr_ (yytname_
[x
]);
1323 res
= YY_("syntax error");
1328 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1330 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1331 ]b4_table_define([pact
], [b4_pact
])[;
1333 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1334 doesn't specify something else to do. Zero means the default is an
1336 ]b4_table_define([defact
], [b4_defact
])[;
1338 /* YYPGOTO[NTERM-NUM]. */
1339 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1341 /* YYDEFGOTO[NTERM-NUM]. */
1342 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1344 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1345 positive, shift that token. If negative, reduce the rule which
1346 number is the opposite. If zero, do what YYDEFACT says. */
1347 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1348 ]b4_table_define([table
], [b4_table
])[;
1351 ]b4_table_define([check
], [b4_check
])[;
1353 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1354 symbol of state STATE-NUM. */
1355 ]b4_table_define([stos
], [b4_stos
])[;
1358 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1360 ]b4_table_define([token_number
], [b4_toknum
])[;
1363 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1364 ]b4_table_define([r1
], [b4_r1
])[;
1366 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1367 ]b4_table_define([r2
], [b4_r2
])[;
1369 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1370 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1371 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1373 const ]b4_parser_class_name
[::yytname_
[] =
1380 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1381 ]b4_table_define([rline
], [b4_rline
])[;
1383 // Print the state stack on the debug stream.
1385 ]b4_parser_class_name
[::yystack_print_ ()
1387 *yycdebug_
<< "Stack now";
1388 for (stack_type::const_iterator
1389 i
= yystack_
.begin (),
1390 i_end
= yystack_
.end ();
1392 *yycdebug_
<< ' ' << i
->state
;
1393 *yycdebug_
<< std::endl
;
1396 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1398 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1400 unsigned int yylno
= yyrline_
[yyrule
];
1401 int yynrhs
= yyr2_
[yyrule
];
1402 /* Print the symbols being reduced, and their result. */
1403 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1404 << " (line " << yylno
<< "):" << std::endl
;
1405 /* The symbols being reduced. */
1406 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1407 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1408 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1412 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1413 ]b4_parser_class_name
[::token_number_type
1414 ]b4_parser_class_name
[::yytranslate_ (int t
)
1417 const token_number_type
1422 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
1423 const token_number_type undef_token_
= ]b4_undef_token_number
[;
1425 if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
1426 return translate_table
[t
];
1428 return undef_token_
;
1431 ]b4_namespace_close
[
1434 @
output(b4_dir_prefix
[]stack
.hh@
)@
1435 b4_copyright([Stack handling
for Bison parsers in C
++])[
1437 #ifndef BISON_STACK_HH
1438 # define BISON_STACK_HH
1443 template <class T
, class S
= std::deque
<T
> >
1448 // Hide our reversed order.
1449 typedef typename
S::reverse_iterator iterator
;
1450 typedef typename
S::const_reverse_iterator const_iterator
;
1456 stack (unsigned int n
) : seq_ (n
)
1462 operator [] (unsigned int i
)
1469 operator [] (unsigned int i
) const
1478 seq_
.push_front (t
);
1483 pop (unsigned int n
= 1)
1490 typename
S::size_type
1493 return seq_
.size ();
1496 inline const_iterator
begin () const { return seq_
.rbegin (); }
1497 inline const_iterator
end () const { return seq_
.rend (); }
1500 /// The wrapped container.
1504 /// Present a slice of the top of a stack.
1505 template <class T
, class S
= stack
<T
> >
1510 slice (const S
& stack
,
1511 unsigned int range
) : stack_ (stack
),
1518 operator [] (unsigned int i
) const
1520 return stack_
[range_
- i
];
1526 unsigned int range_
;
1528 ]b4_namespace_close
[
1530 #endif // not BISON_STACK_HH[]dnl
1533 m4_popdef([b4_copyright_years
])dnl