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 # How the semantic value is extracted when using variants.
34 # b4_symbol_value(VAL, [TYPE])
35 # ----------------------------
36 m4_define([b4_symbol_value
],
43 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
44 # ----------------------------------------------------
45 m4_define([b4_assert_if
],
46 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
49 # b4_lhs_value([TYPE])
50 # --------------------
51 # Expansion of $<TYPE>$.
52 m4_define([b4_lhs_value
],
53 [b4_symbol_value([yylhs
.value
], [$
1])])
59 m4_define([b4_lhs_location
],
63 # b4_rhs_data(RULE-LENGTH, NUM)
64 # -----------------------------
65 # Return the data corresponding to the symbol #NUM, where the current
66 # rule has RULE-LENGTH symbols on RHS.
67 m4_define([b4_rhs_data
],
68 [yystack_@
{($
1) - ($
2)@
}])
71 # b4_rhs_state(RULE-LENGTH, NUM)
72 # -----------------------------
73 # The state corresponding to the symbol #NUM, where the current
74 # rule has RULE-LENGTH symbols on RHS.
75 m4_define([b4_rhs_state
],
76 [b4_rhs_data([$
1], [$
2]).state
])
79 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
80 # --------------------------------------
81 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
83 m4_define([b4_rhs_value
],
84 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
87 # b4_rhs_location(RULE-LENGTH, NUM)
88 # ---------------------------------
89 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
91 m4_define([b4_rhs_location
],
92 [b4_rhs_data([$
1], [$
2]).location
])
95 # b4_symbol_actions(FILENAME, LINENO,
96 # SYMBOL-TAG, SYMBOL-NUM,
97 # SYMBOL-ACTION, SYMBOL-TYPENAME)
98 # -------------------------------------------------
99 # Same as in C, but using references instead of pointers.
100 m4_define([b4_symbol_actions
],
101 [m4_pushdef([b4_dollar_dollar
],
102 [b4_symbol_value([yysym
.value
], [$
6])])dnl
103 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
105 b4_syncline([$
2], [$
1])
107 b4_syncline([@oline@
], [@ofile@
])
109 m4_popdef([b4_at_dollar
])dnl
110 m4_popdef([b4_dollar_dollar
])dnl
114 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
115 # ----------------------------------------------------------
116 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
117 m4_define([b4_symbol_action_
],
120 b4_dollar_dollar($@
);
125 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
126 # ------------------------------------------------
127 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
129 m4_define([b4_symbol_variant
],
130 [m4_pushdef([b4_dollar_dollar
],
131 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
134 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
138 m4_popdef([b4_dollar_dollar
])dnl
142 # _b4_char_sizeof_counter
143 # -----------------------
144 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
145 m4_define([_b4_char_sizeof_counter
],
148 # _b4_char_sizeof_dummy
149 # ---------------------
150 # At each call return a new C++ identifier.
151 m4_define([_b4_char_sizeof_dummy
],
152 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
153 dummy
[]_b4_char_sizeof_counter
])
156 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
157 # -------------------------------------------------------
158 # To be mapped on the list of type names to produce:
160 # char dummy1[sizeof(type_name_1)];
161 # char dummy2[sizeof(type_name_2)];
163 # for defined type names.
164 # $3 is doubly-quoted, do not quote it again.
165 m4_define([b4_char_sizeof
],
168 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
172 m4_pushdef([b4_copyright_years
],
173 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
175 m4_define([b4_parser_class_name
],
176 [b4_percent_define_get([[parser_class_name]])])
178 # The header is mandatory.
180 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
182 # Backward compatibility.
183 m4_define([b4_location_constructors
])
184 m4_include(b4_pkgdatadir
/[location
.cc
])
186 # We do want M4 expansion after # for CPP macros.
190 [@
output(b4_spec_defines_file@
)@
191 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
192 dnl FIXME
: This is wrong
, we want computed header guards
.
194 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
196 #ifndef PARSER_HEADER_H
197 # define PARSER_HEADER_H
199 ]b4_percent_code_get([[requires]])[
201 ]b4_assert_if([#include <cassert>])[
211 /// A char[S] buffer to store and retrieve objects.
213 /// Sort of a variant, but does not keep track of the nature
214 /// of the stored data, since that knowledge is available
215 /// via the current state.
219 /// Whether something is contained.
222 /// Initially uninitialized.
227 /// Instantiate a \a T in here.
228 template <typename T
>
234 return *new (buffer
) T
;
237 /// Accessor to a built \a T.
238 template <typename T
>
243 return reinterpret_cast<T
&>(buffer
);
246 /// Const accessor to a built \a T (for %printer).
247 template <typename T
>
252 return reinterpret_cast<const T
&>(buffer
);
255 /// Swap the content with \a other.
256 template <typename T
>
258 swap(variant
<S
>& other
)
260 std::swap(as
<T
>(), other
.as
<T
>());
263 /// Assign the content of \a other to this.
264 /// Destroys \a other.
265 template <typename T
>
267 build(variant
<S
>& other
)
274 /// Destroy the stored \a T.
275 template <typename T
>
279 as
<T
>().~T();]b4_assert_if([
283 /// A buffer large enough to store any of the semantic values.
289 #include "location.hh"
291 /* Enabling traces. */
293 # define YYDEBUG ]b4_debug_flag[
296 /* Enabling verbose error messages. */
297 #ifdef YYERROR_VERBOSE
298 # undef YYERROR_VERBOSE
299 # define YYERROR_VERBOSE 1
301 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
304 /* Enabling the token table. */
305 #ifndef YYTOKEN_TABLE
306 # define YYTOKEN_TABLE ]b4_token_table[
309 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
310 If N is 0, then set CURRENT to the empty location which ends
311 the previous symbol: RHS[0] (always defined). */
313 #ifndef YYLLOC_DEFAULT
314 # define YYLLOC_DEFAULT(Current, Rhs, N) \
318 (Current).begin = (Rhs)[1].location.begin; \
319 (Current).end = (Rhs)[N].location.end; \
323 (Current).begin = (Current).end = (Rhs)[0].location.end; \
331 class ]b4_parser_class_name
[
336 [ /// An auxiliary type to compute the largest semantic type.
338 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
341 /// Symbol semantic values.
342 typedef variant
<sizeof(union_type
)> semantic_type
;],
343 [ /// Symbol semantic values.
345 [ union semantic_type
348 [m4_if(b4_tag_seen_flag
, 0,
349 [[ typedef int semantic_type
;]],
350 [[ typedef YYSTYPE semantic_type
;]])])])[
352 typedef YYSTYPE semantic_type
;
354 /// Symbol locations.
355 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
359 ]b4_token_enums(b4_tokens
)[
362 typedef token::yytokentype token_type
;
364 /// Build a parser object.
365 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
366 virtual ~]b4_parser_class_name
[ ();
369 /// \returns 0 iff parsing succeeded.
370 virtual int parse ();
373 /// The current debugging stream.
374 std::ostream
& debug_stream () const;
375 /// Set the current debugging stream.
376 void set_debug_stream (std::ostream
&);
378 /// Type for debugging levels.
379 typedef int debug_level_type
;
380 /// The current debugging level.
381 debug_level_type
debug_level () const;
382 /// Set the current debugging level.
383 void set_debug_level (debug_level_type l
);
387 /// Report a syntax error.
388 /// \param loc where the syntax error is found.
389 /// \param msg a description of the syntax error.
390 virtual void error (const location_type
& loc
, const std::string
& msg
);
392 /// Generate an error message.
393 /// \param state the state where the error occurred.
394 /// \param tok the lookahead token.
395 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
398 typedef int state_type
;
400 /// Internal symbol numbers.
401 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
403 /// For a state, the index in \a yytable_ of its portion.
404 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
405 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
407 /// For a state, default rule to reduce.
408 /// Unless\a yytable_ specifies something else to do.
409 /// Zero means the default is an error.
410 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
412 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
413 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
415 /// What to do in a state.
416 /// \a yytable_[yypact_[s]]: what to do in state \a s.
417 /// - if positive, shift that token.
418 /// - if negative, reduce the rule which number is the opposite.
419 /// - if zero, do what YYDEFACT says.
420 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
421 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
423 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
425 /// For a state, its accessing symbol.
426 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
428 /// For a rule, its LHS.
429 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
430 /// For a rule, its RHS length.
431 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
433 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
434 /// For a symbol, its name in clear.
435 static const char* const yytname_
[];
439 /// Convert the symbol name \a n to a form suitable for a diagnostic.
440 virtual std::string
yytnamerr_ (const char *n
);
444 /// For each rule, its source line number.
445 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
446 /// For each scanner token number, its symbol number.
447 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
448 /// Report on the debug stream that the rule \a r is going to be reduced.
449 virtual void yy_reduce_print_ (int r
);
450 /// Print the state stack on the debug stream.
451 virtual void yystack_print_ ();
455 std::ostream
* yycdebug_
;
458 /// Convert a scanner token number \a t to a symbol number.
459 token_number_type
yytranslate_ (int t
);
461 /// A complete symbol, with its type.
462 struct symbol_base_type
464 /// Default constructor.
465 inline symbol_base_type ();
468 inline symbol_base_type (const semantic_type
& v
, const location_type
& l
);
470 /// Return the type of this symbol.
471 virtual int type_get () const = 0;
473 /// The semantic value.
477 location_type location
;
481 /// \brief Display a symbol type, value and location.
482 /// \param yyo The output stream.
483 /// \param yysym The symbol.
484 void yy_print_ (std::ostream
& yyo
, const symbol_base_type
& yysym
) const;
487 /// \brief Reclaim the memory associated to a symbol.
488 /// \param yymsg Why this token is reclaimed.
489 /// If null, print nothing.
490 /// \param s The symbol.
491 inline void yy_destroy_ (const char* yymsg
, symbol_base_type
& yysym
) const;
493 /// Element of the stack: a state and its attributes.
494 struct symbol_type
: symbol_base_type
496 /// Default constructor.
497 inline symbol_type ();
500 inline symbol_type (int t
,
501 const semantic_type
& v
, const location_type
& l
);
506 /// Return the type corresponding to this state.
507 virtual inline int type_get () const;
510 /// Element of the stack: a state and its attributes.
511 struct stack_symbol_type
: symbol_base_type
513 /// Default constructor.
514 inline stack_symbol_type ();
517 inline stack_symbol_type (state_type s
,
518 const semantic_type
& v
, const location_type
& l
);
523 /// Return the type corresponding to this state.
524 virtual inline int type_get () const;
528 typedef stack
<stack_symbol_type
> stack_type
;
533 /// Push a new state on the stack.
534 /// \param m a debug message to display
535 /// if null, no trace is output.
536 /// \param s the symbol
537 /// \warning the contents of \a s.value is stolen.
538 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
540 /// Push a new look ahead token on the state on the stack.
541 /// \param m a debug message to display
542 /// if null, no trace is output.
543 /// \param s the state
544 /// \param sym the symbol (for its value and location).
545 /// \warning the contents of \a s.value is stolen.
546 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
548 /// Pop \a n symbols the three stacks.
549 inline void yypop_ (unsigned int n
= 1);
552 static const int yyeof_
;
553 /* LAST_ -- Last index in TABLE_. */
554 static const int yylast_
;
555 static const int yynnts_
;
556 static const int yyempty_
;
557 static const int yyfinal_
;
558 static const int yyterror_
;
559 static const int yyerrcode_
;
560 static const int yyntokens_
;
561 static const unsigned int yyuser_token_number_max_
;
562 static const token_number_type yyundef_token_
;
563 ]b4_parse_param_vars
[
568 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
569 [b4_token_defines(b4_tokens
)
572 /* Redirection for backward compatibility. */
573 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
576 b4_percent_code_get([[provides]])[]dnl
578 [#endif /* ! defined PARSER_HEADER_H */]
580 @
output(b4_parser_file_name@
)@
581 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
582 b4_percent_code_get([[top]])[]dnl
583 m4_if(b4_prefix
, [yy
], [],
585 // Take the name prefix into account.
586 #define yylex b4_prefix[]lex])[
588 /* First part of user declarations. */
589 ]b4_user_pre_prologue
592 #include "@basename(]b4_spec_defines_file[@)"]])[
594 /* User implementation prologue. */
595 ]b4_user_post_prologue
596 b4_percent_code_get
[]dnl
601 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
602 # define YY_(msgid) dgettext ("bison-runtime", msgid)
606 # define YY_(msgid) msgid
610 /* Suppress unused-variable warnings by "using" E. */
611 #define YYUSE(e) ((void) (e))
613 /* Enable debugging if requested. */
616 /* A pseudo ostream that takes yydebug_ into account. */
617 # define YYCDEBUG if (yydebug_) (*yycdebug_)
619 # define YY_SYMBOL_PRINT(Title, Symbol) \
623 *yycdebug_ << Title << ' '; \
624 yy_print_ (*yycdebug_, Symbol); \
625 *yycdebug_ << std::endl; \
629 # define YY_REDUCE_PRINT(Rule) \
632 yy_reduce_print_ (Rule); \
635 # define YY_STACK_PRINT() \
643 # define YYCDEBUG if (false) std::cerr
644 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
645 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
646 # define YY_STACK_PRINT() static_cast<void>(0)
648 #endif /* !YYDEBUG */
650 #define yyerrok (yyerrstatus_ = 0)
651 #define yyclearin (yychar = yyempty_)
653 #define YYACCEPT goto yyacceptlab
654 #define YYABORT goto yyabortlab
655 #define YYERROR goto yyerrorlab
656 #define YYRECOVERING() (!!yyerrstatus_)
661 /* Return YYSTR after stripping away unnecessary quotes and
662 backslashes, so that it's suitable for yyerror. The heuristic is
663 that double-quoting is unnecessary unless the string contains an
664 apostrophe, a comma, or backslash (other than backslash-backslash).
665 YYSTR is taken from yytname. */
667 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
671 std::string yyr
= "";
672 char const *yyp
= yystr
;
679 goto do_not_strip_quotes
;
683 goto do_not_strip_quotes
;
692 do_not_strip_quotes
: ;
700 /// Build a parser object.
701 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
704 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
705 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
706 #endif]b4_parse_param_cons[
710 ]b4_parser_class_name::~b4_parser_class_name
[ ()
720 ]b4_parser_class_name
[::symbol_base_type::symbol_base_type ()
726 ]b4_parser_class_name
[::symbol_base_type::symbol_base_type (const semantic_type
& v
, const location_type
& l
)
734 ]b4_parser_class_name
[::symbol_type::symbol_type ()
740 ]b4_parser_class_name
[::symbol_type::symbol_type (int t
,
741 const semantic_type
& v
, const location_type
& l
)
743 , symbol_base_type(v
, l
)
748 ]b4_parser_class_name
[::symbol_type::type_get () const
753 // stack_symbol_type.
754 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
760 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (state_type s
,
761 const semantic_type
& v
, const location_type
& l
)
763 , symbol_base_type(v
, l
)
768 ]b4_parser_class_name
[::stack_symbol_type::type_get () const
770 return yystos_
[state
];
775 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
, symbol_base_type
& yysym
) const
777 int yytype
= yysym
.type_get ();
780 YY_SYMBOL_PRINT (yymsg
, yysym
);
785 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
791 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[destroy]])])[
796 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
, const symbol_base_type
& yysym
) const
798 int yytype
= yysym
.type_get ();
799 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
800 << ' ' << yytname_
[yytype
] << " ("
801 << yysym
.location
<< ": ";
804 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
813 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
817 YY_SYMBOL_PRINT (m
, sym
);
819 [[ yystack_
.push (stack_symbol_type (s
, semantic_type(), sym
.location
));
820 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
821 [build
], [sym
.value
])],
822 [ yystack_
.push (stack_symbol_type (s
, sym
.value
, sym
.location
));])[
826 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
829 YY_SYMBOL_PRINT (m
, s
);
831 [[ yystack_
.push (stack_symbol_type (s
.state
, semantic_type(), s
.location
));
832 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
833 [build
], [s
.value
])],
834 [ yystack_
.push (s
);])[
838 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
845 ]b4_parser_class_name
[::debug_stream () const
851 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
857 ]b4_parser_class_name
[::debug_level_type
858 ]b4_parser_class_name
[::debug_level () const
864 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
871 ]b4_parser_class_name
[::parse ()
873 /// Coded type of the lookahead.
874 int yychar
= yyempty_
;
881 /* Error handling. */
883 int yyerrstatus_
= 0;
885 /// The lookahead symbol.
888 /// The locations where the error started and ended.
889 stack_symbol_type yyerror_range
[2];
892 stack_symbol_type yylhs
;
894 /// The return value of parse().
897 YYCDEBUG
<< "Starting parse" << std::endl
;
899 ]m4_ifdef([b4_initial_action
], [
900 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
901 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
902 /* User initialization code. */
903 b4_user_initial_action
904 m4_popdef([b4_dollar_dollar
])dnl
905 m4_popdef([b4_at_dollar
])])dnl
907 [ /* Initialize the stack. The initial state will be set in
908 yynewstate, since the latter expects the semantical and the
909 location values to have been already stored, initialize these
910 stacks with a primary value. */
911 yystack_
= stack_type (0);
912 yypush_ (0, 0, yyla
);
914 // A new state was pushed on the stack.
915 // Invariant: yystate == yystack_[0].state, i.e.,
916 // yystate was just pushed onto the state stack.
918 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
921 if (yystate
== yyfinal_
)
929 /* Try to take a decision without lookahead. */
930 yyn
= yypact_
[yystate
];
931 if (yyn
== yypact_ninf_
)
934 /* Read a lookahead token. */
935 if (yychar
== yyempty_
)
937 YYCDEBUG
<< "Reading a token: ";
938 yychar
= ]b4_c_function_call([yylex
], [int],
939 [[YYSTYPE
*], [&yyla
.value
]][]dnl
940 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
941 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
945 /* Convert token to internal form. */
946 if (yychar
<= yyeof_
)
948 yychar
= yyla
.type
= yyeof_
;
949 YYCDEBUG
<< "Now at end of input." << std::endl
;
953 yyla
.type
= yytranslate_ (yychar
);
954 YY_SYMBOL_PRINT ("Next token is", yyla
);
957 /* If the proper action on seeing token YYLA.TYPE is to reduce or
958 to detect an error, take that action. */
960 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
963 /* Reduce or error. */
967 if (yyn
== 0 || yyn
== yytable_ninf_
)
973 /* Discard the token being shifted. */
976 /* Count tokens shifted since error; after three, turn off error
981 /* Shift the lookahead token. */
983 yypush_ ("Shifting", yystate
, yyla
);
986 /*-----------------------------------------------------------.
987 | yydefault -- do the default action for the current state. |
988 `-----------------------------------------------------------*/
990 yyn
= yydefact_
[yystate
];
995 /*-----------------------------.
996 | yyreduce -- Do a reduction. |
997 `-----------------------------*/
999 yylen
= yyr2_
[yyn
];]b4_variant_if([
1000 /* Variants are always initialized to an empty instance of the
1001 correct type. The default $$=$1 rule is NOT applied when using
1003 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1004 /* If YYLEN is nonzero, implement the default value of the action:
1005 `$$ = $1'. Otherwise, use the top of the stack.
1007 Otherwise, the following line sets YYLHS.VALUE to garbage.
1008 This behavior is undocumented and Bison
1009 users should not rely upon it. */
1011 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1013 yylhs
.value
= yystack_@
{0@
}.value
;])[
1015 // Compute the default @@$.
1017 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1018 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1021 // Perform the reduction.
1022 YY_REDUCE_PRINT (yyn
);
1029 // Compute post-reduction state.
1031 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1032 if (0 <= yystate
&& yystate
<= yylast_
1033 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1034 yystate
= yytable_
[yystate
];
1036 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1037 yylhs
.state
= yystate
;
1038 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1040 // Destroy the lhs symbols.
1041 for (int i
= 0; i
< yylen
; ++i
)
1042 // Destroy a variant which value may have be swapped with
1043 // yylhs.value. The value of yylhs.value (hence maybe one of
1044 // these lhs symbols) depends on what does the default
1045 // contruction for this type. In the case of pointers for
1046 // instance, nothing is done, so the value is junk. Therefore
1047 // do not try to report the content in the debug trace, it's
1048 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1049 // traces as with the other Bison skeletons.
1050 yy_destroy_ (0, yystack_
[i
]);]])[
1056 /* Shift the result of the reduction. */
1060 /*------------------------------------.
1061 | yyerrlab -- here on detecting error |
1062 `------------------------------------*/
1064 /* If not already recovering from an error, report this error. */
1068 error (yyla
.location
, yysyntax_error_ (yystate
, yyla
.type
));
1071 yyerror_range
[0].location
= yyla
.location
;
1072 if (yyerrstatus_
== 3)
1074 /* If just tried and failed to reuse lookahead token after an
1075 error, discard it. */
1077 if (yychar
<= yyeof_
)
1079 /* Return failure if at end of input. */
1080 if (yychar
== yyeof_
)
1085 yy_destroy_ ("Error: discarding", yyla
);
1090 /* Else will try to reuse lookahead token after shifting the error
1095 /*---------------------------------------------------.
1096 | yyerrorlab -- error raised explicitly by YYERROR. |
1097 `---------------------------------------------------*/
1100 /* Pacify compilers like GCC when the user code never invokes
1101 YYERROR and the label yyerrorlab therefore never appears in user
1106 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1107 /* Do not reclaim the symbols of the rule which action triggered
1111 yystate
= yystack_
[0].state
;
1114 /*-------------------------------------------------------------.
1115 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1116 `-------------------------------------------------------------*/
1118 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1120 stack_symbol_type error_token
;
1123 yyn
= yypact_
[yystate
];
1124 if (yyn
!= yypact_ninf_
)
1127 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1129 yyn
= yytable_
[yyn
];
1135 // Pop the current state because it cannot handle the error token.
1136 if (yystack_
.size () == 1)
1139 yyerror_range
[0].location
= yystack_
[0].location
;
1140 yy_destroy_ ("Error: popping", yystack_
[0]);
1142 yystate
= yystack_
[0].state
;
1146 yyerror_range
[1].location
= yyla
.location
;
1147 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1149 /* Shift the error token. */
1150 error_token
.state
= yystate
= yyn
;
1151 yypush_ ("Shifting", error_token
);
1166 if (yychar
!= yyempty_
)
1167 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1169 /* Do not reclaim the symbols of the rule which action triggered
1170 this YYABORT or YYACCEPT. */
1172 while (yystack_
.size () != 1)
1174 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1181 // Generate an error message.
1183 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1184 b4_error_verbose_if([ tok
])[)
1189 int yyn
= yypact_
[yystate
];
1190 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1192 /* Start YYX at -YYN if negative to avoid negative indexes in
1194 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1196 /* Stay within bounds of both yycheck and yytname. */
1197 int yychecklim
= yylast_
- yyn
+ 1;
1198 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1200 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1201 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1204 // FIXME: This method of building the message is not compatible
1205 // with internationalization. It should work like yacc.c does it.
1206 // That is, first build a string that looks like this:
1207 // "syntax error, unexpected %s or %s or %s"
1208 // Then, invoke YY_ on this string.
1209 // Finally, use the string as a format to output
1210 // yytname_[tok], etc.
1211 // Until this gets fixed, this message appears in English only.
1212 res
= "syntax error, unexpected ";
1213 res
+= yytnamerr_ (yytname_
[tok
]);
1217 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1218 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1220 res
+= (!count
++) ? ", expecting " : " or ";
1221 res
+= yytnamerr_ (yytname_
[x
]);
1227 res
= YY_("syntax error");
1232 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1234 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1235 ]b4_table_define([pact
], [b4_pact
])[;
1237 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1238 doesn't specify something else to do. Zero means the default is an
1240 ]b4_table_define([defact
], [b4_defact
])[;
1242 /* YYPGOTO[NTERM-NUM]. */
1243 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1245 /* YYDEFGOTO[NTERM-NUM]. */
1246 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1248 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1249 positive, shift that token. If negative, reduce the rule which
1250 number is the opposite. If zero, do what YYDEFACT says. */
1251 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1252 ]b4_table_define([table
], [b4_table
])[;
1255 ]b4_table_define([check
], [b4_check
])[;
1257 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1258 symbol of state STATE-NUM. */
1259 ]b4_table_define([stos
], [b4_stos
])[;
1262 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1264 ]b4_table_define([token_number
], [b4_toknum
])[;
1267 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1268 ]b4_table_define([r1
], [b4_r1
])[;
1270 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1271 ]b4_table_define([r2
], [b4_r2
])[;
1273 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1274 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1275 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1277 const ]b4_parser_class_name
[::yytname_
[] =
1284 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1285 ]b4_table_define([rline
], [b4_rline
])[;
1287 // Print the state stack on the debug stream.
1289 ]b4_parser_class_name
[::yystack_print_ ()
1291 *yycdebug_
<< "Stack now";
1292 for (stack_type::const_iterator
1293 i
= yystack_
.begin (),
1294 i_end
= yystack_
.end ();
1296 *yycdebug_
<< ' ' << i
->state
;
1297 *yycdebug_
<< std::endl
;
1300 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1302 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1304 unsigned int yylno
= yyrline_
[yyrule
];
1305 int yynrhs
= yyr2_
[yyrule
];
1306 /* Print the symbols being reduced, and their result. */
1307 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1308 << " (line " << yylno
<< "):" << std::endl
;
1309 /* The symbols being reduced. */
1310 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1311 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1312 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1316 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1317 ]b4_parser_class_name
[::token_number_type
1318 ]b4_parser_class_name
[::yytranslate_ (int t
)
1321 const token_number_type
1326 if ((unsigned int) t
<= yyuser_token_number_max_
)
1327 return translate_table
[t
];
1329 return yyundef_token_
;
1332 const int ]b4_parser_class_name
[::yyeof_
= 0;
1333 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1334 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1335 const int ]b4_parser_class_name
[::yyempty_
= -2;
1336 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1337 const int ]b4_parser_class_name
[::yyterror_
= 1;
1338 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1339 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1341 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1342 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1344 ]b4_namespace_close
[
1347 @
output(b4_dir_prefix
[]stack
.hh@
)@
1348 b4_copyright([Stack handling
for Bison parsers in C
++])[
1350 #ifndef BISON_STACK_HH
1351 # define BISON_STACK_HH
1356 template <class T
, class S
= std::deque
<T
> >
1361 // Hide our reversed order.
1362 typedef typename
S::reverse_iterator iterator
;
1363 typedef typename
S::const_reverse_iterator const_iterator
;
1369 stack (unsigned int n
) : seq_ (n
)
1375 operator [] (unsigned int i
)
1382 operator [] (unsigned int i
) const
1391 seq_
.push_front (t
);
1396 pop (unsigned int n
= 1)
1403 typename
S::size_type
1406 return seq_
.size ();
1409 inline const_iterator
begin () const { return seq_
.rbegin (); }
1410 inline const_iterator
end () const { return seq_
.rend (); }
1413 /// The wrapped container.
1417 /// Present a slice of the top of a stack.
1418 template <class T
, class S
= stack
<T
> >
1423 slice (const S
& stack
,
1424 unsigned int range
) : stack_ (stack
),
1431 operator [] (unsigned int i
) const
1433 return stack_
[range_
- i
];
1439 unsigned int range_
;
1441 ]b4_namespace_close
[
1443 #endif // not BISON_STACK_HH[]dnl
1446 m4_popdef([b4_copyright_years
])dnl