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_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
33 # ----------------------------------------------------------
34 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
35 m4_define([b4_symbol_action_
],
43 # b4_symbol_variant(YYTYPE, YYVAL, ACTION)
44 # ----------------------------------------
45 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
47 m4_define([b4_symbol_variant
],
48 [m4_pushdef([b4_dollar_dollar
],
52 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
56 m4_popdef([b4_dollar_dollar
])dnl
60 # _b4_char_sizeof_counter
61 # -----------------------
62 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
63 m4_define([_b4_char_sizeof_counter
],
66 # _b4_char_sizeof_dummy
67 # ---------------------
68 # At each call return a new C++ identifier.
69 m4_define([_b4_char_sizeof_dummy
],
70 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
71 dummy
[]_b4_char_sizeof_counter
])
74 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
75 # -------------------------------------------------------
76 # To be mapped on the list of type names to produce:
78 # char dummy1[sizeof(type_name_1)];
79 # char dummy2[sizeof(type_name_2)];
81 # for defined type names.
82 # $3 is doubly-quoted, do not quote it again.
83 m4_define([b4_char_sizeof
],
86 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
90 m4_define([b4_parser_class_name
],
91 [b4_percent_define_get([[parser_class_name]])])
93 # The header is mandatory.
95 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
97 # Backward compatibility.
98 m4_define([b4_location_constructors
])
99 m4_include(b4_pkgdatadir
/[location
.cc
])
101 # We do want M4 expansion after # for CPP macros.
105 [@
output(b4_spec_defines_file@
)
106 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++],
107 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
108 dnl FIXME
: This is wrong
, we want computed header guards
.
110 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
112 #ifndef PARSER_HEADER_H
113 # define PARSER_HEADER_H
115 ]b4_percent_code_get([[requires]])[
125 /// A char[S] buffer to store and retrieve objects.
127 /// Sort of a variant, but does not keep track of the nature
128 /// of the stored data, since that knowledge is available
129 /// via the current state.
133 /// Instantiate a \a T in here.
134 template <typename T
>
141 /// Destroy the stored \a T.
142 template <typename T
>
146 reinterpret_cast<T
&>(buffer
).~T();
149 /// Accessor to a built \a T.
150 template <typename T
>
154 return reinterpret_cast<T
&>(buffer
);
157 /// Const accessor to a built \a T (for %printer).
158 template <typename T
>
162 return reinterpret_cast<const T
&>(buffer
);
165 /// A buffer large enough to store any of the semantic values.
171 #include "location.hh"
173 /* Enabling traces. */
175 # define YYDEBUG ]b4_debug_flag[
178 /* Enabling verbose error messages. */
179 #ifdef YYERROR_VERBOSE
180 # undef YYERROR_VERBOSE
181 # define YYERROR_VERBOSE 1
183 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
186 /* Enabling the token table. */
187 #ifndef YYTOKEN_TABLE
188 # define YYTOKEN_TABLE ]b4_token_table[
191 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
192 If N is 0, then set CURRENT to the empty location which ends
193 the previous symbol: RHS[0] (always defined). */
195 #ifndef YYLLOC_DEFAULT
196 # define YYLLOC_DEFAULT(Current, Rhs, N) \
200 (Current).begin = (Rhs)[1].begin; \
201 (Current).end = (Rhs)[N].end; \
205 (Current).begin = (Current).end = (Rhs)[0].end; \
213 class ]b4_parser_class_name
[
218 [ /// An auxiliary type to compute the largest semantic type.
220 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
223 /// Symbol semantic values.
224 typedef variant
<sizeof(union_type
)> semantic_type
;],
225 [ /// Symbol semantic values.
227 [ union semantic_type
230 [m4_if(b4_tag_seen_flag
, 0,
231 [[ typedef int semantic_type
;]],
232 [[ typedef YYSTYPE semantic_type
;]])])])[
234 typedef YYSTYPE semantic_type
;
236 /// Symbol locations.
237 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
241 ]b4_token_enums(b4_tokens
)[
244 typedef token::yytokentype token_type
;
246 /// Build a parser object.
247 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
248 virtual ~]b4_parser_class_name
[ ();
251 /// \returns 0 iff parsing succeeded.
252 virtual int parse ();
255 /// The current debugging stream.
256 std::ostream
& debug_stream () const;
257 /// Set the current debugging stream.
258 void set_debug_stream (std::ostream
&);
260 /// Type for debugging levels.
261 typedef int debug_level_type
;
262 /// The current debugging level.
263 debug_level_type
debug_level () const;
264 /// Set the current debugging level.
265 void set_debug_level (debug_level_type l
);
269 /// Report a syntax error.
270 /// \param loc where the syntax error is found.
271 /// \param msg a description of the syntax error.
272 virtual void error (const location_type
& loc
, const std::string
& msg
);
274 /// Generate an error message.
275 /// \param state the state where the error occurred.
276 /// \param tok the lookahead token.
277 virtual std::string
yysyntax_error_ (int yystate
]dnl
278 b4_error_verbose_if([, int tok
])[);
281 /// \brief Report a symbol value on the debug stream.
282 /// \param yytype The token type.
283 /// \param yyvaluep Its semantic value.
284 /// \param yylocationp Its location.
285 virtual void yy_symbol_value_print_ (int yytype
,
286 const semantic_type
* yyvaluep
,
287 const location_type
* yylocationp
);
288 /// \brief Report a symbol on the debug stream.
289 /// \param yytype The token type.
290 /// \param yyvaluep Its semantic value.
291 /// \param yylocationp Its location.
292 virtual void yy_symbol_print_ (int yytype
,
293 const semantic_type
* yyvaluep
,
294 const location_type
* yylocationp
);
299 typedef int state_type
;
300 /// State stack type.
301 typedef stack
<state_type
> state_stack_type
;
302 /// Semantic value stack type.
303 typedef stack
<semantic_type
> semantic_stack_type
;
304 /// location stack type.
305 typedef stack
<location_type
> location_stack_type
;
308 state_stack_type yystate_stack_
;
309 /// The semantic value stack.
310 semantic_stack_type yysemantic_stack_
;
311 /// The location stack.
312 location_stack_type yylocation_stack_
;
314 /// Internal symbol numbers.
315 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
317 /// For a state, the index in \a yytable_ of its portion.
318 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
319 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
321 /// For a state, default rule to reduce.
322 /// Unless\a yytable_ specifies something else to do.
323 /// Zero means the default is an error.
324 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
326 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
327 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
329 /// What to do in a state.
330 /// \a yytable_[yypact_[s]]: what to do in state \a s.
331 /// - if positive, shift that token.
332 /// - if negative, reduce the rule which number is the opposite.
333 /// - if zero, do what YYDEFACT says.
334 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
335 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
337 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
339 /// For a state, its accessing symbol.
340 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
342 /// For a rule, its LHS.
343 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
344 /// For a rule, its RHS length.
345 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
347 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
348 /// For a symbol, its name in clear.
349 static const char* const yytname_
[];
353 /// Convert the symbol name \a n to a form suitable for a diagnostic.
354 virtual std::string
yytnamerr_ (const char *n
);
358 /// A type to store symbol numbers and -1.
359 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
360 /// A `-1'-separated list of the rules' RHS.
361 static const rhs_number_type yyrhs_
[];
362 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
363 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
364 /// For each rule, its source line number.
365 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
366 /// For each scanner token number, its symbol number.
367 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
368 /// Report on the debug stream that the rule \a r is going to be reduced.
369 virtual void yy_reduce_print_ (int r
);
370 /// Print the state stack on the debug stream.
371 virtual void yystack_print_ ();
375 std::ostream
* yycdebug_
;
378 /// Convert a scanner token number \a t to a symbol number.
379 token_number_type
yytranslate_ (int t
);
381 /// \brief Reclaim the memory associated to a symbol.
382 /// \param yymsg Why this token is reclaimed.
383 /// \param yytype The symbol type.
384 /// \param yyvaluep Its semantic value.
385 /// \param yylocationp Its location.
386 inline void yydestruct_ (const char* yymsg
,
388 semantic_type
* yyvaluep
,
389 location_type
* yylocationp
);
391 /// Pop \a n symbols the three stacks.
392 inline void yypop_ (unsigned int n
= 1);
395 static const int yyeof_
;
396 /* LAST_ -- Last index in TABLE_. */
397 static const int yylast_
;
398 static const int yynnts_
;
399 static const int yyempty_
;
400 static const int yyfinal_
;
401 static const int yyterror_
;
402 static const int yyerrcode_
;
403 static const int yyntokens_
;
404 static const unsigned int yyuser_token_number_max_
;
405 static const token_number_type yyundef_token_
;
406 ]b4_parse_param_vars
[
410 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
411 [b4_token_defines(b4_tokens
)
414 /* Redirection for backward compatibility. */
415 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
418 b4_percent_code_get([[provides]])[]dnl
420 [#endif /* ! defined PARSER_HEADER_H */]
422 @
output(b4_parser_file_name@
)
423 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++],
424 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
425 b4_percent_code_get([[top]])[]dnl
426 m4_if(b4_prefix
, [yy
], [],
428 // Take the name prefix into account.
429 #define yylex b4_prefix[]lex])[
431 /* First part of user declarations. */
432 ]b4_user_pre_prologue
435 #include "@basename(]b4_spec_defines_file[@)"]])[
437 /* User implementation prologue. */
438 ]b4_user_post_prologue
439 b4_percent_code_get
[]dnl
444 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
445 # define YY_(msgid) dgettext ("bison-runtime", msgid)
449 # define YY_(msgid) msgid
453 /* Suppress unused-variable warnings by "using" E. */
454 #define YYUSE(e) ((void) (e))
456 /* Enable debugging if requested. */
459 /* A pseudo ostream that takes yydebug_ into account. */
460 # define YYCDEBUG if (yydebug_) (*yycdebug_)
462 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
466 *yycdebug_ << Title << ' '; \
467 yy_symbol_print_ ((Type), (Value), (Location)); \
468 *yycdebug_ << std::endl; \
472 # define YY_REDUCE_PRINT(Rule) \
475 yy_reduce_print_ (Rule); \
478 # define YY_STACK_PRINT() \
486 # define YYCDEBUG if (false) std::cerr
487 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
488 # define YY_REDUCE_PRINT(Rule)
489 # define YY_STACK_PRINT()
491 #endif /* !YYDEBUG */
493 #define yyerrok (yyerrstatus_ = 0)
494 #define yyclearin (yychar = yyempty_)
496 #define YYACCEPT goto yyacceptlab
497 #define YYABORT goto yyabortlab
498 #define YYERROR goto yyerrorlab
499 #define YYRECOVERING() (!!yyerrstatus_)
504 /* Return YYSTR after stripping away unnecessary quotes and
505 backslashes, so that it's suitable for yyerror. The heuristic is
506 that double-quoting is unnecessary unless the string contains an
507 apostrophe, a comma, or backslash (other than backslash-backslash).
508 YYSTR is taken from yytname. */
510 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
514 std::string yyr
= "";
515 char const *yyp
= yystr
;
522 goto do_not_strip_quotes
;
526 goto do_not_strip_quotes
;
535 do_not_strip_quotes
: ;
543 /// Build a parser object.
544 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
547 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
548 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
549 #endif]b4_parse_param_cons[
553 ]b4_parser_class_name::~b4_parser_class_name
[ ()
558 /*--------------------------------.
559 | Print this symbol on YYOUTPUT. |
560 `--------------------------------*/
563 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
564 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
570 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
578 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
579 const semantic_type
* yyvaluep
, const location_type
* yylocationp
)
581 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
582 << ' ' << yytname_
[yytype
] << " ("
583 << *yylocationp
<< ": ";
584 yy_symbol_value_print_ (yytype
, yyvaluep
, yylocationp
);
590 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
591 int yytype
, semantic_type
* yyvaluep
, location_type
* yylocationp
)
597 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvaluep
, yylocationp
);
601 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
608 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
610 yystate_stack_
.pop (n
);
611 yysemantic_stack_
.pop (n
);
612 yylocation_stack_
.pop (n
);
617 ]b4_parser_class_name
[::debug_stream () const
623 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
629 ]b4_parser_class_name
[::debug_level_type
630 ]b4_parser_class_name
[::debug_level () const
636 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
643 ]b4_parser_class_name
[::parse ()
645 /// Lookahead and lookahead in internal form.
646 int yychar
= yyempty_
;
654 /* Error handling. */
656 int yyerrstatus_
= 0;
658 /// Semantic value of the lookahead.
659 semantic_type yylval
;
660 /// Location of the lookahead.
661 location_type yylloc
;
662 /// The locations where the error started and ended.
663 location_type yyerror_range
[2];
672 YYCDEBUG
<< "Starting parse" << std::endl
;
674 ]m4_ifdef([b4_initial_action
], [
675 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
676 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
677 /* User initialization code. */
678 b4_user_initial_action
679 m4_popdef([b4_dollar_dollar
])dnl
680 m4_popdef([b4_at_dollar
])])dnl
682 [ /* Initialize the stacks. The initial state will be pushed in
683 yynewstate, since the latter expects the semantical and the
684 location values to have been already stored, initialize these
685 stacks with a primary value. */
686 yystate_stack_
= state_stack_type (0);
687 yysemantic_stack_
= semantic_stack_type (0);
688 yylocation_stack_
= location_stack_type (0);
689 yysemantic_stack_
.push (yylval
);
690 yylocation_stack_
.push (yylloc
);
694 yystate_stack_
.push (yystate
);
695 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
698 if (yystate
== yyfinal_
)
706 /* Try to take a decision without lookahead. */
707 yyn
= yypact_
[yystate
];
708 if (yyn
== yypact_ninf_
)
711 /* Read a lookahead token. */
712 if (yychar
== yyempty_
)
714 YYCDEBUG
<< "Reading a token: ";
715 yychar
= ]b4_c_function_call([yylex
], [int],
716 [[YYSTYPE
*], [&yylval
]][]dnl
717 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
718 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
722 /* Convert token to internal form. */
723 if (yychar
<= yyeof_
)
725 yychar
= yytoken
= yyeof_
;
726 YYCDEBUG
<< "Now at end of input." << std::endl
;
730 yytoken
= yytranslate_ (yychar
);
731 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
734 /* If the proper action on seeing token YYTOKEN is to reduce or to
735 detect an error, take that action. */
737 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
740 /* Reduce or error. */
744 if (yyn
== 0 || yyn
== yytable_ninf_
)
750 /* Shift the lookahead token. */
751 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
753 /* Discard the token being shifted. */
755 yysemantic_stack_
.push (yylval
);
756 yylocation_stack_
.push (yylloc
);
758 /* Count tokens shifted since error; after three, turn off error
766 /*-----------------------------------------------------------.
767 | yydefault -- do the default action for the current state. |
768 `-----------------------------------------------------------*/
770 yyn
= yydefact_
[yystate
];
775 /*-----------------------------.
776 | yyreduce -- Do a reduction. |
777 `-----------------------------*/
779 yylen
= yyr2_
[yyn
];]b4_variant_if([
780 /* Variants are always initialized to an empty instance of the
781 correct type. The default $$=$1 rule is NOT applied when using
783 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
784 /* If YYLEN is nonzero, implement the default value of the action:
785 `$$ = $1'. Otherwise, use the top of the stack.
787 Otherwise, the following line sets YYVAL to garbage.
788 This behavior is undocumented and Bison
789 users should not rely upon it. */
791 yyval
= yysemantic_stack_@
{yylen
- 1@
};
793 yyval
= yysemantic_stack_@
{0@
};])[
796 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen
);
797 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
799 YY_REDUCE_PRINT (yyn
);
806 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], &yyval
, &yyloc
);
811 yysemantic_stack_
.push (yyval
);
812 yylocation_stack_
.push (yyloc
);
814 /* Shift the result of the reduction. */
816 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystate_stack_
[0];
817 if (0 <= yystate
&& yystate
<= yylast_
818 && yycheck_
[yystate
] == yystate_stack_
[0])
819 yystate
= yytable_
[yystate
];
821 yystate
= yydefgoto_
[yyn
- yyntokens_
];
824 /*------------------------------------.
825 | yyerrlab -- here on detecting error |
826 `------------------------------------*/
828 /* If not already recovering from an error, report this error. */
832 error (yylloc
, yysyntax_error_ (yystate
]dnl
833 b4_error_verbose_if([, yytoken
])[));
836 yyerror_range
[0] = yylloc
;
837 if (yyerrstatus_
== 3)
839 /* If just tried and failed to reuse lookahead token after an
840 error, discard it. */
842 if (yychar
<= yyeof_
)
844 /* Return failure if at end of input. */
845 if (yychar
== yyeof_
)
850 yydestruct_ ("Error: discarding", yytoken
, &yylval
, &yylloc
);
855 /* Else will try to reuse lookahead token after shifting the error
860 /*---------------------------------------------------.
861 | yyerrorlab -- error raised explicitly by YYERROR. |
862 `---------------------------------------------------*/
865 /* Pacify compilers like GCC when the user code never invokes
866 YYERROR and the label yyerrorlab therefore never appears in user
871 yyerror_range
[0] = yylocation_stack_
[yylen
- 1];
872 /* Do not reclaim the symbols of the rule which action triggered
876 yystate
= yystate_stack_
[0];
879 /*-------------------------------------------------------------.
880 | yyerrlab1 -- common code for both syntax error and YYERROR. |
881 `-------------------------------------------------------------*/
883 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
887 yyn
= yypact_
[yystate
];
888 if (yyn
!= yypact_ninf_
)
891 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
899 /* Pop the current state because it cannot handle the error token. */
900 if (yystate_stack_
.size () == 1)
903 yyerror_range
[0] = yylocation_stack_
[0];
904 yydestruct_ ("Error: popping",
906 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
908 yystate
= yystate_stack_
[0];
912 yyerror_range
[1] = yylloc
;
913 // Using YYLLOC is tempting, but would change the location of
914 // the lookahead. YYLOC is available though.
915 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
916 yysemantic_stack_
.push (yylval
);
917 yylocation_stack_
.push (yyloc
);
919 /* Shift the error token. */
920 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
921 &yysemantic_stack_
[0], &yylocation_stack_
[0]);
937 if (yychar
!= yyempty_
)
938 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, &yylval
, &yylloc
);
940 /* Do not reclaim the symbols of the rule which action triggered
941 this YYABORT or YYACCEPT. */
943 while (yystate_stack_
.size () != 1)
945 yydestruct_ ("Cleanup: popping",
946 yystos_
[yystate_stack_
[0]],
947 &yysemantic_stack_
[0],
948 &yylocation_stack_
[0]);
955 // Generate an error message.
957 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
]dnl
958 b4_error_verbose_if([, int tok
])[)
963 int yyn
= yypact_
[yystate
];
964 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
966 /* Start YYX at -YYN if negative to avoid negative indexes in
968 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
970 /* Stay within bounds of both yycheck and yytname. */
971 int yychecklim
= yylast_
- yyn
+ 1;
972 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
974 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
975 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
978 // FIXME: This method of building the message is not compatible
979 // with internationalization. It should work like yacc.c does it.
980 // That is, first build a string that looks like this:
981 // "syntax error, unexpected %s or %s or %s"
982 // Then, invoke YY_ on this string.
983 // Finally, use the string as a format to output
984 // yytname_[tok], etc.
985 // Until this gets fixed, this message appears in English only.
986 res
= "syntax error, unexpected ";
987 res
+= yytnamerr_ (yytname_
[tok
]);
991 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
992 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
994 res
+= (!count
++) ? ", expecting " : " or ";
995 res
+= yytnamerr_ (yytname_
[x
]);
1001 res
= YY_("syntax error");
1006 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1008 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1009 const ]b4_int_type_for([b4_pact
])[
1010 ]b4_parser_class_name
[::yypact_
[] =
1015 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1016 doesn't specify something else to do. Zero means the default is an
1018 const ]b4_int_type_for([b4_defact
])[
1019 ]b4_parser_class_name
[::yydefact_
[] =
1024 /* YYPGOTO[NTERM-NUM]. */
1025 const ]b4_int_type_for([b4_pgoto
])[
1026 ]b4_parser_class_name
[::yypgoto_
[] =
1031 /* YYDEFGOTO[NTERM-NUM]. */
1032 const ]b4_int_type_for([b4_defgoto
])[
1033 ]b4_parser_class_name
[::yydefgoto_
[] =
1038 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1039 positive, shift that token. If negative, reduce the rule which
1040 number is the opposite. If zero, do what YYDEFACT says. */
1041 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1042 const ]b4_int_type_for([b4_table
])[
1043 ]b4_parser_class_name
[::yytable_
[] =
1049 const ]b4_int_type_for([b4_check
])[
1050 ]b4_parser_class_name
[::yycheck_
[] =
1055 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1056 symbol of state STATE-NUM. */
1057 const ]b4_int_type_for([b4_stos
])[
1058 ]b4_parser_class_name
[::yystos_
[] =
1064 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1066 const ]b4_int_type_for([b4_toknum
])[
1067 ]b4_parser_class_name
[::yytoken_number_
[] =
1073 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1074 const ]b4_int_type_for([b4_r1
])[
1075 ]b4_parser_class_name
[::yyr1_
[] =
1080 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1081 const ]b4_int_type_for([b4_r2
])[
1082 ]b4_parser_class_name
[::yyr2_
[] =
1087 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1088 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1089 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1091 const ]b4_parser_class_name
[::yytname_
[] =
1098 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1099 const ]b4_parser_class_name
[::rhs_number_type
1100 ]b4_parser_class_name
[::yyrhs_
[] =
1105 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1107 const ]b4_int_type_for([b4_prhs
])[
1108 ]b4_parser_class_name
[::yyprhs_
[] =
1113 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1114 const ]b4_int_type_for([b4_rline
])[
1115 ]b4_parser_class_name
[::yyrline_
[] =
1120 // Print the state stack on the debug stream.
1122 ]b4_parser_class_name
[::yystack_print_ ()
1124 *yycdebug_
<< "Stack now";
1125 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1126 i
!= yystate_stack_
.end (); ++i
)
1127 *yycdebug_
<< ' ' << *i
;
1128 *yycdebug_
<< std::endl
;
1131 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1133 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1135 unsigned int yylno
= yyrline_
[yyrule
];
1136 int yynrhs
= yyr2_
[yyrule
];
1137 /* Print the symbols being reduced, and their result. */
1138 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1139 << " (line " << yylno
<< "):" << std::endl
;
1140 /* The symbols being reduced. */
1141 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1142 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1143 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1144 &]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1145 &]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1149 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1150 ]b4_parser_class_name
[::token_number_type
1151 ]b4_parser_class_name
[::yytranslate_ (int t
)
1154 const token_number_type
1159 if ((unsigned int) t
<= yyuser_token_number_max_
)
1160 return translate_table
[t
];
1162 return yyundef_token_
;
1165 const int ]b4_parser_class_name
[::yyeof_
= 0;
1166 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1167 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1168 const int ]b4_parser_class_name
[::yyempty_
= -2;
1169 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1170 const int ]b4_parser_class_name
[::yyterror_
= 1;
1171 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1172 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1174 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1175 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1177 ]b4_namespace_close
[
1181 @
output(b4_dir_prefix
[]stack
.hh@
)
1182 b4_copyright([Stack handling
for Bison parsers in C
++],
1183 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1185 #ifndef BISON_STACK_HH
1186 # define BISON_STACK_HH
1191 template <class T
, class S
= std::deque
<T
> >
1196 // Hide our reversed order.
1197 typedef typename
S::reverse_iterator iterator
;
1198 typedef typename
S::const_reverse_iterator const_iterator
;
1204 stack (unsigned int n
) : seq_ (n
)
1210 operator [] (unsigned int i
)
1217 operator [] (unsigned int i
) const
1226 seq_
.push_front (t
);
1231 pop (unsigned int n
= 1)
1238 typename
S::size_type
1241 return seq_
.size ();
1244 inline const_iterator
begin () const { return seq_
.rbegin (); }
1245 inline const_iterator
end () const { return seq_
.rend (); }
1248 /// The wrapped container.
1252 /// Present a slice of the top of a stack.
1253 template <class T
, class S
= stack
<T
> >
1258 slice (const S
& stack
,
1259 unsigned int range
) : stack_ (stack
),
1266 operator [] (unsigned int i
) const
1268 return stack_
[range_
- i
];
1274 unsigned int range_
;
1276 ]b4_namespace_close
[
1278 #endif // not BISON_STACK_HH[]dnl