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 /// Accessor to a built \a T.
251 template <typename T
>
256 return reinterpret_cast<T
&>(buffer
);
259 /// Const accessor to a built \a T (for %printer).
260 template <typename T
>
265 return reinterpret_cast<const T
&>(buffer
);
268 /// Swap the content with \a other.
269 template <typename T
>
271 swap(variant
<S
>& other
)
273 std::swap(as
<T
>(), other
.as
<T
>());
276 /// Assign the content of \a other to this.
277 /// Destroys \a other.
278 template <typename T
>
280 build(variant
<S
>& other
)
287 /// Destroy the stored \a T.
288 template <typename T
>
292 as
<T
>().~T();]b4_assert_if([
296 /// A buffer large enough to store any of the semantic values.
302 #include "location.hh"
304 /* Enabling traces. */
306 # define YYDEBUG ]b4_debug_flag[
309 /* Enabling verbose error messages. */
310 #ifdef YYERROR_VERBOSE
311 # undef YYERROR_VERBOSE
312 # define YYERROR_VERBOSE 1
314 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
317 /* Enabling the token table. */
318 #ifndef YYTOKEN_TABLE
319 # define YYTOKEN_TABLE ]b4_token_table[
322 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
323 If N is 0, then set CURRENT to the empty location which ends
324 the previous symbol: RHS[0] (always defined). */
326 #ifndef YYLLOC_DEFAULT
327 # define YYLLOC_DEFAULT(Current, Rhs, N) \
331 (Current).begin = (Rhs)[1].location.begin; \
332 (Current).end = (Rhs)[N].location.end; \
336 (Current).begin = (Current).end = (Rhs)[0].location.end; \
344 class ]b4_parser_class_name
[
349 [ /// An auxiliary type to compute the largest semantic type.
351 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
354 /// Symbol semantic values.
355 typedef variant
<sizeof(union_type
)> semantic_type
;],
356 [ /// Symbol semantic values.
358 [ union semantic_type
361 [m4_if(b4_tag_seen_flag
, 0,
362 [[ typedef int semantic_type
;]],
363 [[ typedef YYSTYPE semantic_type
;]])])])[
365 typedef YYSTYPE semantic_type
;
367 /// Symbol locations.
368 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
372 ]b4_token_enums(b4_tokens
)[
375 typedef token::yytokentype token_type
;
377 /// Build a parser object.
378 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
379 virtual ~]b4_parser_class_name
[ ();
382 /// \returns 0 iff parsing succeeded.
383 virtual int parse ();
386 /// The current debugging stream.
387 std::ostream
& debug_stream () const;
388 /// Set the current debugging stream.
389 void set_debug_stream (std::ostream
&);
391 /// Type for debugging levels.
392 typedef int debug_level_type
;
393 /// The current debugging level.
394 debug_level_type
debug_level () const;
395 /// Set the current debugging level.
396 void set_debug_level (debug_level_type l
);
400 /// Report a syntax error.
401 /// \param loc where the syntax error is found.
402 /// \param msg a description of the syntax error.
403 virtual void error (const location_type
& loc
, const std::string
& msg
);
405 /// Generate an error message.
406 /// \param state the state where the error occurred.
407 /// \param tok the lookahead token.
408 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
411 typedef int state_type
;
413 /// Internal symbol numbers.
414 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
416 /// For a state, the index in \a yytable_ of its portion.
417 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
418 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
420 /// For a state, default rule to reduce.
421 /// Unless\a yytable_ specifies something else to do.
422 /// Zero means the default is an error.
423 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
425 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
426 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
428 /// What to do in a state.
429 /// \a yytable_[yypact_[s]]: what to do in state \a s.
430 /// - if positive, shift that token.
431 /// - if negative, reduce the rule which number is the opposite.
432 /// - if zero, do what YYDEFACT says.
433 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
434 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
436 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
438 /// For a state, its accessing symbol.
439 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
441 /// For a rule, its LHS.
442 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
443 /// For a rule, its RHS length.
444 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
446 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
447 /// For a symbol, its name in clear.
448 static const char* const yytname_
[];
452 /// Convert the symbol name \a n to a form suitable for a diagnostic.
453 virtual std::string
yytnamerr_ (const char *n
);
457 /// For each rule, its source line number.
458 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
459 /// For each scanner token number, its symbol number.
460 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
461 /// Report on the debug stream that the rule \a r is going to be reduced.
462 virtual void yy_reduce_print_ (int r
);
463 /// Print the state stack on the debug stream.
464 virtual void yystack_print_ ();
468 std::ostream
* yycdebug_
;
471 /// Convert a scanner token number \a t to a symbol number.
472 token_number_type
yytranslate_ (int t
);
474 /// A complete symbol, with its type.
475 template <typename Exact
>
476 struct symbol_base_type
478 /// Default constructor.
479 inline symbol_base_type ();
482 inline symbol_base_type (const semantic_type
& v
, const location_type
& l
);
484 /// Return this with its exact type.
485 const Exact
& self () const;
488 /// Return the type of this symbol.
489 int type_get () const;
491 /// The semantic value.
495 location_type location
;
499 /// \brief Display a symbol type, value and location.
500 /// \param yyo The output stream.
501 /// \param yysym The symbol.
502 template <typename Exact
>
503 void yy_print_ (std::ostream
& yyo
,
504 const symbol_base_type
<Exact
>& yysym
) const;
507 /// \brief Reclaim the memory associated to a symbol.
508 /// \param yymsg Why this token is reclaimed.
509 /// If null, print nothing.
510 /// \param s The symbol.
511 template <typename Exact
>
512 inline void yy_destroy_ (const char* yymsg
,
513 symbol_base_type
<Exact
>& yysym
) const;
515 /// Element of the stack: a state and its attributes.
516 struct symbol_type
: symbol_base_type
<symbol_type
>
518 /// The parent class.
519 typedef symbol_base_type
<symbol_type
> super_type
;
521 /// Default constructor.
522 inline symbol_type ();
525 inline symbol_type (int t
,
526 const semantic_type
& v
, const location_type
& l
);
531 /// Return the type corresponding to this state.
532 inline int type_get_ () const;
535 /// Element of the stack: a state and its attributes.
536 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
538 /// The parent class.
539 typedef symbol_base_type
<stack_symbol_type
> super_type
;
541 /// Default constructor.
542 inline stack_symbol_type ();
545 inline stack_symbol_type (state_type s
,
546 const semantic_type
& v
, const location_type
& l
);
551 /// Return the type corresponding to this state.
552 inline int type_get_ () const;
556 typedef stack
<stack_symbol_type
> stack_type
;
561 /// Push a new state on the stack.
562 /// \param m a debug message to display
563 /// if null, no trace is output.
564 /// \param s the symbol
565 /// \warning the contents of \a s.value is stolen.
566 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
568 /// Push a new look ahead token on the state on the stack.
569 /// \param m a debug message to display
570 /// if null, no trace is output.
571 /// \param s the state
572 /// \param sym the symbol (for its value and location).
573 /// \warning the contents of \a s.value is stolen.
574 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
576 /// Pop \a n symbols the three stacks.
577 inline void yypop_ (unsigned int n
= 1);
580 static const int yyeof_
;
581 /* LAST_ -- Last index in TABLE_. */
582 static const int yylast_
;
583 static const int yynnts_
;
584 static const int yyempty_
;
585 static const int yyfinal_
;
586 static const int yyterror_
;
587 static const int yyerrcode_
;
588 static const int yyntokens_
;
589 static const unsigned int yyuser_token_number_max_
;
590 static const token_number_type yyundef_token_
;
591 ]b4_parse_param_vars
[
596 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
597 [b4_token_defines(b4_tokens
)
600 /* Redirection for backward compatibility. */
601 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
604 b4_percent_code_get([[provides]])[]dnl
606 [#endif /* ! defined PARSER_HEADER_H */]
608 @
output(b4_parser_file_name@
)@
609 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
610 b4_percent_code_get([[top]])[]dnl
611 m4_if(b4_prefix
, [yy
], [],
613 // Take the name prefix into account.
614 #define yylex b4_prefix[]lex])[
616 /* First part of user declarations. */
617 ]b4_user_pre_prologue
620 #include "@basename(]b4_spec_defines_file[@)"]])[
622 /* User implementation prologue. */
623 ]b4_user_post_prologue
624 b4_percent_code_get
[]dnl
629 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
630 # define YY_(msgid) dgettext ("bison-runtime", msgid)
634 # define YY_(msgid) msgid
638 /* Suppress unused-variable warnings by "using" E. */
639 #define YYUSE(e) ((void) (e))
641 /* Enable debugging if requested. */
644 /* A pseudo ostream that takes yydebug_ into account. */
645 # define YYCDEBUG if (yydebug_) (*yycdebug_)
647 # define YY_SYMBOL_PRINT(Title, Symbol) \
651 *yycdebug_ << Title << ' '; \
652 yy_print_ (*yycdebug_, Symbol); \
653 *yycdebug_ << std::endl; \
657 # define YY_REDUCE_PRINT(Rule) \
660 yy_reduce_print_ (Rule); \
663 # define YY_STACK_PRINT() \
671 # define YYCDEBUG if (false) std::cerr
672 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
673 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
674 # define YY_STACK_PRINT() static_cast<void>(0)
676 #endif /* !YYDEBUG */
678 #define yyerrok (yyerrstatus_ = 0)
679 #define yyclearin (yychar = yyempty_)
681 #define YYACCEPT goto yyacceptlab
682 #define YYABORT goto yyabortlab
683 #define YYERROR goto yyerrorlab
684 #define YYRECOVERING() (!!yyerrstatus_)
689 /* Return YYSTR after stripping away unnecessary quotes and
690 backslashes, so that it's suitable for yyerror. The heuristic is
691 that double-quoting is unnecessary unless the string contains an
692 apostrophe, a comma, or backslash (other than backslash-backslash).
693 YYSTR is taken from yytname. */
695 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
699 std::string yyr
= "";
700 char const *yyp
= yystr
;
707 goto do_not_strip_quotes
;
711 goto do_not_strip_quotes
;
720 do_not_strip_quotes
: ;
728 /// Build a parser object.
729 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
732 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
733 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
734 #endif]b4_parse_param_cons[
738 ]b4_parser_class_name::~b4_parser_class_name
[ ()
748 template <typename Exact
>
749 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
755 template <typename Exact
>
756 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const semantic_type
& v
, const location_type
& l
)
762 template <typename Exact
>
764 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
766 return static_cast<const Exact
&>(*this);
769 template <typename Exact
>
771 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
773 return static_cast<Exact
&>(*this);
776 template <typename Exact
>
778 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
780 return self ().type_get_ ();
784 ]b4_parser_class_name
[::symbol_type::symbol_type ()
790 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
791 const semantic_type
& v
, const location_type
& l
)
798 ]b4_parser_class_name
[::symbol_type::type_get_ () const
803 // stack_symbol_type.
804 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
810 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (state_type s
,
811 const semantic_type
& v
, const location_type
& l
)
818 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
820 return yystos_
[state
];
824 template <typename Exact
>
826 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
827 symbol_base_type
<Exact
>& yysym
) const
829 int yytype
= yysym
.type_get ();
832 YY_SYMBOL_PRINT (yymsg
, yysym
);
837 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
843 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
847 template <typename Exact
>
849 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
850 const symbol_base_type
<Exact
>& yysym
) const
852 int yytype
= yysym
.type_get ();
853 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
854 << ' ' << yytname_
[yytype
] << " ("
855 << yysym
.location
<< ": ";
858 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
867 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
871 YY_SYMBOL_PRINT (m
, sym
);
873 [[ yystack_
.push (stack_symbol_type (s
, semantic_type(), sym
.location
));
874 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
875 [build
], [sym
.value
])],
876 [ yystack_
.push (stack_symbol_type (s
, sym
.value
, sym
.location
));])[
880 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
883 YY_SYMBOL_PRINT (m
, s
);
885 [[ yystack_
.push (stack_symbol_type (s
.state
, semantic_type(), s
.location
));
886 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
887 [build
], [s
.value
])],
888 [ yystack_
.push (s
);])[
892 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
899 ]b4_parser_class_name
[::debug_stream () const
905 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
911 ]b4_parser_class_name
[::debug_level_type
912 ]b4_parser_class_name
[::debug_level () const
918 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
925 ]b4_parser_class_name
[::parse ()
927 /// Coded type of the lookahead.
928 int yychar
= yyempty_
;
935 /* Error handling. */
937 int yyerrstatus_
= 0;
939 /// The lookahead symbol.
942 /// The locations where the error started and ended.
943 stack_symbol_type yyerror_range
[2];
946 stack_symbol_type yylhs
;
948 /// The return value of parse().
951 YYCDEBUG
<< "Starting parse" << std::endl
;
953 ]m4_ifdef([b4_initial_action
], [
954 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
955 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
956 /* User initialization code. */
957 b4_user_initial_action
958 m4_popdef([b4_dollar_dollar
])dnl
959 m4_popdef([b4_at_dollar
])])dnl
961 [ /* Initialize the stack. The initial state will be set in
962 yynewstate, since the latter expects the semantical and the
963 location values to have been already stored, initialize these
964 stacks with a primary value. */
965 yystack_
= stack_type (0);
966 yypush_ (0, 0, yyla
);
968 // A new state was pushed on the stack.
969 // Invariant: yystate == yystack_[0].state, i.e.,
970 // yystate was just pushed onto the state stack.
972 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
975 if (yystate
== yyfinal_
)
983 /* Try to take a decision without lookahead. */
984 yyn
= yypact_
[yystate
];
985 if (yyn
== yypact_ninf_
)
988 /* Read a lookahead token. */
989 if (yychar
== yyempty_
)
991 YYCDEBUG
<< "Reading a token: ";
992 yychar
= ]b4_c_function_call([yylex
], [int],
993 [[YYSTYPE
*], [&yyla
.value
]][]dnl
994 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
995 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
999 /* Convert token to internal form. */
1000 if (yychar
<= yyeof_
)
1002 yychar
= yyla
.type
= yyeof_
;
1003 YYCDEBUG
<< "Now at end of input." << std::endl
;
1007 yyla
.type
= yytranslate_ (yychar
);
1008 YY_SYMBOL_PRINT ("Next token is", yyla
);
1011 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1012 to detect an error, take that action. */
1014 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1017 /* Reduce or error. */
1018 yyn
= yytable_
[yyn
];
1021 if (yyn
== 0 || yyn
== yytable_ninf_
)
1027 /* Discard the token being shifted. */
1030 /* Count tokens shifted since error; after three, turn off error
1035 /* Shift the lookahead token. */
1037 yypush_ ("Shifting", yystate
, yyla
);
1040 /*-----------------------------------------------------------.
1041 | yydefault -- do the default action for the current state. |
1042 `-----------------------------------------------------------*/
1044 yyn
= yydefact_
[yystate
];
1049 /*-----------------------------.
1050 | yyreduce -- Do a reduction. |
1051 `-----------------------------*/
1053 yylen
= yyr2_
[yyn
];]b4_variant_if([
1054 /* Variants are always initialized to an empty instance of the
1055 correct type. The default $$=$1 rule is NOT applied when using
1057 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1058 /* If YYLEN is nonzero, implement the default value of the action:
1059 `$$ = $1'. Otherwise, use the top of the stack.
1061 Otherwise, the following line sets YYLHS.VALUE to garbage.
1062 This behavior is undocumented and Bison
1063 users should not rely upon it. */
1065 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1067 yylhs
.value
= yystack_@
{0@
}.value
;])[
1069 // Compute the default @@$.
1071 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1072 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1075 // Perform the reduction.
1076 YY_REDUCE_PRINT (yyn
);
1083 // Compute post-reduction state.
1085 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1086 if (0 <= yystate
&& yystate
<= yylast_
1087 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1088 yystate
= yytable_
[yystate
];
1090 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1091 yylhs
.state
= yystate
;
1092 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1094 // Destroy the lhs symbols.
1095 for (int i
= 0; i
< yylen
; ++i
)
1096 // Destroy a variant which value may have be swapped with
1097 // yylhs.value. The value of yylhs.value (hence maybe one of
1098 // these lhs symbols) depends on what does the default
1099 // contruction for this type. In the case of pointers for
1100 // instance, nothing is done, so the value is junk. Therefore
1101 // do not try to report the content in the debug trace, it's
1102 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1103 // traces as with the other Bison skeletons.
1104 yy_destroy_ (0, yystack_
[i
]);]])[
1110 /* Shift the result of the reduction. */
1114 /*------------------------------------.
1115 | yyerrlab -- here on detecting error |
1116 `------------------------------------*/
1118 /* If not already recovering from an error, report this error. */
1122 error (yyla
.location
, yysyntax_error_ (yystate
, yyla
.type
));
1125 yyerror_range
[0].location
= yyla
.location
;
1126 if (yyerrstatus_
== 3)
1128 /* If just tried and failed to reuse lookahead token after an
1129 error, discard it. */
1131 if (yychar
<= yyeof_
)
1133 /* Return failure if at end of input. */
1134 if (yychar
== yyeof_
)
1139 yy_destroy_ ("Error: discarding", yyla
);
1144 /* Else will try to reuse lookahead token after shifting the error
1149 /*---------------------------------------------------.
1150 | yyerrorlab -- error raised explicitly by YYERROR. |
1151 `---------------------------------------------------*/
1154 /* Pacify compilers like GCC when the user code never invokes
1155 YYERROR and the label yyerrorlab therefore never appears in user
1160 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1161 /* Do not reclaim the symbols of the rule which action triggered
1165 yystate
= yystack_
[0].state
;
1168 /*-------------------------------------------------------------.
1169 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1170 `-------------------------------------------------------------*/
1172 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1174 stack_symbol_type error_token
;
1177 yyn
= yypact_
[yystate
];
1178 if (yyn
!= yypact_ninf_
)
1181 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1183 yyn
= yytable_
[yyn
];
1189 // Pop the current state because it cannot handle the error token.
1190 if (yystack_
.size () == 1)
1193 yyerror_range
[0].location
= yystack_
[0].location
;
1194 yy_destroy_ ("Error: popping", yystack_
[0]);
1196 yystate
= yystack_
[0].state
;
1200 yyerror_range
[1].location
= yyla
.location
;
1201 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1203 /* Shift the error token. */
1204 error_token
.state
= yystate
= yyn
;
1205 yypush_ ("Shifting", error_token
);
1220 if (yychar
!= yyempty_
)
1221 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1223 /* Do not reclaim the symbols of the rule which action triggered
1224 this YYABORT or YYACCEPT. */
1226 while (yystack_
.size () != 1)
1228 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1235 // Generate an error message.
1237 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1238 b4_error_verbose_if([ tok
])[)
1243 int yyn
= yypact_
[yystate
];
1244 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1246 /* Start YYX at -YYN if negative to avoid negative indexes in
1248 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1250 /* Stay within bounds of both yycheck and yytname. */
1251 int yychecklim
= yylast_
- yyn
+ 1;
1252 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1254 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1255 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1258 // FIXME: This method of building the message is not compatible
1259 // with internationalization. It should work like yacc.c does it.
1260 // That is, first build a string that looks like this:
1261 // "syntax error, unexpected %s or %s or %s"
1262 // Then, invoke YY_ on this string.
1263 // Finally, use the string as a format to output
1264 // yytname_[tok], etc.
1265 // Until this gets fixed, this message appears in English only.
1266 res
= "syntax error, unexpected ";
1267 res
+= yytnamerr_ (yytname_
[tok
]);
1271 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1272 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1274 res
+= (!count
++) ? ", expecting " : " or ";
1275 res
+= yytnamerr_ (yytname_
[x
]);
1281 res
= YY_("syntax error");
1286 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1288 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1289 ]b4_table_define([pact
], [b4_pact
])[;
1291 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1292 doesn't specify something else to do. Zero means the default is an
1294 ]b4_table_define([defact
], [b4_defact
])[;
1296 /* YYPGOTO[NTERM-NUM]. */
1297 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1299 /* YYDEFGOTO[NTERM-NUM]. */
1300 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1302 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1303 positive, shift that token. If negative, reduce the rule which
1304 number is the opposite. If zero, do what YYDEFACT says. */
1305 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1306 ]b4_table_define([table
], [b4_table
])[;
1309 ]b4_table_define([check
], [b4_check
])[;
1311 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1312 symbol of state STATE-NUM. */
1313 ]b4_table_define([stos
], [b4_stos
])[;
1316 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1318 ]b4_table_define([token_number
], [b4_toknum
])[;
1321 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1322 ]b4_table_define([r1
], [b4_r1
])[;
1324 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1325 ]b4_table_define([r2
], [b4_r2
])[;
1327 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1328 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1329 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1331 const ]b4_parser_class_name
[::yytname_
[] =
1338 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1339 ]b4_table_define([rline
], [b4_rline
])[;
1341 // Print the state stack on the debug stream.
1343 ]b4_parser_class_name
[::yystack_print_ ()
1345 *yycdebug_
<< "Stack now";
1346 for (stack_type::const_iterator
1347 i
= yystack_
.begin (),
1348 i_end
= yystack_
.end ();
1350 *yycdebug_
<< ' ' << i
->state
;
1351 *yycdebug_
<< std::endl
;
1354 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1356 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1358 unsigned int yylno
= yyrline_
[yyrule
];
1359 int yynrhs
= yyr2_
[yyrule
];
1360 /* Print the symbols being reduced, and their result. */
1361 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1362 << " (line " << yylno
<< "):" << std::endl
;
1363 /* The symbols being reduced. */
1364 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1365 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1366 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1370 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1371 ]b4_parser_class_name
[::token_number_type
1372 ]b4_parser_class_name
[::yytranslate_ (int t
)
1375 const token_number_type
1380 if ((unsigned int) t
<= yyuser_token_number_max_
)
1381 return translate_table
[t
];
1383 return yyundef_token_
;
1386 const int ]b4_parser_class_name
[::yyeof_
= 0;
1387 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1388 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1389 const int ]b4_parser_class_name
[::yyempty_
= -2;
1390 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1391 const int ]b4_parser_class_name
[::yyterror_
= 1;
1392 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1393 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1395 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1396 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1398 ]b4_namespace_close
[
1401 @
output(b4_dir_prefix
[]stack
.hh@
)@
1402 b4_copyright([Stack handling
for Bison parsers in C
++])[
1404 #ifndef BISON_STACK_HH
1405 # define BISON_STACK_HH
1410 template <class T
, class S
= std::deque
<T
> >
1415 // Hide our reversed order.
1416 typedef typename
S::reverse_iterator iterator
;
1417 typedef typename
S::const_reverse_iterator const_iterator
;
1423 stack (unsigned int n
) : seq_ (n
)
1429 operator [] (unsigned int i
)
1436 operator [] (unsigned int i
) const
1445 seq_
.push_front (t
);
1450 pop (unsigned int n
= 1)
1457 typename
S::size_type
1460 return seq_
.size ();
1463 inline const_iterator
begin () const { return seq_
.rbegin (); }
1464 inline const_iterator
end () const { return seq_
.rend (); }
1467 /// The wrapped container.
1471 /// Present a slice of the top of a stack.
1472 template <class T
, class S
= stack
<T
> >
1477 slice (const S
& stack
,
1478 unsigned int range
) : stack_ (stack
),
1485 operator [] (unsigned int i
) const
1487 return stack_
[range_
- i
];
1493 unsigned int range_
;
1495 ]b4_namespace_close
[
1497 #endif // not BISON_STACK_HH[]dnl
1500 m4_popdef([b4_copyright_years
])dnl