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_actions(FILENAME, LINENO,
117 # SYMBOL-TAG, SYMBOL-NUM,
118 # SYMBOL-ACTION, SYMBOL-TYPENAME)
119 # -------------------------------------------------
120 # Same as in C, but using references instead of pointers.
121 m4_define([b4_symbol_actions
],
122 [m4_pushdef([b4_dollar_dollar
],
123 [b4_symbol_value_template([yysym
.value
], [$
6])])dnl
124 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
126 b4_syncline([$
2], [$
1])
128 b4_syncline([@oline@
], [@ofile@
])
130 m4_popdef([b4_at_dollar
])dnl
131 m4_popdef([b4_dollar_dollar
])dnl
135 # b4_symbol_action_(NUM)
136 # ----------------------
137 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
138 m4_define([b4_symbol_action_
],
139 [m4_ifval(b4_symbol([$
1], [type_name
]),
140 [ case b4_symbol([$
1], [number
]): // b4_symbol([$1], [tag])
141 b4_dollar_dollar([b4_symbol([$
1], [number
])],
142 [b4_symbol([$
1], [tag
])],
143 [b4_symbol([$
1], [type_name
])]);
148 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
149 # ------------------------------------------------
150 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
152 m4_define([b4_symbol_variant
],
153 [m4_pushdef([b4_dollar_dollar
],
154 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
157 m4_map([b4_symbol_action_
], m4_defn([b4_symbol_numbers
]))
161 m4_popdef([b4_dollar_dollar
])dnl
165 # _b4_char_sizeof_counter
166 # -----------------------
167 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
168 m4_define([_b4_char_sizeof_counter
],
171 # _b4_char_sizeof_dummy
172 # ---------------------
173 # At each call return a new C++ identifier.
174 m4_define([_b4_char_sizeof_dummy
],
175 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
176 dummy
[]_b4_char_sizeof_counter
])
179 # b4_char_sizeof(SYMBOL-NUM)
180 # --------------------------
181 # To be mapped on the list of type names to produce:
183 # char dummy1[sizeof(type_name_1)];
184 # char dummy2[sizeof(type_name_2)];
186 # for defined type names.
187 # $3 is doubly-quoted, do not quote it again.
188 m4_define([b4_char_sizeof
],
189 [m4_ifval(b4_symbol([$
1], [type_name
]),
191 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type_name
])])@
}; // b4_symbol([$1], [tag])])dnl
195 m4_pushdef([b4_copyright_years
],
196 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
198 m4_define([b4_parser_class_name
],
199 [b4_percent_define_get([[parser_class_name]])])
201 # The header is mandatory.
203 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
205 # Backward compatibility.
206 m4_define([b4_location_constructors
])
207 m4_include(b4_pkgdatadir
/[location
.cc
])
209 # We do want M4 expansion after # for CPP macros.
213 [@
output(b4_spec_defines_file@
)@
214 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
215 dnl FIXME
: This is wrong
, we want computed header guards
.
217 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
219 #ifndef PARSER_HEADER_H
220 # define PARSER_HEADER_H
222 ]b4_percent_code_get([[requires]])[
224 ]b4_assert_if([#include <cassert>])[
234 /// A char[S] buffer to store and retrieve objects.
236 /// Sort of a variant, but does not keep track of the nature
237 /// of the stored data, since that knowledge is available
238 /// via the current state.
242 /// Whether something is contained.
245 /// Initially uninitialized.
250 /// Instantiate a \a T in here.
251 template <typename T
>
257 return *new (buffer
) T
;
260 /// Instantiate a \a T in here from \a t.
261 template <typename T
>
267 return *new (buffer
) T(t
);
270 /// Accessor to a built \a T.
271 template <typename T
>
276 return reinterpret_cast<T
&>(buffer
);
279 /// Const accessor to a built \a T (for %printer).
280 template <typename T
>
285 return reinterpret_cast<const T
&>(buffer
);
288 /// Swap the content with \a other.
289 template <typename T
>
291 swap(variant
<S
>& other
)
293 std::swap(as
<T
>(), other
.as
<T
>());
296 /// Assign the content of \a other to this.
297 /// Destroys \a other.
298 template <typename T
>
300 build(variant
<S
>& other
)
307 /// Destroy the stored \a T.
308 template <typename T
>
312 as
<T
>().~T();]b4_assert_if([
316 /// A buffer large enough to store any of the semantic values.
322 #include "location.hh"
324 /* Enabling traces. */
326 # define YYDEBUG ]b4_debug_flag[
329 /* Enabling verbose error messages. */
330 #ifdef YYERROR_VERBOSE
331 # undef YYERROR_VERBOSE
332 # define YYERROR_VERBOSE 1
334 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
337 /* Enabling the token table. */
338 #ifndef YYTOKEN_TABLE
339 # define YYTOKEN_TABLE ]b4_token_table[
342 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
343 If N is 0, then set CURRENT to the empty location which ends
344 the previous symbol: RHS[0] (always defined). */
346 #ifndef YYLLOC_DEFAULT
347 # define YYLLOC_DEFAULT(Current, Rhs, N) \
351 (Current).begin = (Rhs)[1].location.begin; \
352 (Current).end = (Rhs)[N].location.end; \
356 (Current).begin = (Current).end = (Rhs)[0].location.end; \
364 class ]b4_parser_class_name
[
369 [ /// An auxiliary type to compute the largest semantic type.
371 {]m4_map([b4_char_sizeof
], m4_defn([b4_symbol_numbers
]))[
374 /// Symbol semantic values.
375 typedef variant
<sizeof(union_type
)> semantic_type
;],
376 [ /// Symbol semantic values.
378 [ union semantic_type
381 [m4_if(b4_tag_seen_flag
, 0,
382 [[ typedef int semantic_type
;]],
383 [[ typedef YYSTYPE semantic_type
;]])])])[
385 typedef YYSTYPE semantic_type
;
387 /// Symbol locations.
388 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
392 ]b4_token_enums(b4_tokens
)[
395 typedef token::yytokentype token_type
;
397 /// Build a parser object.
398 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
399 virtual ~]b4_parser_class_name
[ ();
402 /// \returns 0 iff parsing succeeded.
403 virtual int parse ();
406 /// The current debugging stream.
407 std::ostream
& debug_stream () const;
408 /// Set the current debugging stream.
409 void set_debug_stream (std::ostream
&);
411 /// Type for debugging levels.
412 typedef int debug_level_type
;
413 /// The current debugging level.
414 debug_level_type
debug_level () const;
415 /// Set the current debugging level.
416 void set_debug_level (debug_level_type l
);
420 /// Report a syntax error.
421 /// \param loc where the syntax error is found.
422 /// \param msg a description of the syntax error.
423 virtual void error (const location_type
& loc
, const std::string
& msg
);
425 /// Generate an error message.
426 /// \param state the state where the error occurred.
427 /// \param tok the lookahead token.
428 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
431 typedef int state_type
;
433 /// Internal symbol numbers.
434 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
436 /// For a state, the index in \a yytable_ of its portion.
437 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
438 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
440 /// For a state, default rule to reduce.
441 /// Unless\a yytable_ specifies something else to do.
442 /// Zero means the default is an error.
443 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
445 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
446 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
448 /// What to do in a state.
449 /// \a yytable_[yypact_[s]]: what to do in state \a s.
450 /// - if positive, shift that token.
451 /// - if negative, reduce the rule which number is the opposite.
452 /// - if zero, do what YYDEFACT says.
453 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
454 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
456 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
458 /// For a state, its accessing symbol.
459 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
461 /// For a rule, its LHS.
462 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
463 /// For a rule, its RHS length.
464 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
466 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
467 /// For a symbol, its name in clear.
468 static const char* const yytname_
[];
472 /// Convert the symbol name \a n to a form suitable for a diagnostic.
473 virtual std::string
yytnamerr_ (const char *n
);
477 /// For each rule, its source line number.
478 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
479 /// For each scanner token number, its symbol number.
480 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
481 /// Report on the debug stream that the rule \a r is going to be reduced.
482 virtual void yy_reduce_print_ (int r
);
483 /// Print the state stack on the debug stream.
484 virtual void yystack_print_ ();
488 std::ostream
* yycdebug_
;
491 /// Convert a scanner token number \a t to a symbol number.
492 token_number_type
yytranslate_ (int t
);
494 /// A complete symbol, with its type.
495 template <typename Exact
>
496 struct symbol_base_type
498 /// Default constructor.
499 inline symbol_base_type ();
502 inline symbol_base_type (const semantic_type
& v
, const location_type
& l
);
504 /// Return this with its exact type.
505 const Exact
& self () const;
508 /// Return the type of this symbol.
509 int type_get () const;
511 /// The semantic value.
515 location_type location
;
519 /// \brief Display a symbol type, value and location.
520 /// \param yyo The output stream.
521 /// \param yysym The symbol.
522 template <typename Exact
>
523 void yy_print_ (std::ostream
& yyo
,
524 const symbol_base_type
<Exact
>& yysym
) const;
527 /// \brief Reclaim the memory associated to a symbol.
528 /// \param yymsg Why this token is reclaimed.
529 /// If null, print nothing.
530 /// \param s The symbol.
531 template <typename Exact
>
532 inline void yy_destroy_ (const char* yymsg
,
533 symbol_base_type
<Exact
>& yysym
) const;
535 /// Element of the stack: a state and its attributes.
536 struct symbol_type
: symbol_base_type
<symbol_type
>
538 /// The parent class.
539 typedef symbol_base_type
<symbol_type
> super_type
;
541 /// Default constructor.
542 inline symbol_type ();
545 inline symbol_type (int t
,
546 const semantic_type
& v
, const location_type
& l
);
551 /// Return the type corresponding to this state.
552 inline int type_get_ () const;
555 /// Element of the stack: a state and its attributes.
556 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
558 /// The parent class.
559 typedef symbol_base_type
<stack_symbol_type
> super_type
;
561 /// Default constructor.
562 inline stack_symbol_type ();
565 inline stack_symbol_type (state_type s
,
566 const semantic_type
& v
, const location_type
& l
);
571 /// Return the type corresponding to this state.
572 inline int type_get_ () const;
576 typedef stack
<stack_symbol_type
> stack_type
;
581 /// Push a new state on the stack.
582 /// \param m a debug message to display
583 /// if null, no trace is output.
584 /// \param s the symbol
585 /// \warning the contents of \a s.value is stolen.
586 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
588 /// Push a new look ahead token on the state on the stack.
589 /// \param m a debug message to display
590 /// if null, no trace is output.
591 /// \param s the state
592 /// \param sym the symbol (for its value and location).
593 /// \warning the contents of \a s.value is stolen.
594 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
596 /// Pop \a n symbols the three stacks.
597 inline void yypop_ (unsigned int n
= 1);
600 static const int yyeof_
;
601 /* LAST_ -- Last index in TABLE_. */
602 static const int yylast_
;
603 static const int yynnts_
;
604 static const int yyempty_
;
605 static const int yyfinal_
;
606 static const int yyterror_
;
607 static const int yyerrcode_
;
608 static const int yyntokens_
;
609 static const unsigned int yyuser_token_number_max_
;
610 static const token_number_type yyundef_token_
;
611 ]b4_parse_param_vars
[
616 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
617 [b4_token_defines(b4_tokens
)
620 /* Redirection for backward compatibility. */
621 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
624 b4_percent_code_get([[provides]])[]dnl
626 [#endif /* ! defined PARSER_HEADER_H */]
628 @
output(b4_parser_file_name@
)@
629 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
630 b4_percent_code_get([[top]])[]dnl
631 m4_if(b4_prefix
, [yy
], [],
633 // Take the name prefix into account.
634 #define yylex b4_prefix[]lex])[
636 /* First part of user declarations. */
637 ]b4_user_pre_prologue
640 #include "@basename(]b4_spec_defines_file[@)"]])[
642 /* User implementation prologue. */
643 ]b4_user_post_prologue
644 b4_percent_code_get
[]dnl
649 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
650 # define YY_(msgid) dgettext ("bison-runtime", msgid)
654 # define YY_(msgid) msgid
658 /* Suppress unused-variable warnings by "using" E. */
659 #define YYUSE(e) ((void) (e))
661 /* Enable debugging if requested. */
664 /* A pseudo ostream that takes yydebug_ into account. */
665 # define YYCDEBUG if (yydebug_) (*yycdebug_)
667 # define YY_SYMBOL_PRINT(Title, Symbol) \
671 *yycdebug_ << Title << ' '; \
672 yy_print_ (*yycdebug_, Symbol); \
673 *yycdebug_ << std::endl; \
677 # define YY_REDUCE_PRINT(Rule) \
680 yy_reduce_print_ (Rule); \
683 # define YY_STACK_PRINT() \
691 # define YYCDEBUG if (false) std::cerr
692 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
693 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
694 # define YY_STACK_PRINT() static_cast<void>(0)
696 #endif /* !YYDEBUG */
698 #define yyerrok (yyerrstatus_ = 0)
699 #define yyclearin (yychar = yyempty_)
701 #define YYACCEPT goto yyacceptlab
702 #define YYABORT goto yyabortlab
703 #define YYERROR goto yyerrorlab
704 #define YYRECOVERING() (!!yyerrstatus_)
709 /* Return YYSTR after stripping away unnecessary quotes and
710 backslashes, so that it's suitable for yyerror. The heuristic is
711 that double-quoting is unnecessary unless the string contains an
712 apostrophe, a comma, or backslash (other than backslash-backslash).
713 YYSTR is taken from yytname. */
715 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
719 std::string yyr
= "";
720 char const *yyp
= yystr
;
727 goto do_not_strip_quotes
;
731 goto do_not_strip_quotes
;
740 do_not_strip_quotes
: ;
748 /// Build a parser object.
749 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
752 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
753 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
754 #endif]b4_parse_param_cons[
758 ]b4_parser_class_name::~b4_parser_class_name
[ ()
768 template <typename Exact
>
769 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
775 template <typename Exact
>
776 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const semantic_type
& v
, const location_type
& l
)
782 template <typename Exact
>
784 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
786 return static_cast<const Exact
&>(*this);
789 template <typename Exact
>
791 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
793 return static_cast<Exact
&>(*this);
796 template <typename Exact
>
798 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
800 return self ().type_get_ ();
804 ]b4_parser_class_name
[::symbol_type::symbol_type ()
810 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
811 const semantic_type
& v
, const location_type
& l
)
818 ]b4_parser_class_name
[::symbol_type::type_get_ () const
823 // stack_symbol_type.
824 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
830 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (state_type s
,
831 const semantic_type
& v
, const location_type
& l
)
838 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
840 return yystos_
[state
];
844 template <typename Exact
>
846 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
847 symbol_base_type
<Exact
>& yysym
) const
849 int yytype
= yysym
.type_get ();
852 YY_SYMBOL_PRINT (yymsg
, yysym
);
857 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
863 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
867 template <typename Exact
>
869 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
870 const symbol_base_type
<Exact
>& yysym
) const
872 int yytype
= yysym
.type_get ();
873 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
874 << ' ' << yytname_
[yytype
] << " ("
875 << yysym
.location
<< ": ";
878 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
887 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
891 YY_SYMBOL_PRINT (m
, sym
);
893 [[ yystack_
.push (stack_symbol_type (s
, semantic_type(), sym
.location
));
894 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
895 [build
], [sym
.value
])],
896 [ yystack_
.push (stack_symbol_type (s
, sym
.value
, sym
.location
));])[
900 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
903 YY_SYMBOL_PRINT (m
, s
);
905 [[ yystack_
.push (stack_symbol_type (s
.state
, semantic_type(), s
.location
));
906 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
907 [build
], [s
.value
])],
908 [ yystack_
.push (s
);])[
912 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
919 ]b4_parser_class_name
[::debug_stream () const
925 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
931 ]b4_parser_class_name
[::debug_level_type
932 ]b4_parser_class_name
[::debug_level () const
938 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
945 ]b4_parser_class_name
[::parse ()
947 /// Coded type of the lookahead.
948 int yychar
= yyempty_
;
955 /* Error handling. */
957 int yyerrstatus_
= 0;
959 /// The lookahead symbol.
962 /// The locations where the error started and ended.
963 stack_symbol_type yyerror_range
[2];
966 stack_symbol_type yylhs
;
968 /// The return value of parse().
971 YYCDEBUG
<< "Starting parse" << std::endl
;
973 ]m4_ifdef([b4_initial_action
], [
974 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
975 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
976 /* User initialization code. */
977 b4_user_initial_action
978 m4_popdef([b4_dollar_dollar
])dnl
979 m4_popdef([b4_at_dollar
])])dnl
981 [ /* Initialize the stack. The initial state will be set in
982 yynewstate, since the latter expects the semantical and the
983 location values to have been already stored, initialize these
984 stacks with a primary value. */
985 yystack_
= stack_type (0);
986 yypush_ (0, 0, yyla
);
988 // A new state was pushed on the stack.
989 // Invariant: yystate == yystack_[0].state, i.e.,
990 // yystate was just pushed onto the state stack.
992 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
995 if (yystate
== yyfinal_
)
1003 /* Try to take a decision without lookahead. */
1004 yyn
= yypact_
[yystate
];
1005 if (yyn
== yypact_ninf_
)
1008 /* Read a lookahead token. */
1009 if (yychar
== yyempty_
)
1011 YYCDEBUG
<< "Reading a token: ";
1012 yychar
= ]b4_c_function_call([yylex
], [int],
1013 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1014 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1015 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
1019 /* Convert token to internal form. */
1020 if (yychar
<= yyeof_
)
1022 yychar
= yyla
.type
= yyeof_
;
1023 YYCDEBUG
<< "Now at end of input." << std::endl
;
1027 yyla
.type
= yytranslate_ (yychar
);
1028 YY_SYMBOL_PRINT ("Next token is", yyla
);
1031 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1032 to detect an error, take that action. */
1034 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1037 /* Reduce or error. */
1038 yyn
= yytable_
[yyn
];
1041 if (yyn
== 0 || yyn
== yytable_ninf_
)
1047 /* Discard the token being shifted. */
1050 /* Count tokens shifted since error; after three, turn off error
1055 /* Shift the lookahead token. */
1057 yypush_ ("Shifting", yystate
, yyla
);
1060 /*-----------------------------------------------------------.
1061 | yydefault -- do the default action for the current state. |
1062 `-----------------------------------------------------------*/
1064 yyn
= yydefact_
[yystate
];
1069 /*-----------------------------.
1070 | yyreduce -- Do a reduction. |
1071 `-----------------------------*/
1073 yylen
= yyr2_
[yyn
];]b4_variant_if([
1074 /* Variants are always initialized to an empty instance of the
1075 correct type. The default $$=$1 rule is NOT applied when using
1077 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1078 /* If YYLEN is nonzero, implement the default value of the action:
1079 `$$ = $1'. Otherwise, use the top of the stack.
1081 Otherwise, the following line sets YYLHS.VALUE to garbage.
1082 This behavior is undocumented and Bison
1083 users should not rely upon it. */
1085 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1087 yylhs
.value
= yystack_@
{0@
}.value
;])[
1089 // Compute the default @@$.
1091 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1092 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1095 // Perform the reduction.
1096 YY_REDUCE_PRINT (yyn
);
1103 // Compute post-reduction state.
1105 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1106 if (0 <= yystate
&& yystate
<= yylast_
1107 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1108 yystate
= yytable_
[yystate
];
1110 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1111 yylhs
.state
= yystate
;
1112 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1114 // Destroy the lhs symbols.
1115 for (int i
= 0; i
< yylen
; ++i
)
1116 // Destroy a variant which value may have be swapped with
1117 // yylhs.value. The value of yylhs.value (hence maybe one of
1118 // these lhs symbols) depends on what does the default
1119 // contruction for this type. In the case of pointers for
1120 // instance, nothing is done, so the value is junk. Therefore
1121 // do not try to report the content in the debug trace, it's
1122 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1123 // traces as with the other Bison skeletons.
1124 yy_destroy_ (0, yystack_
[i
]);]])[
1130 /* Shift the result of the reduction. */
1134 /*------------------------------------.
1135 | yyerrlab -- here on detecting error |
1136 `------------------------------------*/
1138 /* If not already recovering from an error, report this error. */
1142 error (yyla
.location
, yysyntax_error_ (yystate
, yyla
.type
));
1145 yyerror_range
[0].location
= yyla
.location
;
1146 if (yyerrstatus_
== 3)
1148 /* If just tried and failed to reuse lookahead token after an
1149 error, discard it. */
1151 if (yychar
<= yyeof_
)
1153 /* Return failure if at end of input. */
1154 if (yychar
== yyeof_
)
1159 yy_destroy_ ("Error: discarding", yyla
);
1164 /* Else will try to reuse lookahead token after shifting the error
1169 /*---------------------------------------------------.
1170 | yyerrorlab -- error raised explicitly by YYERROR. |
1171 `---------------------------------------------------*/
1174 /* Pacify compilers like GCC when the user code never invokes
1175 YYERROR and the label yyerrorlab therefore never appears in user
1180 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1181 /* Do not reclaim the symbols of the rule which action triggered
1185 yystate
= yystack_
[0].state
;
1188 /*-------------------------------------------------------------.
1189 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1190 `-------------------------------------------------------------*/
1192 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1194 stack_symbol_type error_token
;
1197 yyn
= yypact_
[yystate
];
1198 if (yyn
!= yypact_ninf_
)
1201 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1203 yyn
= yytable_
[yyn
];
1209 // Pop the current state because it cannot handle the error token.
1210 if (yystack_
.size () == 1)
1213 yyerror_range
[0].location
= yystack_
[0].location
;
1214 yy_destroy_ ("Error: popping", yystack_
[0]);
1216 yystate
= yystack_
[0].state
;
1220 yyerror_range
[1].location
= yyla
.location
;
1221 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1223 /* Shift the error token. */
1224 error_token
.state
= yystate
= yyn
;
1225 yypush_ ("Shifting", error_token
);
1240 if (yychar
!= yyempty_
)
1241 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1243 /* Do not reclaim the symbols of the rule which action triggered
1244 this YYABORT or YYACCEPT. */
1246 while (yystack_
.size () != 1)
1248 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1255 // Generate an error message.
1257 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1258 b4_error_verbose_if([ tok
])[)
1263 int yyn
= yypact_
[yystate
];
1264 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1266 /* Start YYX at -YYN if negative to avoid negative indexes in
1268 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1270 /* Stay within bounds of both yycheck and yytname. */
1271 int yychecklim
= yylast_
- yyn
+ 1;
1272 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1274 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1275 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1278 // FIXME: This method of building the message is not compatible
1279 // with internationalization. It should work like yacc.c does it.
1280 // That is, first build a string that looks like this:
1281 // "syntax error, unexpected %s or %s or %s"
1282 // Then, invoke YY_ on this string.
1283 // Finally, use the string as a format to output
1284 // yytname_[tok], etc.
1285 // Until this gets fixed, this message appears in English only.
1286 res
= "syntax error, unexpected ";
1287 res
+= yytnamerr_ (yytname_
[tok
]);
1291 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1292 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1294 res
+= (!count
++) ? ", expecting " : " or ";
1295 res
+= yytnamerr_ (yytname_
[x
]);
1301 res
= YY_("syntax error");
1306 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1308 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1309 ]b4_table_define([pact
], [b4_pact
])[;
1311 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1312 doesn't specify something else to do. Zero means the default is an
1314 ]b4_table_define([defact
], [b4_defact
])[;
1316 /* YYPGOTO[NTERM-NUM]. */
1317 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1319 /* YYDEFGOTO[NTERM-NUM]. */
1320 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1322 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1323 positive, shift that token. If negative, reduce the rule which
1324 number is the opposite. If zero, do what YYDEFACT says. */
1325 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1326 ]b4_table_define([table
], [b4_table
])[;
1329 ]b4_table_define([check
], [b4_check
])[;
1331 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1332 symbol of state STATE-NUM. */
1333 ]b4_table_define([stos
], [b4_stos
])[;
1336 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1338 ]b4_table_define([token_number
], [b4_toknum
])[;
1341 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1342 ]b4_table_define([r1
], [b4_r1
])[;
1344 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1345 ]b4_table_define([r2
], [b4_r2
])[;
1347 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1348 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1349 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1351 const ]b4_parser_class_name
[::yytname_
[] =
1358 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1359 ]b4_table_define([rline
], [b4_rline
])[;
1361 // Print the state stack on the debug stream.
1363 ]b4_parser_class_name
[::yystack_print_ ()
1365 *yycdebug_
<< "Stack now";
1366 for (stack_type::const_iterator
1367 i
= yystack_
.begin (),
1368 i_end
= yystack_
.end ();
1370 *yycdebug_
<< ' ' << i
->state
;
1371 *yycdebug_
<< std::endl
;
1374 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1376 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1378 unsigned int yylno
= yyrline_
[yyrule
];
1379 int yynrhs
= yyr2_
[yyrule
];
1380 /* Print the symbols being reduced, and their result. */
1381 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1382 << " (line " << yylno
<< "):" << std::endl
;
1383 /* The symbols being reduced. */
1384 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1385 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1386 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1390 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1391 ]b4_parser_class_name
[::token_number_type
1392 ]b4_parser_class_name
[::yytranslate_ (int t
)
1395 const token_number_type
1400 if ((unsigned int) t
<= yyuser_token_number_max_
)
1401 return translate_table
[t
];
1403 return yyundef_token_
;
1406 const int ]b4_parser_class_name
[::yyeof_
= 0;
1407 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1408 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1409 const int ]b4_parser_class_name
[::yyempty_
= -2;
1410 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1411 const int ]b4_parser_class_name
[::yyterror_
= 1;
1412 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1413 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1415 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1416 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1418 ]b4_namespace_close
[
1421 @
output(b4_dir_prefix
[]stack
.hh@
)@
1422 b4_copyright([Stack handling
for Bison parsers in C
++])[
1424 #ifndef BISON_STACK_HH
1425 # define BISON_STACK_HH
1430 template <class T
, class S
= std::deque
<T
> >
1435 // Hide our reversed order.
1436 typedef typename
S::reverse_iterator iterator
;
1437 typedef typename
S::const_reverse_iterator const_iterator
;
1443 stack (unsigned int n
) : seq_ (n
)
1449 operator [] (unsigned int i
)
1456 operator [] (unsigned int i
) const
1465 seq_
.push_front (t
);
1470 pop (unsigned int n
= 1)
1477 typename
S::size_type
1480 return seq_
.size ();
1483 inline const_iterator
begin () const { return seq_
.rbegin (); }
1484 inline const_iterator
end () const { return seq_
.rend (); }
1487 /// The wrapped container.
1491 /// Present a slice of the top of a stack.
1492 template <class T
, class S
= stack
<T
> >
1497 slice (const S
& stack
,
1498 unsigned int range
) : stack_ (stack
),
1505 operator [] (unsigned int i
) const
1507 return stack_
[range_
- i
];
1513 unsigned int range_
;
1515 ]b4_namespace_close
[
1517 #endif // not BISON_STACK_HH[]dnl
1520 m4_popdef([b4_copyright_years
])dnl