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 # How the semantic value is extracted when using variants.
23 # b4_symbol_value(VAL, [TYPE])
24 # ----------------------------
25 m4_define([b4_symbol_value
],
32 # b4_symbol_actions(FILENAME, LINENO,
33 # SYMBOL-TAG, SYMBOL-NUM,
34 # SYMBOL-ACTION, SYMBOL-TYPENAME)
35 # -------------------------------------------------
36 # Same as in C, but using references instead of pointers.
37 m4_define([b4_symbol_actions
],
38 [m4_pushdef([b4_dollar_dollar
],
39 [b4_symbol_value([yyvalue
], [$
6])])dnl
40 m4_pushdef([b4_at_dollar
], [yylocation
])dnl
42 b4_syncline([$
2], [$
1])
44 b4_syncline([@oline@
], [@ofile@
])
46 m4_popdef([b4_at_dollar
])dnl
47 m4_popdef([b4_dollar_dollar
])dnl
51 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
52 # ----------------------------------------------------------
53 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
54 m4_define([b4_symbol_action_
],
62 # b4_symbol_variant(YYTYPE, YYVAL, ACTION)
63 # ----------------------------------------
64 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
66 m4_define([b4_symbol_variant
],
67 [m4_pushdef([b4_dollar_dollar
],
71 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
75 m4_popdef([b4_dollar_dollar
])dnl
79 # _b4_char_sizeof_counter
80 # -----------------------
81 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
82 m4_define([_b4_char_sizeof_counter
],
85 # _b4_char_sizeof_dummy
86 # ---------------------
87 # At each call return a new C++ identifier.
88 m4_define([_b4_char_sizeof_dummy
],
89 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
90 dummy
[]_b4_char_sizeof_counter
])
93 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
94 # -------------------------------------------------------
95 # To be mapped on the list of type names to produce:
97 # char dummy1[sizeof(type_name_1)];
98 # char dummy2[sizeof(type_name_2)];
100 # for defined type names.
101 # $3 is doubly-quoted, do not quote it again.
102 m4_define([b4_char_sizeof
],
105 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
109 m4_define([b4_parser_class_name
],
110 [b4_percent_define_get([[parser_class_name]])])
112 # The header is mandatory.
114 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
116 # Backward compatibility.
117 m4_define([b4_location_constructors
])
118 m4_include(b4_pkgdatadir
/[location
.cc
])
120 # We do want M4 expansion after # for CPP macros.
124 [@
output(b4_spec_defines_file@
)
125 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++],
126 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
127 dnl FIXME
: This is wrong
, we want computed header guards
.
129 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
131 #ifndef PARSER_HEADER_H
132 # define PARSER_HEADER_H
134 ]b4_percent_code_get([[requires]])[
144 /// A char[S] buffer to store and retrieve objects.
146 /// Sort of a variant, but does not keep track of the nature
147 /// of the stored data, since that knowledge is available
148 /// via the current state.
152 /// Instantiate a \a T in here.
153 template <typename T
>
160 /// Destroy the stored \a T.
161 template <typename T
>
165 reinterpret_cast<T
&>(buffer
).~T();
168 /// Accessor to a built \a T.
169 template <typename T
>
173 return reinterpret_cast<T
&>(buffer
);
176 /// Const accessor to a built \a T (for %printer).
177 template <typename T
>
181 return reinterpret_cast<const T
&>(buffer
);
184 /// A buffer large enough to store any of the semantic values.
190 #include "location.hh"
192 /* Enabling traces. */
194 # define YYDEBUG ]b4_debug_flag[
197 /* Enabling verbose error messages. */
198 #ifdef YYERROR_VERBOSE
199 # undef YYERROR_VERBOSE
200 # define YYERROR_VERBOSE 1
202 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
205 /* Enabling the token table. */
206 #ifndef YYTOKEN_TABLE
207 # define YYTOKEN_TABLE ]b4_token_table[
210 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
211 If N is 0, then set CURRENT to the empty location which ends
212 the previous symbol: RHS[0] (always defined). */
214 #ifndef YYLLOC_DEFAULT
215 # define YYLLOC_DEFAULT(Current, Rhs, N) \
219 (Current).begin = (Rhs)[1].begin; \
220 (Current).end = (Rhs)[N].end; \
224 (Current).begin = (Current).end = (Rhs)[0].end; \
232 class ]b4_parser_class_name
[
237 [ /// An auxiliary type to compute the largest semantic type.
239 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
242 /// Symbol semantic values.
243 typedef variant
<sizeof(union_type
)> semantic_type
;],
244 [ /// Symbol semantic values.
246 [ union semantic_type
249 [m4_if(b4_tag_seen_flag
, 0,
250 [[ typedef int semantic_type
;]],
251 [[ typedef YYSTYPE semantic_type
;]])])])[
253 typedef YYSTYPE semantic_type
;
255 /// Symbol locations.
256 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
260 ]b4_token_enums(b4_tokens
)[
263 typedef token::yytokentype token_type
;
265 /// Build a parser object.
266 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
267 virtual ~]b4_parser_class_name
[ ();
270 /// \returns 0 iff parsing succeeded.
271 virtual int parse ();
274 /// The current debugging stream.
275 std::ostream
& debug_stream () const;
276 /// Set the current debugging stream.
277 void set_debug_stream (std::ostream
&);
279 /// Type for debugging levels.
280 typedef int debug_level_type
;
281 /// The current debugging level.
282 debug_level_type
debug_level () const;
283 /// Set the current debugging level.
284 void set_debug_level (debug_level_type l
);
288 /// Report a syntax error.
289 /// \param loc where the syntax error is found.
290 /// \param msg a description of the syntax error.
291 virtual void error (const location_type
& loc
, const std::string
& msg
);
293 /// Generate an error message.
294 /// \param state the state where the error occurred.
295 /// \param tok the lookahead token.
296 virtual std::string
yysyntax_error_ (int yystate
]dnl
297 b4_error_verbose_if([, int tok
])[);
300 /// \brief Report a symbol value on the debug stream.
301 /// \param yytype The token type.
302 /// \param yyvalue Its semantic value.
303 /// \param yylocation Its location.
304 virtual void yy_symbol_value_print_ (int yytype
,
305 const semantic_type
& yyvalue
,
306 const location_type
& yylocation
);
307 /// \brief Report a symbol on the debug stream.
308 /// \param yytype The token type.
309 /// \param yyvalue Its semantic value.
310 /// \param yylocation Its location.
311 virtual void yy_symbol_print_ (int yytype
,
312 const semantic_type
& yyvalue
,
313 const location_type
& yylocation
);
318 typedef int state_type
;
319 /// State stack type.
320 typedef stack
<state_type
> state_stack_type
;
321 /// Semantic value stack type.
322 typedef stack
<semantic_type
> semantic_stack_type
;
323 /// location stack type.
324 typedef stack
<location_type
> location_stack_type
;
327 state_stack_type yystate_stack_
;
328 /// The semantic value stack.
329 semantic_stack_type yysemantic_stack_
;
330 /// The location stack.
331 location_stack_type yylocation_stack_
;
333 /// Internal symbol numbers.
334 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
336 /// For a state, the index in \a yytable_ of its portion.
337 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
338 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
340 /// For a state, default rule to reduce.
341 /// Unless\a yytable_ specifies something else to do.
342 /// Zero means the default is an error.
343 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
345 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
346 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
348 /// What to do in a state.
349 /// \a yytable_[yypact_[s]]: what to do in state \a s.
350 /// - if positive, shift that token.
351 /// - if negative, reduce the rule which number is the opposite.
352 /// - if zero, do what YYDEFACT says.
353 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
354 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
356 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
358 /// For a state, its accessing symbol.
359 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
361 /// For a rule, its LHS.
362 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
363 /// For a rule, its RHS length.
364 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
366 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
367 /// For a symbol, its name in clear.
368 static const char* const yytname_
[];
372 /// Convert the symbol name \a n to a form suitable for a diagnostic.
373 virtual std::string
yytnamerr_ (const char *n
);
377 /// A type to store symbol numbers and -1.
378 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
379 /// A `-1'-separated list of the rules' RHS.
380 static const rhs_number_type yyrhs_
[];
381 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
382 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
383 /// For each rule, its source line number.
384 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
385 /// For each scanner token number, its symbol number.
386 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
387 /// Report on the debug stream that the rule \a r is going to be reduced.
388 virtual void yy_reduce_print_ (int r
);
389 /// Print the state stack on the debug stream.
390 virtual void yystack_print_ ();
394 std::ostream
* yycdebug_
;
397 /// Convert a scanner token number \a t to a symbol number.
398 token_number_type
yytranslate_ (int t
);
400 /// \brief Reclaim the memory associated to a symbol.
401 /// \param yymsg Why this token is reclaimed.
402 /// \param yytype The symbol type.
403 /// \param yyvalue Its semantic value.
404 /// \param yylocation Its location.
405 inline void yydestruct_ (const char* yymsg
,
407 semantic_type
& yyvalue
,
408 location_type
& yylocation
);
410 /// Push a new state on the stack.
411 /// \warning the contents of \a v is stolen.
412 inline void yypush_ (state_type s
,
413 semantic_type
& v
, const location_type
& l
);
415 /// Pop \a n symbols the three stacks.
416 inline void yypop_ (unsigned int n
= 1);
419 static const int yyeof_
;
420 /* LAST_ -- Last index in TABLE_. */
421 static const int yylast_
;
422 static const int yynnts_
;
423 static const int yyempty_
;
424 static const int yyfinal_
;
425 static const int yyterror_
;
426 static const int yyerrcode_
;
427 static const int yyntokens_
;
428 static const unsigned int yyuser_token_number_max_
;
429 static const token_number_type yyundef_token_
;
430 ]b4_parse_param_vars
[
434 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
435 [b4_token_defines(b4_tokens
)
438 /* Redirection for backward compatibility. */
439 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
442 b4_percent_code_get([[provides]])[]dnl
444 [#endif /* ! defined PARSER_HEADER_H */]
446 @
output(b4_parser_file_name@
)
447 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++],
448 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
449 b4_percent_code_get([[top]])[]dnl
450 m4_if(b4_prefix
, [yy
], [],
452 // Take the name prefix into account.
453 #define yylex b4_prefix[]lex])[
455 /* First part of user declarations. */
456 ]b4_user_pre_prologue
459 #include "@basename(]b4_spec_defines_file[@)"]])[
461 /* User implementation prologue. */
462 ]b4_user_post_prologue
463 b4_percent_code_get
[]dnl
468 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
469 # define YY_(msgid) dgettext ("bison-runtime", msgid)
473 # define YY_(msgid) msgid
477 /* Suppress unused-variable warnings by "using" E. */
478 #define YYUSE(e) ((void) (e))
480 /* Enable debugging if requested. */
483 /* A pseudo ostream that takes yydebug_ into account. */
484 # define YYCDEBUG if (yydebug_) (*yycdebug_)
486 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
490 *yycdebug_ << Title << ' '; \
491 yy_symbol_print_ ((Type), (Value), (Location)); \
492 *yycdebug_ << std::endl; \
496 # define YY_REDUCE_PRINT(Rule) \
499 yy_reduce_print_ (Rule); \
502 # define YY_STACK_PRINT() \
510 # define YYCDEBUG if (false) std::cerr
511 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
512 # define YY_REDUCE_PRINT(Rule)
513 # define YY_STACK_PRINT()
515 #endif /* !YYDEBUG */
517 #define yyerrok (yyerrstatus_ = 0)
518 #define yyclearin (yychar = yyempty_)
520 #define YYACCEPT goto yyacceptlab
521 #define YYABORT goto yyabortlab
522 #define YYERROR goto yyerrorlab
523 #define YYRECOVERING() (!!yyerrstatus_)
528 /* Return YYSTR after stripping away unnecessary quotes and
529 backslashes, so that it's suitable for yyerror. The heuristic is
530 that double-quoting is unnecessary unless the string contains an
531 apostrophe, a comma, or backslash (other than backslash-backslash).
532 YYSTR is taken from yytname. */
534 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
538 std::string yyr
= "";
539 char const *yyp
= yystr
;
546 goto do_not_strip_quotes
;
550 goto do_not_strip_quotes
;
559 do_not_strip_quotes
: ;
567 /// Build a parser object.
568 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
571 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
572 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
573 #endif]b4_parse_param_cons[
577 ]b4_parser_class_name::~b4_parser_class_name
[ ()
582 /*--------------------------------.
583 | Print this symbol on YYOUTPUT. |
584 `--------------------------------*/
587 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
588 const semantic_type
& yyvalue
, const location_type
& yylocation
)
594 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
602 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
603 const semantic_type
& yyvalue
, const location_type
& yylocation
)
605 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
606 << ' ' << yytname_
[yytype
] << " ("
607 << yylocation
<< ": ";
608 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
614 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
615 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
621 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
625 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
632 ]b4_parser_class_name
[::yypush_ (state_type s
,
633 semantic_type
& v
, const location_type
& l
)
635 yystate_stack_
.push (s
);
636 yysemantic_stack_
.push (v
);
637 yylocation_stack_
.push (l
);
641 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
643 yystate_stack_
.pop (n
);
644 yysemantic_stack_
.pop (n
);
645 yylocation_stack_
.pop (n
);
650 ]b4_parser_class_name
[::debug_stream () const
656 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
662 ]b4_parser_class_name
[::debug_level_type
663 ]b4_parser_class_name
[::debug_level () const
669 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
676 ]b4_parser_class_name
[::parse ()
678 /// Lookahead and lookahead in internal form.
679 int yychar
= yyempty_
;
687 /* Error handling. */
689 int yyerrstatus_
= 0;
691 /// Semantic value of the lookahead.
692 semantic_type yylval
;
693 /// Location of the lookahead.
694 location_type yylloc
;
695 /// The locations where the error started and ended.
696 location_type yyerror_range
[2];
705 YYCDEBUG
<< "Starting parse" << std::endl
;
707 ]m4_ifdef([b4_initial_action
], [
708 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
709 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
710 /* User initialization code. */
711 b4_user_initial_action
712 m4_popdef([b4_dollar_dollar
])dnl
713 m4_popdef([b4_at_dollar
])])dnl
715 [ /* Initialize the stacks. The initial state will be pushed in
716 yynewstate, since the latter expects the semantical and the
717 location values to have been already stored, initialize these
718 stacks with a primary value. */
719 yystate_stack_
= state_stack_type (0);
720 yysemantic_stack_
= semantic_stack_type (0);
721 yylocation_stack_
= location_stack_type (0);
722 yypush_ (yystate
, yylval
, yylloc
);
724 // A new state was pushed on the stack.
725 // Invariant: yystate == yystack_[0].state, i.e.,
726 // yystate was just pushed onto the state stack.
728 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
731 if (yystate
== yyfinal_
)
739 /* Try to take a decision without lookahead. */
740 yyn
= yypact_
[yystate
];
741 if (yyn
== yypact_ninf_
)
744 /* Read a lookahead token. */
745 if (yychar
== yyempty_
)
747 YYCDEBUG
<< "Reading a token: ";
748 yychar
= ]b4_c_function_call([yylex
], [int],
749 [[YYSTYPE
*], [&yylval
]][]dnl
750 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
751 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
755 /* Convert token to internal form. */
756 if (yychar
<= yyeof_
)
758 yychar
= yytoken
= yyeof_
;
759 YYCDEBUG
<< "Now at end of input." << std::endl
;
763 yytoken
= yytranslate_ (yychar
);
764 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
767 /* If the proper action on seeing token YYTOKEN is to reduce or to
768 detect an error, take that action. */
770 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
773 /* Reduce or error. */
777 if (yyn
== 0 || yyn
== yytable_ninf_
)
783 /* Shift the lookahead token. */
784 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylval
, yylloc
);
786 /* Discard the token being shifted. */
789 /* Count tokens shifted since error; after three, turn off error
795 yypush_ (yystate
, yylval
, yylloc
);
798 /*-----------------------------------------------------------.
799 | yydefault -- do the default action for the current state. |
800 `-----------------------------------------------------------*/
802 yyn
= yydefact_
[yystate
];
807 /*-----------------------------.
808 | yyreduce -- Do a reduction. |
809 `-----------------------------*/
811 yylen
= yyr2_
[yyn
];]b4_variant_if([
812 /* Variants are always initialized to an empty instance of the
813 correct type. The default $$=$1 rule is NOT applied when using
815 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
816 /* If YYLEN is nonzero, implement the default value of the action:
817 `$$ = $1'. Otherwise, use the top of the stack.
819 Otherwise, the following line sets YYVAL to garbage.
820 This behavior is undocumented and Bison
821 users should not rely upon it. */
823 yyval
= yysemantic_stack_@
{yylen
- 1@
};
825 yyval
= yysemantic_stack_@
{0@
};])[
828 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen
);
829 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
831 YY_REDUCE_PRINT (yyn
);
838 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], yyval
, yyloc
);
844 /* Shift the result of the reduction. */
846 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystate_stack_
[0];
847 if (0 <= yystate
&& yystate
<= yylast_
848 && yycheck_
[yystate
] == yystate_stack_
[0])
849 yystate
= yytable_
[yystate
];
851 yystate
= yydefgoto_
[yyn
- yyntokens_
];
852 yypush_ (yystate
, yyval
, yyloc
);
855 /*------------------------------------.
856 | yyerrlab -- here on detecting error |
857 `------------------------------------*/
859 /* If not already recovering from an error, report this error. */
863 error (yylloc
, yysyntax_error_ (yystate
]dnl
864 b4_error_verbose_if([, yytoken
])[));
867 yyerror_range
[0] = yylloc
;
868 if (yyerrstatus_
== 3)
870 /* If just tried and failed to reuse lookahead token after an
871 error, discard it. */
873 if (yychar
<= yyeof_
)
875 /* Return failure if at end of input. */
876 if (yychar
== yyeof_
)
881 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
886 /* Else will try to reuse lookahead token after shifting the error
891 /*---------------------------------------------------.
892 | yyerrorlab -- error raised explicitly by YYERROR. |
893 `---------------------------------------------------*/
896 /* Pacify compilers like GCC when the user code never invokes
897 YYERROR and the label yyerrorlab therefore never appears in user
902 yyerror_range
[0] = yylocation_stack_
[yylen
- 1];
903 /* Do not reclaim the symbols of the rule which action triggered
907 yystate
= yystate_stack_
[0];
910 /*-------------------------------------------------------------.
911 | yyerrlab1 -- common code for both syntax error and YYERROR. |
912 `-------------------------------------------------------------*/
914 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
918 yyn
= yypact_
[yystate
];
919 if (yyn
!= yypact_ninf_
)
922 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
930 /* Pop the current state because it cannot handle the error token. */
931 if (yystate_stack_
.size () == 1)
934 yyerror_range
[0] = yylocation_stack_
[0];
935 yydestruct_ ("Error: popping",
937 yysemantic_stack_
[0], yylocation_stack_
[0]);
939 yystate
= yystate_stack_
[0];
943 yyerror_range
[1] = yylloc
;
944 // Using YYLLOC is tempting, but would change the location of
945 // the lookahead. YYLOC is available though.
946 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
948 /* Shift the error token. */
949 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
950 yysemantic_stack_
[0], yylocation_stack_
[0]);
953 yypush_ (yystate
, yylval
, yyloc
);
967 if (yychar
!= yyempty_
)
968 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
970 /* Do not reclaim the symbols of the rule which action triggered
971 this YYABORT or YYACCEPT. */
973 while (yystate_stack_
.size () != 1)
975 yydestruct_ ("Cleanup: popping",
976 yystos_
[yystate_stack_
[0]],
977 yysemantic_stack_
[0],
978 yylocation_stack_
[0]);
985 // Generate an error message.
987 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
]dnl
988 b4_error_verbose_if([, int tok
])[)
993 int yyn
= yypact_
[yystate
];
994 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
996 /* Start YYX at -YYN if negative to avoid negative indexes in
998 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1000 /* Stay within bounds of both yycheck and yytname. */
1001 int yychecklim
= yylast_
- yyn
+ 1;
1002 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1004 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1005 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1008 // FIXME: This method of building the message is not compatible
1009 // with internationalization. It should work like yacc.c does it.
1010 // That is, first build a string that looks like this:
1011 // "syntax error, unexpected %s or %s or %s"
1012 // Then, invoke YY_ on this string.
1013 // Finally, use the string as a format to output
1014 // yytname_[tok], etc.
1015 // Until this gets fixed, this message appears in English only.
1016 res
= "syntax error, unexpected ";
1017 res
+= yytnamerr_ (yytname_
[tok
]);
1021 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1022 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1024 res
+= (!count
++) ? ", expecting " : " or ";
1025 res
+= yytnamerr_ (yytname_
[x
]);
1031 res
= YY_("syntax error");
1036 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1038 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1039 const ]b4_int_type_for([b4_pact
])[
1040 ]b4_parser_class_name
[::yypact_
[] =
1045 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1046 doesn't specify something else to do. Zero means the default is an
1048 const ]b4_int_type_for([b4_defact
])[
1049 ]b4_parser_class_name
[::yydefact_
[] =
1054 /* YYPGOTO[NTERM-NUM]. */
1055 const ]b4_int_type_for([b4_pgoto
])[
1056 ]b4_parser_class_name
[::yypgoto_
[] =
1061 /* YYDEFGOTO[NTERM-NUM]. */
1062 const ]b4_int_type_for([b4_defgoto
])[
1063 ]b4_parser_class_name
[::yydefgoto_
[] =
1068 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1069 positive, shift that token. If negative, reduce the rule which
1070 number is the opposite. If zero, do what YYDEFACT says. */
1071 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1072 const ]b4_int_type_for([b4_table
])[
1073 ]b4_parser_class_name
[::yytable_
[] =
1079 const ]b4_int_type_for([b4_check
])[
1080 ]b4_parser_class_name
[::yycheck_
[] =
1085 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1086 symbol of state STATE-NUM. */
1087 const ]b4_int_type_for([b4_stos
])[
1088 ]b4_parser_class_name
[::yystos_
[] =
1094 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1096 const ]b4_int_type_for([b4_toknum
])[
1097 ]b4_parser_class_name
[::yytoken_number_
[] =
1103 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1104 const ]b4_int_type_for([b4_r1
])[
1105 ]b4_parser_class_name
[::yyr1_
[] =
1110 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1111 const ]b4_int_type_for([b4_r2
])[
1112 ]b4_parser_class_name
[::yyr2_
[] =
1117 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1118 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1119 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1121 const ]b4_parser_class_name
[::yytname_
[] =
1128 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1129 const ]b4_parser_class_name
[::rhs_number_type
1130 ]b4_parser_class_name
[::yyrhs_
[] =
1135 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1137 const ]b4_int_type_for([b4_prhs
])[
1138 ]b4_parser_class_name
[::yyprhs_
[] =
1143 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1144 const ]b4_int_type_for([b4_rline
])[
1145 ]b4_parser_class_name
[::yyrline_
[] =
1150 // Print the state stack on the debug stream.
1152 ]b4_parser_class_name
[::yystack_print_ ()
1154 *yycdebug_
<< "Stack now";
1155 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1156 i
!= yystate_stack_
.end (); ++i
)
1157 *yycdebug_
<< ' ' << *i
;
1158 *yycdebug_
<< std::endl
;
1161 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1163 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1165 unsigned int yylno
= yyrline_
[yyrule
];
1166 int yynrhs
= yyr2_
[yyrule
];
1167 /* Print the symbols being reduced, and their result. */
1168 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1169 << " (line " << yylno
<< "):" << std::endl
;
1170 /* The symbols being reduced. */
1171 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1172 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1173 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1174 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1175 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1179 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1180 ]b4_parser_class_name
[::token_number_type
1181 ]b4_parser_class_name
[::yytranslate_ (int t
)
1184 const token_number_type
1189 if ((unsigned int) t
<= yyuser_token_number_max_
)
1190 return translate_table
[t
];
1192 return yyundef_token_
;
1195 const int ]b4_parser_class_name
[::yyeof_
= 0;
1196 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1197 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1198 const int ]b4_parser_class_name
[::yyempty_
= -2;
1199 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1200 const int ]b4_parser_class_name
[::yyterror_
= 1;
1201 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1202 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1204 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1205 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1207 ]b4_namespace_close
[
1211 @
output(b4_dir_prefix
[]stack
.hh@
)
1212 b4_copyright([Stack handling
for Bison parsers in C
++],
1213 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1215 #ifndef BISON_STACK_HH
1216 # define BISON_STACK_HH
1221 template <class T
, class S
= std::deque
<T
> >
1226 // Hide our reversed order.
1227 typedef typename
S::reverse_iterator iterator
;
1228 typedef typename
S::const_reverse_iterator const_iterator
;
1234 stack (unsigned int n
) : seq_ (n
)
1240 operator [] (unsigned int i
)
1247 operator [] (unsigned int i
) const
1256 seq_
.push_front (t
);
1261 pop (unsigned int n
= 1)
1268 typename
S::size_type
1271 return seq_
.size ();
1274 inline const_iterator
begin () const { return seq_
.rbegin (); }
1275 inline const_iterator
end () const { return seq_
.rend (); }
1278 /// The wrapped container.
1282 /// Present a slice of the top of a stack.
1283 template <class T
, class S
= stack
<T
> >
1288 slice (const S
& stack
,
1289 unsigned int range
) : stack_ (stack
),
1296 operator [] (unsigned int i
) const
1298 return stack_
[range_
- i
];
1304 unsigned int range_
;
1306 ]b4_namespace_close
[
1308 #endif // not BISON_STACK_HH[]dnl