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_value(RULE-LENGTH, NUM, [TYPE])
64 # --------------------------------------
65 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
67 m4_define([b4_rhs_value
],
68 [b4_symbol_value([yystack_@
{($
1) - ($
2)@
}.value
], [$
3])])
70 # b4_rhs_location(RULE-LENGTH, NUM)
71 # ---------------------------------
72 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
74 m4_define([b4_rhs_location
],
75 [yystack_@
{($
1) - ($
2)@
}.location
])
78 # b4_symbol_actions(FILENAME, LINENO,
79 # SYMBOL-TAG, SYMBOL-NUM,
80 # SYMBOL-ACTION, SYMBOL-TYPENAME)
81 # -------------------------------------------------
82 # Same as in C, but using references instead of pointers.
83 m4_define([b4_symbol_actions
],
84 [m4_pushdef([b4_dollar_dollar
],
85 [b4_symbol_value([yyvalue
], [$
6])])dnl
86 m4_pushdef([b4_at_dollar
], [yylocation
])dnl
88 b4_syncline([$
2], [$
1])
90 b4_syncline([@oline@
], [@ofile@
])
92 m4_popdef([b4_at_dollar
])dnl
93 m4_popdef([b4_dollar_dollar
])dnl
97 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
98 # ----------------------------------------------------------
99 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
100 m4_define([b4_symbol_action_
],
103 b4_dollar_dollar($@
);
108 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
109 # ------------------------------------------------
110 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
112 m4_define([b4_symbol_variant
],
113 [m4_pushdef([b4_dollar_dollar
],
114 [$
2.$
3<$
][3>(m4_shift3($@
))])dnl
117 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
121 m4_popdef([b4_dollar_dollar
])dnl
125 # _b4_char_sizeof_counter
126 # -----------------------
127 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
128 m4_define([_b4_char_sizeof_counter
],
131 # _b4_char_sizeof_dummy
132 # ---------------------
133 # At each call return a new C++ identifier.
134 m4_define([_b4_char_sizeof_dummy
],
135 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
136 dummy
[]_b4_char_sizeof_counter
])
139 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
140 # -------------------------------------------------------
141 # To be mapped on the list of type names to produce:
143 # char dummy1[sizeof(type_name_1)];
144 # char dummy2[sizeof(type_name_2)];
146 # for defined type names.
147 # $3 is doubly-quoted, do not quote it again.
148 m4_define([b4_char_sizeof
],
151 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
155 m4_pushdef([b4_copyright_years
],
156 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
158 m4_define([b4_parser_class_name
],
159 [b4_percent_define_get([[parser_class_name]])])
161 # The header is mandatory.
163 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
165 # Backward compatibility.
166 m4_define([b4_location_constructors
])
167 m4_include(b4_pkgdatadir
/[location
.cc
])
169 # We do want M4 expansion after # for CPP macros.
173 [@
output(b4_spec_defines_file@
)@
174 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
175 dnl FIXME
: This is wrong
, we want computed header guards
.
177 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
179 #ifndef PARSER_HEADER_H
180 # define PARSER_HEADER_H
182 ]b4_percent_code_get([[requires]])[
184 ]b4_assert_if([#include <cassert>])[
194 /// A char[S] buffer to store and retrieve objects.
196 /// Sort of a variant, but does not keep track of the nature
197 /// of the stored data, since that knowledge is available
198 /// via the current state.
202 /// Whether something is contained.
205 /// Initially uninitialized.
210 /// Instantiate a \a T in here.
211 template <typename T
>
217 return *new (buffer
) T
;
220 /// Accessor to a built \a T.
221 template <typename T
>
226 return reinterpret_cast<T
&>(buffer
);
229 /// Const accessor to a built \a T (for %printer).
230 template <typename T
>
235 return reinterpret_cast<const T
&>(buffer
);
238 /// Swap the content with \a other.
239 template <typename T
>
241 swap(variant
<S
>& other
)
243 std::swap(as
<T
>(), other
.as
<T
>());
246 /// Assign the content of \a other to this.
247 /// Destroys \a other.
248 template <typename T
>
250 build(variant
<S
>& other
)
257 /// Destroy the stored \a T.
258 template <typename T
>
262 as
<T
>().~T();]b4_assert_if([
266 /// A buffer large enough to store any of the semantic values.
272 #include "location.hh"
274 /* Enabling traces. */
276 # define YYDEBUG ]b4_debug_flag[
279 /* Enabling verbose error messages. */
280 #ifdef YYERROR_VERBOSE
281 # undef YYERROR_VERBOSE
282 # define YYERROR_VERBOSE 1
284 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
287 /* Enabling the token table. */
288 #ifndef YYTOKEN_TABLE
289 # define YYTOKEN_TABLE ]b4_token_table[
292 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
293 If N is 0, then set CURRENT to the empty location which ends
294 the previous symbol: RHS[0] (always defined). */
296 #ifndef YYLLOC_DEFAULT
297 # define YYLLOC_DEFAULT(Current, Rhs, N) \
301 (Current).begin = (Rhs)[1].location.begin; \
302 (Current).end = (Rhs)[N].location.end; \
306 (Current).begin = (Current).end = (Rhs)[0].location.end; \
314 class ]b4_parser_class_name
[
319 [ /// An auxiliary type to compute the largest semantic type.
321 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
324 /// Symbol semantic values.
325 typedef variant
<sizeof(union_type
)> semantic_type
;],
326 [ /// Symbol semantic values.
328 [ union semantic_type
331 [m4_if(b4_tag_seen_flag
, 0,
332 [[ typedef int semantic_type
;]],
333 [[ typedef YYSTYPE semantic_type
;]])])])[
335 typedef YYSTYPE semantic_type
;
337 /// Symbol locations.
338 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
342 ]b4_token_enums(b4_tokens
)[
345 typedef token::yytokentype token_type
;
347 /// Build a parser object.
348 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
349 virtual ~]b4_parser_class_name
[ ();
352 /// \returns 0 iff parsing succeeded.
353 virtual int parse ();
356 /// The current debugging stream.
357 std::ostream
& debug_stream () const;
358 /// Set the current debugging stream.
359 void set_debug_stream (std::ostream
&);
361 /// Type for debugging levels.
362 typedef int debug_level_type
;
363 /// The current debugging level.
364 debug_level_type
debug_level () const;
365 /// Set the current debugging level.
366 void set_debug_level (debug_level_type l
);
370 /// Report a syntax error.
371 /// \param loc where the syntax error is found.
372 /// \param msg a description of the syntax error.
373 virtual void error (const location_type
& loc
, const std::string
& msg
);
375 /// Generate an error message.
376 /// \param state the state where the error occurred.
377 /// \param tok the lookahead token.
378 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
381 /// \brief Report a symbol value on the debug stream.
382 /// \param yytype The token type.
383 /// \param yyvalue Its semantic value.
384 /// \param yylocation Its location.
385 virtual void yy_symbol_value_print_ (int yytype
,
386 const semantic_type
& yyvalue
,
387 const location_type
& yylocation
);
388 /// \brief Report a symbol on the debug stream.
389 /// \param yytype The token type.
390 /// \param yyvalue Its semantic value.
391 /// \param yylocation Its location.
392 virtual void yy_symbol_print_ (int yytype
,
393 const semantic_type
& yyvalue
,
394 const location_type
& yylocation
);
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 /// A `-1'-separated list of the rules' RHS.
445 static const ]b4_int_type_for([b4_rhs
])[ yyrhs_
[];
446 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
447 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
448 /// For each rule, its source line number.
449 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
450 /// For each scanner token number, its symbol number.
451 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
452 /// Report on the debug stream that the rule \a r is going to be reduced.
453 virtual void yy_reduce_print_ (int r
);
454 /// Print the state stack on the debug stream.
455 virtual void yystack_print_ ();
459 std::ostream
* yycdebug_
;
462 /// Convert a scanner token number \a t to a symbol number.
463 token_number_type
yytranslate_ (int t
);
465 /// \brief Reclaim the memory associated to a symbol.
466 /// \param yymsg Why this token is reclaimed.
467 /// If null, nothing is printed at all.
468 /// \param yytype The symbol type.
469 /// \param yyvalue Its semantic value.
470 /// \param yylocation Its location.
471 inline void yydestruct_ (const char* yymsg
,
473 semantic_type
& yyvalue
,
474 location_type
& yylocation
);
476 /// Element of the stack: a state and its attributes.
479 /// Default constructor.
483 data_type (state_type s
, const semantic_type
& v
, const location_type
& l
);
488 /// The semantic value.
492 location_type location
;
496 typedef stack
<data_type
> stack_type
;
501 /// Push a new state on the stack.
502 /// \param m a debug message to display
503 /// if null, no trace is output.
504 /// \param s the state entered
505 /// \param v semantic value
506 /// \param l location
507 /// \warning the contents of \a v is stolen.
508 inline void yypush_ (const char* m
, state_type s
,
509 semantic_type
& v
, const location_type
& l
);
511 /// Pop \a n symbols the three stacks.
512 inline void yypop_ (unsigned int n
= 1);
515 static const int yyeof_
;
516 /* LAST_ -- Last index in TABLE_. */
517 static const int yylast_
;
518 static const int yynnts_
;
519 static const int yyempty_
;
520 static const int yyfinal_
;
521 static const int yyterror_
;
522 static const int yyerrcode_
;
523 static const int yyntokens_
;
524 static const unsigned int yyuser_token_number_max_
;
525 static const token_number_type yyundef_token_
;
526 ]b4_parse_param_vars
[
530 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
531 [b4_token_defines(b4_tokens
)
534 /* Redirection for backward compatibility. */
535 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
538 b4_percent_code_get([[provides]])[]dnl
540 [#endif /* ! defined PARSER_HEADER_H */]
542 @
output(b4_parser_file_name@
)@
543 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
544 b4_percent_code_get([[top]])[]dnl
545 m4_if(b4_prefix
, [yy
], [],
547 // Take the name prefix into account.
548 #define yylex b4_prefix[]lex])[
550 /* First part of user declarations. */
551 ]b4_user_pre_prologue
554 #include "@basename(]b4_spec_defines_file[@)"]])[
556 /* User implementation prologue. */
557 ]b4_user_post_prologue
558 b4_percent_code_get
[]dnl
563 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
564 # define YY_(msgid) dgettext ("bison-runtime", msgid)
568 # define YY_(msgid) msgid
572 /* Suppress unused-variable warnings by "using" E. */
573 #define YYUSE(e) ((void) (e))
575 /* Enable debugging if requested. */
578 /* A pseudo ostream that takes yydebug_ into account. */
579 # define YYCDEBUG if (yydebug_) (*yycdebug_)
581 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
585 *yycdebug_ << Title << ' '; \
586 yy_symbol_print_ ((Type), (Value), (Location)); \
587 *yycdebug_ << std::endl; \
591 # define YY_REDUCE_PRINT(Rule) \
594 yy_reduce_print_ (Rule); \
597 # define YY_STACK_PRINT() \
605 # define YYCDEBUG if (false) std::cerr
606 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) static_cast<void>(0)
607 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
608 # define YY_STACK_PRINT() static_cast<void>(0)
610 #endif /* !YYDEBUG */
612 #define yyerrok (yyerrstatus_ = 0)
613 #define yyclearin (yychar = yyempty_)
615 #define YYACCEPT goto yyacceptlab
616 #define YYABORT goto yyabortlab
617 #define YYERROR goto yyerrorlab
618 #define YYRECOVERING() (!!yyerrstatus_)
623 /* Return YYSTR after stripping away unnecessary quotes and
624 backslashes, so that it's suitable for yyerror. The heuristic is
625 that double-quoting is unnecessary unless the string contains an
626 apostrophe, a comma, or backslash (other than backslash-backslash).
627 YYSTR is taken from yytname. */
629 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
633 std::string yyr
= "";
634 char const *yyp
= yystr
;
641 goto do_not_strip_quotes
;
645 goto do_not_strip_quotes
;
654 do_not_strip_quotes
: ;
662 /// Build a parser object.
663 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
666 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
667 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
668 #endif]b4_parse_param_cons[
672 ]b4_parser_class_name::~b4_parser_class_name
[ ()
677 /*--------------------------------.
678 | Print this symbol on YYOUTPUT. |
679 `--------------------------------*/
682 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
683 const semantic_type
& yyvalue
, const location_type
& yylocation
)
689 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
697 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
698 const semantic_type
& yyvalue
, const location_type
& yylocation
)
700 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
701 << ' ' << yytname_
[yytype
] << " ("
702 << yylocation
<< ": ";
703 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
709 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
710 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
717 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
722 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
728 b4_symbol_variant([[yytype]], [[yyvalue]], [[destroy]])])[
731 ]b4_parser_class_name
[::data_type::data_type ()
738 ]b4_parser_class_name
[::data_type::data_type (state_type s
,
739 const semantic_type
& v
, const location_type
& l
)
747 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
748 semantic_type
& v
, const location_type
& l
)
751 YY_SYMBOL_PRINT (m
, yystos_
[s
], v
, l
);
753 [[ yystack_
.push (data_type (s
, semantic_type(), l
));
754 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]], [build
], [v
])],
755 [ yystack_
.push (data_type (s
, v
, l
));])[
759 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
766 ]b4_parser_class_name
[::debug_stream () const
772 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
778 ]b4_parser_class_name
[::debug_level_type
779 ]b4_parser_class_name
[::debug_level () const
785 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
792 ]b4_parser_class_name
[::parse ()
794 /// Lookahead and lookahead in internal form.
795 int yychar
= yyempty_
;
803 /* Error handling. */
805 int yyerrstatus_
= 0;
807 /// Semantic value of the lookahead.
808 semantic_type yylval
;
809 /// Location of the lookahead.
810 location_type yylloc
;
811 /// The locations where the error started and ended.
812 data_type yyerror_range
[2];
817 /// The return value of parse().
820 YYCDEBUG
<< "Starting parse" << std::endl
;
822 ]m4_ifdef([b4_initial_action
], [
823 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
824 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
825 /* User initialization code. */
826 b4_user_initial_action
827 m4_popdef([b4_dollar_dollar
])dnl
828 m4_popdef([b4_at_dollar
])])dnl
830 [ /* Initialize the stack. The initial state will be set in
831 yynewstate, since the latter expects the semantical and the
832 location values to have been already stored, initialize these
833 stacks with a primary value. */
834 yystack_
= stack_type (0);
835 yypush_ (0, yystate
, yylval
, yylloc
);
837 // A new state was pushed on the stack.
838 // Invariant: yystate == yystack_[0].state, i.e.,
839 // yystate was just pushed onto the state stack.
841 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
844 if (yystate
== yyfinal_
)
852 /* Try to take a decision without lookahead. */
853 yyn
= yypact_
[yystate
];
854 if (yyn
== yypact_ninf_
)
857 /* Read a lookahead token. */
858 if (yychar
== yyempty_
)
860 YYCDEBUG
<< "Reading a token: ";
861 yychar
= ]b4_c_function_call([yylex
], [int],
862 [[YYSTYPE
*], [&yylval
]][]dnl
863 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
864 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
868 /* Convert token to internal form. */
869 if (yychar
<= yyeof_
)
871 yychar
= yytoken
= yyeof_
;
872 YYCDEBUG
<< "Now at end of input." << std::endl
;
876 yytoken
= yytranslate_ (yychar
);
877 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
880 /* If the proper action on seeing token YYTOKEN is to reduce or to
881 detect an error, take that action. */
883 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
886 /* Reduce or error. */
890 if (yyn
== 0 || yyn
== yytable_ninf_
)
896 /* Discard the token being shifted. */
899 /* Count tokens shifted since error; after three, turn off error
904 /* Shift the lookahead token. */
906 yypush_ ("Shifting", yystate
, yylval
, yylloc
);
909 /*-----------------------------------------------------------.
910 | yydefault -- do the default action for the current state. |
911 `-----------------------------------------------------------*/
913 yyn
= yydefact_
[yystate
];
918 /*-----------------------------.
919 | yyreduce -- Do a reduction. |
920 `-----------------------------*/
922 yylen
= yyr2_
[yyn
];]b4_variant_if([
923 /* Variants are always initialized to an empty instance of the
924 correct type. The default $$=$1 rule is NOT applied when using
926 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
927 /* If YYLEN is nonzero, implement the default value of the action:
928 `$$ = $1'. Otherwise, use the top of the stack.
930 Otherwise, the following line sets YYLHS.VALUE to garbage.
931 This behavior is undocumented and Bison
932 users should not rely upon it. */
934 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
936 yylhs
.value
= yystack_@
{0@
}.value
;])[
938 // Compute the default @@$.
940 slice
<data_type
, stack_type
> slice (yystack_
, yylen
);
941 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
944 // Perform the reduction.
945 YY_REDUCE_PRINT (yyn
);
952 // Compute post-reduction state.
954 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
955 if (0 <= yystate
&& yystate
<= yylast_
956 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
957 yystate
= yytable_
[yystate
];
959 yystate
= yydefgoto_
[yyn
- yyntokens_
];
960 yylhs
.state
= yystate
;
961 YY_SYMBOL_PRINT ("-> $$ =", yyn
, yylhs
.value
, yylhs
.location
);
963 // Destroy the lhs symbols.
964 for (int i
= 0; i
< yylen
; ++i
)
965 // Destroy a variant which value may have be swapped with
966 // yylhs.value. The value of yylhs.value (hence maybe one of
967 // these lhs symbols) depends on what does the default
968 // contruction for this type. In the case of pointers for
969 // instance, nothing is done, so the value is junk. Therefore
970 // do not try to report the content in the debug trace, it's
971 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
972 // traces as with the other Bison skeletons.
974 yystos_
[yystack_
[i
].state
],
975 yystack_
[i
].value
, yystack_
[i
].location
);]])[
981 /* Shift the result of the reduction. */
982 yypush_ (0, yylhs
.state
, yylhs
.value
, yylhs
.location
);
985 /*------------------------------------.
986 | yyerrlab -- here on detecting error |
987 `------------------------------------*/
989 /* If not already recovering from an error, report this error. */
993 error (yylloc
, yysyntax_error_ (yystate
, yytoken
));
996 yyerror_range
[0].location
= yylloc
;
997 if (yyerrstatus_
== 3)
999 /* If just tried and failed to reuse lookahead token after an
1000 error, discard it. */
1002 if (yychar
<= yyeof_
)
1004 /* Return failure if at end of input. */
1005 if (yychar
== yyeof_
)
1010 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
1015 /* Else will try to reuse lookahead token after shifting the error
1020 /*---------------------------------------------------.
1021 | yyerrorlab -- error raised explicitly by YYERROR. |
1022 `---------------------------------------------------*/
1025 /* Pacify compilers like GCC when the user code never invokes
1026 YYERROR and the label yyerrorlab therefore never appears in user
1031 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
1032 /* Do not reclaim the symbols of the rule which action triggered
1036 yystate
= yystack_
[0].state
;
1039 /*-------------------------------------------------------------.
1040 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1041 `-------------------------------------------------------------*/
1043 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1045 data_type error_token
;
1048 yyn
= yypact_
[yystate
];
1049 if (yyn
!= yypact_ninf_
)
1052 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1054 yyn
= yytable_
[yyn
];
1060 // Pop the current state because it cannot handle the error token.
1061 if (yystack_
.size () == 1)
1064 yyerror_range
[0].location
= yystack_
[0].location
;
1065 yydestruct_ ("Error: popping",
1067 yystack_
[0].value
, yystack_
[0].location
);
1069 yystate
= yystack_
[0].state
;
1073 yyerror_range
[1].location
= yylloc
;
1074 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);
1076 /* Shift the error token. */
1078 yypush_ ("Shifting", yystate
, error_token
.value
, error_token
.location
);
1093 if (yychar
!= yyempty_
)
1094 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
1096 /* Do not reclaim the symbols of the rule which action triggered
1097 this YYABORT or YYACCEPT. */
1099 while (yystack_
.size () != 1)
1101 yydestruct_ ("Cleanup: popping",
1102 yystos_
[yystack_
[0].state
],
1103 yystack_
[0].value
, yystack_
[0].location
);
1110 // Generate an error message.
1112 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1113 b4_error_verbose_if([ tok
])[)
1118 int yyn
= yypact_
[yystate
];
1119 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1121 /* Start YYX at -YYN if negative to avoid negative indexes in
1123 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1125 /* Stay within bounds of both yycheck and yytname. */
1126 int yychecklim
= yylast_
- yyn
+ 1;
1127 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1129 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1130 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1133 // FIXME: This method of building the message is not compatible
1134 // with internationalization. It should work like yacc.c does it.
1135 // That is, first build a string that looks like this:
1136 // "syntax error, unexpected %s or %s or %s"
1137 // Then, invoke YY_ on this string.
1138 // Finally, use the string as a format to output
1139 // yytname_[tok], etc.
1140 // Until this gets fixed, this message appears in English only.
1141 res
= "syntax error, unexpected ";
1142 res
+= yytnamerr_ (yytname_
[tok
]);
1146 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1147 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1149 res
+= (!count
++) ? ", expecting " : " or ";
1150 res
+= yytnamerr_ (yytname_
[x
]);
1156 res
= YY_("syntax error");
1161 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1163 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1164 ]b4_table_define([pact
], [b4_pact
])[;
1166 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1167 doesn't specify something else to do. Zero means the default is an
1169 ]b4_table_define([defact
], [b4_defact
])[;
1171 /* YYPGOTO[NTERM-NUM]. */
1172 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1174 /* YYDEFGOTO[NTERM-NUM]. */
1175 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1177 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1178 positive, shift that token. If negative, reduce the rule which
1179 number is the opposite. If zero, do what YYDEFACT says. */
1180 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1181 ]b4_table_define([table
], [b4_table
])[;
1184 ]b4_table_define([check
], [b4_check
])[;
1186 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1187 symbol of state STATE-NUM. */
1188 ]b4_table_define([stos
], [b4_stos
])[;
1191 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1193 ]b4_table_define([token_number
], [b4_toknum
])[;
1196 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1197 ]b4_table_define([r1
], [b4_r1
])[;
1199 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1200 ]b4_table_define([r2
], [b4_r2
])[;
1202 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1203 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1204 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1206 const ]b4_parser_class_name
[::yytname_
[] =
1213 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1214 ]b4_table_define([rhs
], [b4_rhs
])[;
1216 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1218 ]b4_table_define([prhs
], [b4_prhs
])[;
1220 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1221 ]b4_table_define([rline
], [b4_rline
])[;
1223 // Print the state stack on the debug stream.
1225 ]b4_parser_class_name
[::yystack_print_ ()
1227 *yycdebug_
<< "Stack now";
1228 for (stack_type::const_iterator
1229 i
= yystack_
.begin (),
1230 i_end
= yystack_
.end ();
1232 *yycdebug_
<< ' ' << i
->state
;
1233 *yycdebug_
<< std::endl
;
1236 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1238 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1240 unsigned int yylno
= yyrline_
[yyrule
];
1241 int yynrhs
= yyr2_
[yyrule
];
1242 /* Print the symbols being reduced, and their result. */
1243 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1244 << " (line " << yylno
<< "):" << std::endl
;
1245 /* The symbols being reduced. */
1246 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1247 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1248 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1249 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1250 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1254 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1255 ]b4_parser_class_name
[::token_number_type
1256 ]b4_parser_class_name
[::yytranslate_ (int t
)
1259 const token_number_type
1264 if ((unsigned int) t
<= yyuser_token_number_max_
)
1265 return translate_table
[t
];
1267 return yyundef_token_
;
1270 const int ]b4_parser_class_name
[::yyeof_
= 0;
1271 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1272 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1273 const int ]b4_parser_class_name
[::yyempty_
= -2;
1274 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1275 const int ]b4_parser_class_name
[::yyterror_
= 1;
1276 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1277 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1279 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1280 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1282 ]b4_namespace_close
[
1285 @
output(b4_dir_prefix
[]stack
.hh@
)@
1286 b4_copyright([Stack handling
for Bison parsers in C
++])[
1288 #ifndef BISON_STACK_HH
1289 # define BISON_STACK_HH
1294 template <class T
, class S
= std::deque
<T
> >
1299 // Hide our reversed order.
1300 typedef typename
S::reverse_iterator iterator
;
1301 typedef typename
S::const_reverse_iterator const_iterator
;
1307 stack (unsigned int n
) : seq_ (n
)
1313 operator [] (unsigned int i
)
1320 operator [] (unsigned int i
) const
1329 seq_
.push_front (t
);
1334 pop (unsigned int n
= 1)
1341 typename
S::size_type
1344 return seq_
.size ();
1347 inline const_iterator
begin () const { return seq_
.rbegin (); }
1348 inline const_iterator
end () const { return seq_
.rend (); }
1351 /// The wrapped container.
1355 /// Present a slice of the top of a stack.
1356 template <class T
, class S
= stack
<T
> >
1361 slice (const S
& stack
,
1362 unsigned int range
) : stack_ (stack
),
1369 operator [] (unsigned int i
) const
1371 return stack_
[range_
- i
];
1377 unsigned int range_
;
1379 ]b4_namespace_close
[
1381 #endif // not BISON_STACK_HH[]dnl
1384 m4_popdef([b4_copyright_years
])dnl