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 /// Pop \a n symbols the three stacks.
411 inline void yypop_ (unsigned int n
= 1);
414 static const int yyeof_
;
415 /* LAST_ -- Last index in TABLE_. */
416 static const int yylast_
;
417 static const int yynnts_
;
418 static const int yyempty_
;
419 static const int yyfinal_
;
420 static const int yyterror_
;
421 static const int yyerrcode_
;
422 static const int yyntokens_
;
423 static const unsigned int yyuser_token_number_max_
;
424 static const token_number_type yyundef_token_
;
425 ]b4_parse_param_vars
[
429 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
430 [b4_token_defines(b4_tokens
)
433 /* Redirection for backward compatibility. */
434 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
437 b4_percent_code_get([[provides]])[]dnl
439 [#endif /* ! defined PARSER_HEADER_H */]
441 @
output(b4_parser_file_name@
)
442 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++],
443 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
444 b4_percent_code_get([[top]])[]dnl
445 m4_if(b4_prefix
, [yy
], [],
447 // Take the name prefix into account.
448 #define yylex b4_prefix[]lex])[
450 /* First part of user declarations. */
451 ]b4_user_pre_prologue
454 #include "@basename(]b4_spec_defines_file[@)"]])[
456 /* User implementation prologue. */
457 ]b4_user_post_prologue
458 b4_percent_code_get
[]dnl
463 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
464 # define YY_(msgid) dgettext ("bison-runtime", msgid)
468 # define YY_(msgid) msgid
472 /* Suppress unused-variable warnings by "using" E. */
473 #define YYUSE(e) ((void) (e))
475 /* Enable debugging if requested. */
478 /* A pseudo ostream that takes yydebug_ into account. */
479 # define YYCDEBUG if (yydebug_) (*yycdebug_)
481 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
485 *yycdebug_ << Title << ' '; \
486 yy_symbol_print_ ((Type), (Value), (Location)); \
487 *yycdebug_ << std::endl; \
491 # define YY_REDUCE_PRINT(Rule) \
494 yy_reduce_print_ (Rule); \
497 # define YY_STACK_PRINT() \
505 # define YYCDEBUG if (false) std::cerr
506 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
507 # define YY_REDUCE_PRINT(Rule)
508 # define YY_STACK_PRINT()
510 #endif /* !YYDEBUG */
512 #define yyerrok (yyerrstatus_ = 0)
513 #define yyclearin (yychar = yyempty_)
515 #define YYACCEPT goto yyacceptlab
516 #define YYABORT goto yyabortlab
517 #define YYERROR goto yyerrorlab
518 #define YYRECOVERING() (!!yyerrstatus_)
523 /* Return YYSTR after stripping away unnecessary quotes and
524 backslashes, so that it's suitable for yyerror. The heuristic is
525 that double-quoting is unnecessary unless the string contains an
526 apostrophe, a comma, or backslash (other than backslash-backslash).
527 YYSTR is taken from yytname. */
529 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
533 std::string yyr
= "";
534 char const *yyp
= yystr
;
541 goto do_not_strip_quotes
;
545 goto do_not_strip_quotes
;
554 do_not_strip_quotes
: ;
562 /// Build a parser object.
563 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
566 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
567 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
568 #endif]b4_parse_param_cons[
572 ]b4_parser_class_name::~b4_parser_class_name
[ ()
577 /*--------------------------------.
578 | Print this symbol on YYOUTPUT. |
579 `--------------------------------*/
582 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
583 const semantic_type
& yyvalue
, const location_type
& yylocation
)
589 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
597 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
598 const semantic_type
& yyvalue
, const location_type
& yylocation
)
600 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
601 << ' ' << yytname_
[yytype
] << " ("
602 << yylocation
<< ": ";
603 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
609 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
610 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
616 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
620 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
627 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
629 yystate_stack_
.pop (n
);
630 yysemantic_stack_
.pop (n
);
631 yylocation_stack_
.pop (n
);
636 ]b4_parser_class_name
[::debug_stream () const
642 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
648 ]b4_parser_class_name
[::debug_level_type
649 ]b4_parser_class_name
[::debug_level () const
655 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
662 ]b4_parser_class_name
[::parse ()
664 /// Lookahead and lookahead in internal form.
665 int yychar
= yyempty_
;
673 /* Error handling. */
675 int yyerrstatus_
= 0;
677 /// Semantic value of the lookahead.
678 semantic_type yylval
;
679 /// Location of the lookahead.
680 location_type yylloc
;
681 /// The locations where the error started and ended.
682 location_type yyerror_range
[2];
691 YYCDEBUG
<< "Starting parse" << std::endl
;
693 ]m4_ifdef([b4_initial_action
], [
694 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
695 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
696 /* User initialization code. */
697 b4_user_initial_action
698 m4_popdef([b4_dollar_dollar
])dnl
699 m4_popdef([b4_at_dollar
])])dnl
701 [ /* Initialize the stacks. The initial state will be pushed in
702 yynewstate, since the latter expects the semantical and the
703 location values to have been already stored, initialize these
704 stacks with a primary value. */
705 yystate_stack_
= state_stack_type (0);
706 yysemantic_stack_
= semantic_stack_type (0);
707 yylocation_stack_
= location_stack_type (0);
708 yysemantic_stack_
.push (yylval
);
709 yylocation_stack_
.push (yylloc
);
713 yystate_stack_
.push (yystate
);
714 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
717 if (yystate
== yyfinal_
)
725 /* Try to take a decision without lookahead. */
726 yyn
= yypact_
[yystate
];
727 if (yyn
== yypact_ninf_
)
730 /* Read a lookahead token. */
731 if (yychar
== yyempty_
)
733 YYCDEBUG
<< "Reading a token: ";
734 yychar
= ]b4_c_function_call([yylex
], [int],
735 [[YYSTYPE
*], [&yylval
]][]dnl
736 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
737 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
741 /* Convert token to internal form. */
742 if (yychar
<= yyeof_
)
744 yychar
= yytoken
= yyeof_
;
745 YYCDEBUG
<< "Now at end of input." << std::endl
;
749 yytoken
= yytranslate_ (yychar
);
750 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
753 /* If the proper action on seeing token YYTOKEN is to reduce or to
754 detect an error, take that action. */
756 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
759 /* Reduce or error. */
763 if (yyn
== 0 || yyn
== yytable_ninf_
)
769 /* Shift the lookahead token. */
770 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylval
, yylloc
);
772 /* Discard the token being shifted. */
774 yysemantic_stack_
.push (yylval
);
775 yylocation_stack_
.push (yylloc
);
777 /* Count tokens shifted since error; after three, turn off error
785 /*-----------------------------------------------------------.
786 | yydefault -- do the default action for the current state. |
787 `-----------------------------------------------------------*/
789 yyn
= yydefact_
[yystate
];
794 /*-----------------------------.
795 | yyreduce -- Do a reduction. |
796 `-----------------------------*/
798 yylen
= yyr2_
[yyn
];]b4_variant_if([
799 /* Variants are always initialized to an empty instance of the
800 correct type. The default $$=$1 rule is NOT applied when using
802 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
803 /* If YYLEN is nonzero, implement the default value of the action:
804 `$$ = $1'. Otherwise, use the top of the stack.
806 Otherwise, the following line sets YYVAL to garbage.
807 This behavior is undocumented and Bison
808 users should not rely upon it. */
810 yyval
= yysemantic_stack_@
{yylen
- 1@
};
812 yyval
= yysemantic_stack_@
{0@
};])[
815 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen
);
816 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
818 YY_REDUCE_PRINT (yyn
);
825 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], yyval
, yyloc
);
830 yysemantic_stack_
.push (yyval
);
831 yylocation_stack_
.push (yyloc
);
833 /* Shift the result of the reduction. */
835 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystate_stack_
[0];
836 if (0 <= yystate
&& yystate
<= yylast_
837 && yycheck_
[yystate
] == yystate_stack_
[0])
838 yystate
= yytable_
[yystate
];
840 yystate
= yydefgoto_
[yyn
- yyntokens_
];
843 /*------------------------------------.
844 | yyerrlab -- here on detecting error |
845 `------------------------------------*/
847 /* If not already recovering from an error, report this error. */
851 error (yylloc
, yysyntax_error_ (yystate
]dnl
852 b4_error_verbose_if([, yytoken
])[));
855 yyerror_range
[0] = yylloc
;
856 if (yyerrstatus_
== 3)
858 /* If just tried and failed to reuse lookahead token after an
859 error, discard it. */
861 if (yychar
<= yyeof_
)
863 /* Return failure if at end of input. */
864 if (yychar
== yyeof_
)
869 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
874 /* Else will try to reuse lookahead token after shifting the error
879 /*---------------------------------------------------.
880 | yyerrorlab -- error raised explicitly by YYERROR. |
881 `---------------------------------------------------*/
884 /* Pacify compilers like GCC when the user code never invokes
885 YYERROR and the label yyerrorlab therefore never appears in user
890 yyerror_range
[0] = yylocation_stack_
[yylen
- 1];
891 /* Do not reclaim the symbols of the rule which action triggered
895 yystate
= yystate_stack_
[0];
898 /*-------------------------------------------------------------.
899 | yyerrlab1 -- common code for both syntax error and YYERROR. |
900 `-------------------------------------------------------------*/
902 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
906 yyn
= yypact_
[yystate
];
907 if (yyn
!= yypact_ninf_
)
910 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
918 /* Pop the current state because it cannot handle the error token. */
919 if (yystate_stack_
.size () == 1)
922 yyerror_range
[0] = yylocation_stack_
[0];
923 yydestruct_ ("Error: popping",
925 yysemantic_stack_
[0], yylocation_stack_
[0]);
927 yystate
= yystate_stack_
[0];
931 yyerror_range
[1] = yylloc
;
932 // Using YYLLOC is tempting, but would change the location of
933 // the lookahead. YYLOC is available though.
934 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
935 yysemantic_stack_
.push (yylval
);
936 yylocation_stack_
.push (yyloc
);
938 /* Shift the error token. */
939 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
940 yysemantic_stack_
[0], yylocation_stack_
[0]);
956 if (yychar
!= yyempty_
)
957 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
959 /* Do not reclaim the symbols of the rule which action triggered
960 this YYABORT or YYACCEPT. */
962 while (yystate_stack_
.size () != 1)
964 yydestruct_ ("Cleanup: popping",
965 yystos_
[yystate_stack_
[0]],
966 yysemantic_stack_
[0],
967 yylocation_stack_
[0]);
974 // Generate an error message.
976 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
]dnl
977 b4_error_verbose_if([, int tok
])[)
982 int yyn
= yypact_
[yystate
];
983 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
985 /* Start YYX at -YYN if negative to avoid negative indexes in
987 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
989 /* Stay within bounds of both yycheck and yytname. */
990 int yychecklim
= yylast_
- yyn
+ 1;
991 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
993 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
994 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
997 // FIXME: This method of building the message is not compatible
998 // with internationalization. It should work like yacc.c does it.
999 // That is, first build a string that looks like this:
1000 // "syntax error, unexpected %s or %s or %s"
1001 // Then, invoke YY_ on this string.
1002 // Finally, use the string as a format to output
1003 // yytname_[tok], etc.
1004 // Until this gets fixed, this message appears in English only.
1005 res
= "syntax error, unexpected ";
1006 res
+= yytnamerr_ (yytname_
[tok
]);
1010 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1011 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1013 res
+= (!count
++) ? ", expecting " : " or ";
1014 res
+= yytnamerr_ (yytname_
[x
]);
1020 res
= YY_("syntax error");
1025 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1027 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1028 const ]b4_int_type_for([b4_pact
])[
1029 ]b4_parser_class_name
[::yypact_
[] =
1034 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1035 doesn't specify something else to do. Zero means the default is an
1037 const ]b4_int_type_for([b4_defact
])[
1038 ]b4_parser_class_name
[::yydefact_
[] =
1043 /* YYPGOTO[NTERM-NUM]. */
1044 const ]b4_int_type_for([b4_pgoto
])[
1045 ]b4_parser_class_name
[::yypgoto_
[] =
1050 /* YYDEFGOTO[NTERM-NUM]. */
1051 const ]b4_int_type_for([b4_defgoto
])[
1052 ]b4_parser_class_name
[::yydefgoto_
[] =
1057 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1058 positive, shift that token. If negative, reduce the rule which
1059 number is the opposite. If zero, do what YYDEFACT says. */
1060 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1061 const ]b4_int_type_for([b4_table
])[
1062 ]b4_parser_class_name
[::yytable_
[] =
1068 const ]b4_int_type_for([b4_check
])[
1069 ]b4_parser_class_name
[::yycheck_
[] =
1074 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1075 symbol of state STATE-NUM. */
1076 const ]b4_int_type_for([b4_stos
])[
1077 ]b4_parser_class_name
[::yystos_
[] =
1083 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1085 const ]b4_int_type_for([b4_toknum
])[
1086 ]b4_parser_class_name
[::yytoken_number_
[] =
1092 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1093 const ]b4_int_type_for([b4_r1
])[
1094 ]b4_parser_class_name
[::yyr1_
[] =
1099 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1100 const ]b4_int_type_for([b4_r2
])[
1101 ]b4_parser_class_name
[::yyr2_
[] =
1106 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1107 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1108 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1110 const ]b4_parser_class_name
[::yytname_
[] =
1117 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1118 const ]b4_parser_class_name
[::rhs_number_type
1119 ]b4_parser_class_name
[::yyrhs_
[] =
1124 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1126 const ]b4_int_type_for([b4_prhs
])[
1127 ]b4_parser_class_name
[::yyprhs_
[] =
1132 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1133 const ]b4_int_type_for([b4_rline
])[
1134 ]b4_parser_class_name
[::yyrline_
[] =
1139 // Print the state stack on the debug stream.
1141 ]b4_parser_class_name
[::yystack_print_ ()
1143 *yycdebug_
<< "Stack now";
1144 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1145 i
!= yystate_stack_
.end (); ++i
)
1146 *yycdebug_
<< ' ' << *i
;
1147 *yycdebug_
<< std::endl
;
1150 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1152 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1154 unsigned int yylno
= yyrline_
[yyrule
];
1155 int yynrhs
= yyr2_
[yyrule
];
1156 /* Print the symbols being reduced, and their result. */
1157 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1158 << " (line " << yylno
<< "):" << std::endl
;
1159 /* The symbols being reduced. */
1160 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1161 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1162 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1163 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1164 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1168 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1169 ]b4_parser_class_name
[::token_number_type
1170 ]b4_parser_class_name
[::yytranslate_ (int t
)
1173 const token_number_type
1178 if ((unsigned int) t
<= yyuser_token_number_max_
)
1179 return translate_table
[t
];
1181 return yyundef_token_
;
1184 const int ]b4_parser_class_name
[::yyeof_
= 0;
1185 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1186 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1187 const int ]b4_parser_class_name
[::yyempty_
= -2;
1188 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1189 const int ]b4_parser_class_name
[::yyterror_
= 1;
1190 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1191 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1193 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1194 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1196 ]b4_namespace_close
[
1200 @
output(b4_dir_prefix
[]stack
.hh@
)
1201 b4_copyright([Stack handling
for Bison parsers in C
++],
1202 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1204 #ifndef BISON_STACK_HH
1205 # define BISON_STACK_HH
1210 template <class T
, class S
= std::deque
<T
> >
1215 // Hide our reversed order.
1216 typedef typename
S::reverse_iterator iterator
;
1217 typedef typename
S::const_reverse_iterator const_iterator
;
1223 stack (unsigned int n
) : seq_ (n
)
1229 operator [] (unsigned int i
)
1236 operator [] (unsigned int i
) const
1245 seq_
.push_front (t
);
1250 pop (unsigned int n
= 1)
1257 typename
S::size_type
1260 return seq_
.size ();
1263 inline const_iterator
begin () const { return seq_
.rbegin (); }
1264 inline const_iterator
end () const { return seq_
.rend (); }
1267 /// The wrapped container.
1271 /// Present a slice of the top of a stack.
1272 template <class T
, class S
= stack
<T
> >
1277 slice (const S
& stack
,
1278 unsigned int range
) : stack_ (stack
),
1285 operator [] (unsigned int i
) const
1287 return stack_
[range_
- i
];
1293 unsigned int range_
;
1295 ]b4_namespace_close
[
1297 #endif // not BISON_STACK_HH[]dnl