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 m4_pushdef([b4_copyright_years
],
22 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
24 # How the semantic value is extracted when using variants.
26 # b4_symbol_value(VAL, [TYPE])
27 # ----------------------------
28 m4_define([b4_symbol_value
],
35 # b4_symbol_actions(FILENAME, LINENO,
36 # SYMBOL-TAG, SYMBOL-NUM,
37 # SYMBOL-ACTION, SYMBOL-TYPENAME)
38 # -------------------------------------------------
39 # Same as in C, but using references instead of pointers.
40 m4_define([b4_symbol_actions
],
41 [m4_pushdef([b4_dollar_dollar
],
42 [b4_symbol_value([yyvalue
], [$
6])])dnl
43 m4_pushdef([b4_at_dollar
], [yylocation
])dnl
45 b4_syncline([$
2], [$
1])
47 b4_syncline([@oline@
], [@ofile@
])
49 m4_popdef([b4_at_dollar
])dnl
50 m4_popdef([b4_dollar_dollar
])dnl
54 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
55 # ----------------------------------------------------------
56 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
57 m4_define([b4_symbol_action_
],
65 # b4_symbol_variant(YYTYPE, YYVAL, ACTION)
66 # ----------------------------------------
67 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
69 m4_define([b4_symbol_variant
],
70 [m4_pushdef([b4_dollar_dollar
],
74 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
78 m4_popdef([b4_dollar_dollar
])dnl
82 # _b4_char_sizeof_counter
83 # -----------------------
84 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
85 m4_define([_b4_char_sizeof_counter
],
88 # _b4_char_sizeof_dummy
89 # ---------------------
90 # At each call return a new C++ identifier.
91 m4_define([_b4_char_sizeof_dummy
],
92 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
93 dummy
[]_b4_char_sizeof_counter
])
96 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
97 # -------------------------------------------------------
98 # To be mapped on the list of type names to produce:
100 # char dummy1[sizeof(type_name_1)];
101 # char dummy2[sizeof(type_name_2)];
103 # for defined type names.
104 # $3 is doubly-quoted, do not quote it again.
105 m4_define([b4_char_sizeof
],
108 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
112 m4_define([b4_parser_class_name
],
113 [b4_percent_define_get([[parser_class_name]])])
115 # The header is mandatory.
117 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
119 # Backward compatibility.
120 m4_define([b4_location_constructors
])
121 m4_include(b4_pkgdatadir
/[location
.cc
])
123 # We do want M4 expansion after # for CPP macros.
127 [@
output(b4_spec_defines_file@
)@
128 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
129 dnl FIXME
: This is wrong
, we want computed header guards
.
131 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
133 #ifndef PARSER_HEADER_H
134 # define PARSER_HEADER_H
136 ]b4_percent_code_get([[requires]])[
146 /// A char[S] buffer to store and retrieve objects.
148 /// Sort of a variant, but does not keep track of the nature
149 /// of the stored data, since that knowledge is available
150 /// via the current state.
154 /// Instantiate a \a T in here.
155 template <typename T
>
162 /// Destroy the stored \a T.
163 template <typename T
>
167 reinterpret_cast<T
&>(buffer
).~T();
170 /// Accessor to a built \a T.
171 template <typename T
>
175 return reinterpret_cast<T
&>(buffer
);
178 /// Const accessor to a built \a T (for %printer).
179 template <typename T
>
183 return reinterpret_cast<const T
&>(buffer
);
186 /// A buffer large enough to store any of the semantic values.
192 #include "location.hh"
194 /* Enabling traces. */
196 # define YYDEBUG ]b4_debug_flag[
199 /* Enabling verbose error messages. */
200 #ifdef YYERROR_VERBOSE
201 # undef YYERROR_VERBOSE
202 # define YYERROR_VERBOSE 1
204 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
207 /* Enabling the token table. */
208 #ifndef YYTOKEN_TABLE
209 # define YYTOKEN_TABLE ]b4_token_table[
212 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
213 If N is 0, then set CURRENT to the empty location which ends
214 the previous symbol: RHS[0] (always defined). */
216 #ifndef YYLLOC_DEFAULT
217 # define YYLLOC_DEFAULT(Current, Rhs, N) \
221 (Current).begin = (Rhs)[1].begin; \
222 (Current).end = (Rhs)[N].end; \
226 (Current).begin = (Current).end = (Rhs)[0].end; \
234 class ]b4_parser_class_name
[
239 [ /// An auxiliary type to compute the largest semantic type.
241 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
244 /// Symbol semantic values.
245 typedef variant
<sizeof(union_type
)> semantic_type
;],
246 [ /// Symbol semantic values.
248 [ union semantic_type
251 [m4_if(b4_tag_seen_flag
, 0,
252 [[ typedef int semantic_type
;]],
253 [[ typedef YYSTYPE semantic_type
;]])])])[
255 typedef YYSTYPE semantic_type
;
257 /// Symbol locations.
258 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
262 ]b4_token_enums(b4_tokens
)[
265 typedef token::yytokentype token_type
;
267 /// Build a parser object.
268 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
269 virtual ~]b4_parser_class_name
[ ();
272 /// \returns 0 iff parsing succeeded.
273 virtual int parse ();
276 /// The current debugging stream.
277 std::ostream
& debug_stream () const;
278 /// Set the current debugging stream.
279 void set_debug_stream (std::ostream
&);
281 /// Type for debugging levels.
282 typedef int debug_level_type
;
283 /// The current debugging level.
284 debug_level_type
debug_level () const;
285 /// Set the current debugging level.
286 void set_debug_level (debug_level_type l
);
290 /// Report a syntax error.
291 /// \param loc where the syntax error is found.
292 /// \param msg a description of the syntax error.
293 virtual void error (const location_type
& loc
, const std::string
& msg
);
295 /// Generate an error message.
296 /// \param state the state where the error occurred.
297 /// \param tok the lookahead token.
298 virtual std::string
yysyntax_error_ (int yystate
]dnl
299 b4_error_verbose_if([, int tok
])[);
302 /// \brief Report a symbol value on the debug stream.
303 /// \param yytype The token type.
304 /// \param yyvalue Its semantic value.
305 /// \param yylocation Its location.
306 virtual void yy_symbol_value_print_ (int yytype
,
307 const semantic_type
& yyvalue
,
308 const location_type
& yylocation
);
309 /// \brief Report a symbol on the debug stream.
310 /// \param yytype The token type.
311 /// \param yyvalue Its semantic value.
312 /// \param yylocation Its location.
313 virtual void yy_symbol_print_ (int yytype
,
314 const semantic_type
& yyvalue
,
315 const location_type
& yylocation
);
320 typedef int state_type
;
321 /// State stack type.
322 typedef stack
<state_type
> state_stack_type
;
323 /// Semantic value stack type.
324 typedef stack
<semantic_type
> semantic_stack_type
;
325 /// location stack type.
326 typedef stack
<location_type
> location_stack_type
;
329 state_stack_type yystate_stack_
;
330 /// The semantic value stack.
331 semantic_stack_type yysemantic_stack_
;
332 /// The location stack.
333 location_stack_type yylocation_stack_
;
335 /// Internal symbol numbers.
336 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
338 /// For a state, the index in \a yytable_ of its portion.
339 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
340 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
342 /// For a state, default rule to reduce.
343 /// Unless\a yytable_ specifies something else to do.
344 /// Zero means the default is an error.
345 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
347 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
348 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
350 /// What to do in a state.
351 /// \a yytable_[yypact_[s]]: what to do in state \a s.
352 /// - if positive, shift that token.
353 /// - if negative, reduce the rule which number is the opposite.
354 /// - if zero, do what YYDEFACT says.
355 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
356 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
358 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
360 /// For a state, its accessing symbol.
361 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
363 /// For a rule, its LHS.
364 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
365 /// For a rule, its RHS length.
366 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
368 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
369 /// For a symbol, its name in clear.
370 static const char* const yytname_
[];
374 /// Convert the symbol name \a n to a form suitable for a diagnostic.
375 virtual std::string
yytnamerr_ (const char *n
);
379 /// A type to store symbol numbers and -1.
380 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
381 /// A `-1'-separated list of the rules' RHS.
382 static const rhs_number_type yyrhs_
[];
383 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
384 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
385 /// For each rule, its source line number.
386 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
387 /// For each scanner token number, its symbol number.
388 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
389 /// Report on the debug stream that the rule \a r is going to be reduced.
390 virtual void yy_reduce_print_ (int r
);
391 /// Print the state stack on the debug stream.
392 virtual void yystack_print_ ();
396 std::ostream
* yycdebug_
;
399 /// Convert a scanner token number \a t to a symbol number.
400 token_number_type
yytranslate_ (int t
);
402 /// \brief Reclaim the memory associated to a symbol.
403 /// \param yymsg Why this token is reclaimed.
404 /// \param yytype The symbol type.
405 /// \param yyvalue Its semantic value.
406 /// \param yylocation Its location.
407 inline void yydestruct_ (const char* yymsg
,
409 semantic_type
& yyvalue
,
410 location_type
& yylocation
);
412 /// Push a new state on the stack.
413 /// \warning the contents of \a v is stolen.
414 inline void yypush_ (state_type s
,
415 semantic_type
& v
, const location_type
& l
);
417 /// Pop \a n symbols the three stacks.
418 inline void yypop_ (unsigned int n
= 1);
421 static const int yyeof_
;
422 /* LAST_ -- Last index in TABLE_. */
423 static const int yylast_
;
424 static const int yynnts_
;
425 static const int yyempty_
;
426 static const int yyfinal_
;
427 static const int yyterror_
;
428 static const int yyerrcode_
;
429 static const int yyntokens_
;
430 static const unsigned int yyuser_token_number_max_
;
431 static const token_number_type yyundef_token_
;
432 ]b4_parse_param_vars
[
436 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
437 [b4_token_defines(b4_tokens
)
440 /* Redirection for backward compatibility. */
441 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
444 b4_percent_code_get([[provides]])[]dnl
446 [#endif /* ! defined PARSER_HEADER_H */]
448 @
output(b4_parser_file_name@
)@
449 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
450 b4_percent_code_get([[top]])[]dnl
451 m4_if(b4_prefix
, [yy
], [],
453 // Take the name prefix into account.
454 #define yylex b4_prefix[]lex])[
456 /* First part of user declarations. */
457 ]b4_user_pre_prologue
460 #include "@basename(]b4_spec_defines_file[@)"]])[
462 /* User implementation prologue. */
463 ]b4_user_post_prologue
464 b4_percent_code_get
[]dnl
469 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
470 # define YY_(msgid) dgettext ("bison-runtime", msgid)
474 # define YY_(msgid) msgid
478 /* Suppress unused-variable warnings by "using" E. */
479 #define YYUSE(e) ((void) (e))
481 /* Enable debugging if requested. */
484 /* A pseudo ostream that takes yydebug_ into account. */
485 # define YYCDEBUG if (yydebug_) (*yycdebug_)
487 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
491 *yycdebug_ << Title << ' '; \
492 yy_symbol_print_ ((Type), (Value), (Location)); \
493 *yycdebug_ << std::endl; \
497 # define YY_REDUCE_PRINT(Rule) \
500 yy_reduce_print_ (Rule); \
503 # define YY_STACK_PRINT() \
511 # define YYCDEBUG if (false) std::cerr
512 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
513 # define YY_REDUCE_PRINT(Rule)
514 # define YY_STACK_PRINT()
516 #endif /* !YYDEBUG */
518 #define yyerrok (yyerrstatus_ = 0)
519 #define yyclearin (yychar = yyempty_)
521 #define YYACCEPT goto yyacceptlab
522 #define YYABORT goto yyabortlab
523 #define YYERROR goto yyerrorlab
524 #define YYRECOVERING() (!!yyerrstatus_)
529 /* Return YYSTR after stripping away unnecessary quotes and
530 backslashes, so that it's suitable for yyerror. The heuristic is
531 that double-quoting is unnecessary unless the string contains an
532 apostrophe, a comma, or backslash (other than backslash-backslash).
533 YYSTR is taken from yytname. */
535 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
539 std::string yyr
= "";
540 char const *yyp
= yystr
;
547 goto do_not_strip_quotes
;
551 goto do_not_strip_quotes
;
560 do_not_strip_quotes
: ;
568 /// Build a parser object.
569 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
572 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
573 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
574 #endif]b4_parse_param_cons[
578 ]b4_parser_class_name::~b4_parser_class_name
[ ()
583 /*--------------------------------.
584 | Print this symbol on YYOUTPUT. |
585 `--------------------------------*/
588 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
589 const semantic_type
& yyvalue
, const location_type
& yylocation
)
595 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
603 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
604 const semantic_type
& yyvalue
, const location_type
& yylocation
)
606 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
607 << ' ' << yytname_
[yytype
] << " ("
608 << yylocation
<< ": ";
609 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
615 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
616 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
622 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
626 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
633 ]b4_parser_class_name
[::yypush_ (state_type s
,
634 semantic_type
& v
, const location_type
& l
)
636 yystate_stack_
.push (s
);
637 yysemantic_stack_
.push (v
);
638 yylocation_stack_
.push (l
);
642 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
644 yystate_stack_
.pop (n
);
645 yysemantic_stack_
.pop (n
);
646 yylocation_stack_
.pop (n
);
651 ]b4_parser_class_name
[::debug_stream () const
657 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
663 ]b4_parser_class_name
[::debug_level_type
664 ]b4_parser_class_name
[::debug_level () const
670 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
677 ]b4_parser_class_name
[::parse ()
679 /// Lookahead and lookahead in internal form.
680 int yychar
= yyempty_
;
688 /* Error handling. */
690 int yyerrstatus_
= 0;
692 /// Semantic value of the lookahead.
693 semantic_type yylval
;
694 /// Location of the lookahead.
695 location_type yylloc
;
696 /// The locations where the error started and ended.
697 location_type yyerror_range
[2];
706 YYCDEBUG
<< "Starting parse" << std::endl
;
708 ]m4_ifdef([b4_initial_action
], [
709 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
710 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
711 /* User initialization code. */
712 b4_user_initial_action
713 m4_popdef([b4_dollar_dollar
])dnl
714 m4_popdef([b4_at_dollar
])])dnl
716 [ /* Initialize the stacks. The initial state will be pushed in
717 yynewstate, since the latter expects the semantical and the
718 location values to have been already stored, initialize these
719 stacks with a primary value. */
720 yystate_stack_
= state_stack_type (0);
721 yysemantic_stack_
= semantic_stack_type (0);
722 yylocation_stack_
= location_stack_type (0);
723 yypush_ (yystate
, yylval
, yylloc
);
725 // A new state was pushed on the stack.
726 // Invariant: yystate == yystack_[0].state, i.e.,
727 // yystate was just pushed onto the state stack.
729 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
732 if (yystate
== yyfinal_
)
740 /* Try to take a decision without lookahead. */
741 yyn
= yypact_
[yystate
];
742 if (yyn
== yypact_ninf_
)
745 /* Read a lookahead token. */
746 if (yychar
== yyempty_
)
748 YYCDEBUG
<< "Reading a token: ";
749 yychar
= ]b4_c_function_call([yylex
], [int],
750 [[YYSTYPE
*], [&yylval
]][]dnl
751 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
752 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
756 /* Convert token to internal form. */
757 if (yychar
<= yyeof_
)
759 yychar
= yytoken
= yyeof_
;
760 YYCDEBUG
<< "Now at end of input." << std::endl
;
764 yytoken
= yytranslate_ (yychar
);
765 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
768 /* If the proper action on seeing token YYTOKEN is to reduce or to
769 detect an error, take that action. */
771 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
774 /* Reduce or error. */
778 if (yyn
== 0 || yyn
== yytable_ninf_
)
784 /* Shift the lookahead token. */
785 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylval
, yylloc
);
787 /* Discard the token being shifted. */
790 /* Count tokens shifted since error; after three, turn off error
796 yypush_ (yystate
, yylval
, yylloc
);
799 /*-----------------------------------------------------------.
800 | yydefault -- do the default action for the current state. |
801 `-----------------------------------------------------------*/
803 yyn
= yydefact_
[yystate
];
808 /*-----------------------------.
809 | yyreduce -- Do a reduction. |
810 `-----------------------------*/
812 yylen
= yyr2_
[yyn
];]b4_variant_if([
813 /* Variants are always initialized to an empty instance of the
814 correct type. The default $$=$1 rule is NOT applied when using
816 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
817 /* If YYLEN is nonzero, implement the default value of the action:
818 `$$ = $1'. Otherwise, use the top of the stack.
820 Otherwise, the following line sets YYVAL to garbage.
821 This behavior is undocumented and Bison
822 users should not rely upon it. */
824 yyval
= yysemantic_stack_@
{yylen
- 1@
};
826 yyval
= yysemantic_stack_@
{0@
};])[
829 slice
<location_type
, location_stack_type
> slice (yylocation_stack_
, yylen
);
830 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
832 YY_REDUCE_PRINT (yyn
);
839 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], yyval
, yyloc
);
845 /* Shift the result of the reduction. */
847 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystate_stack_
[0];
848 if (0 <= yystate
&& yystate
<= yylast_
849 && yycheck_
[yystate
] == yystate_stack_
[0])
850 yystate
= yytable_
[yystate
];
852 yystate
= yydefgoto_
[yyn
- yyntokens_
];
853 yypush_ (yystate
, yyval
, yyloc
);
856 /*------------------------------------.
857 | yyerrlab -- here on detecting error |
858 `------------------------------------*/
860 /* If not already recovering from an error, report this error. */
864 error (yylloc
, yysyntax_error_ (yystate
]dnl
865 b4_error_verbose_if([, yytoken
])[));
868 yyerror_range
[0] = yylloc
;
869 if (yyerrstatus_
== 3)
871 /* If just tried and failed to reuse lookahead token after an
872 error, discard it. */
874 if (yychar
<= yyeof_
)
876 /* Return failure if at end of input. */
877 if (yychar
== yyeof_
)
882 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
887 /* Else will try to reuse lookahead token after shifting the error
892 /*---------------------------------------------------.
893 | yyerrorlab -- error raised explicitly by YYERROR. |
894 `---------------------------------------------------*/
897 /* Pacify compilers like GCC when the user code never invokes
898 YYERROR and the label yyerrorlab therefore never appears in user
903 yyerror_range
[0] = yylocation_stack_
[yylen
- 1];
904 /* Do not reclaim the symbols of the rule which action triggered
908 yystate
= yystate_stack_
[0];
911 /*-------------------------------------------------------------.
912 | yyerrlab1 -- common code for both syntax error and YYERROR. |
913 `-------------------------------------------------------------*/
915 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
919 yyn
= yypact_
[yystate
];
920 if (yyn
!= yypact_ninf_
)
923 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
931 /* Pop the current state because it cannot handle the error token. */
932 if (yystate_stack_
.size () == 1)
935 yyerror_range
[0] = yylocation_stack_
[0];
936 yydestruct_ ("Error: popping",
938 yysemantic_stack_
[0], yylocation_stack_
[0]);
940 yystate
= yystate_stack_
[0];
944 yyerror_range
[1] = yylloc
;
945 // Using YYLLOC is tempting, but would change the location of
946 // the lookahead. YYLOC is available though.
947 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
949 /* Shift the error token. */
950 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
951 yysemantic_stack_
[0], yylocation_stack_
[0]);
954 yypush_ (yystate
, yylval
, yyloc
);
968 if (yychar
!= yyempty_
)
969 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
971 /* Do not reclaim the symbols of the rule which action triggered
972 this YYABORT or YYACCEPT. */
974 while (yystate_stack_
.size () != 1)
976 yydestruct_ ("Cleanup: popping",
977 yystos_
[yystate_stack_
[0]],
978 yysemantic_stack_
[0],
979 yylocation_stack_
[0]);
986 // Generate an error message.
988 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
]dnl
989 b4_error_verbose_if([, int tok
])[)
994 int yyn
= yypact_
[yystate
];
995 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
997 /* Start YYX at -YYN if negative to avoid negative indexes in
999 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1001 /* Stay within bounds of both yycheck and yytname. */
1002 int yychecklim
= yylast_
- yyn
+ 1;
1003 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1005 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1006 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1009 // FIXME: This method of building the message is not compatible
1010 // with internationalization. It should work like yacc.c does it.
1011 // That is, first build a string that looks like this:
1012 // "syntax error, unexpected %s or %s or %s"
1013 // Then, invoke YY_ on this string.
1014 // Finally, use the string as a format to output
1015 // yytname_[tok], etc.
1016 // Until this gets fixed, this message appears in English only.
1017 res
= "syntax error, unexpected ";
1018 res
+= yytnamerr_ (yytname_
[tok
]);
1022 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1023 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1025 res
+= (!count
++) ? ", expecting " : " or ";
1026 res
+= yytnamerr_ (yytname_
[x
]);
1032 res
= YY_("syntax error");
1037 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1039 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1040 const ]b4_int_type_for([b4_pact
])[
1041 ]b4_parser_class_name
[::yypact_
[] =
1046 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1047 doesn't specify something else to do. Zero means the default is an
1049 const ]b4_int_type_for([b4_defact
])[
1050 ]b4_parser_class_name
[::yydefact_
[] =
1055 /* YYPGOTO[NTERM-NUM]. */
1056 const ]b4_int_type_for([b4_pgoto
])[
1057 ]b4_parser_class_name
[::yypgoto_
[] =
1062 /* YYDEFGOTO[NTERM-NUM]. */
1063 const ]b4_int_type_for([b4_defgoto
])[
1064 ]b4_parser_class_name
[::yydefgoto_
[] =
1069 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1070 positive, shift that token. If negative, reduce the rule which
1071 number is the opposite. If zero, do what YYDEFACT says. */
1072 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1073 const ]b4_int_type_for([b4_table
])[
1074 ]b4_parser_class_name
[::yytable_
[] =
1080 const ]b4_int_type_for([b4_check
])[
1081 ]b4_parser_class_name
[::yycheck_
[] =
1086 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1087 symbol of state STATE-NUM. */
1088 const ]b4_int_type_for([b4_stos
])[
1089 ]b4_parser_class_name
[::yystos_
[] =
1095 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1097 const ]b4_int_type_for([b4_toknum
])[
1098 ]b4_parser_class_name
[::yytoken_number_
[] =
1104 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1105 const ]b4_int_type_for([b4_r1
])[
1106 ]b4_parser_class_name
[::yyr1_
[] =
1111 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1112 const ]b4_int_type_for([b4_r2
])[
1113 ]b4_parser_class_name
[::yyr2_
[] =
1118 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1119 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1120 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1122 const ]b4_parser_class_name
[::yytname_
[] =
1129 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1130 const ]b4_parser_class_name
[::rhs_number_type
1131 ]b4_parser_class_name
[::yyrhs_
[] =
1136 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1138 const ]b4_int_type_for([b4_prhs
])[
1139 ]b4_parser_class_name
[::yyprhs_
[] =
1144 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1145 const ]b4_int_type_for([b4_rline
])[
1146 ]b4_parser_class_name
[::yyrline_
[] =
1151 // Print the state stack on the debug stream.
1153 ]b4_parser_class_name
[::yystack_print_ ()
1155 *yycdebug_
<< "Stack now";
1156 for (state_stack_type::const_iterator i
= yystate_stack_
.begin ();
1157 i
!= yystate_stack_
.end (); ++i
)
1158 *yycdebug_
<< ' ' << *i
;
1159 *yycdebug_
<< std::endl
;
1162 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1164 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1166 unsigned int yylno
= yyrline_
[yyrule
];
1167 int yynrhs
= yyr2_
[yyrule
];
1168 /* Print the symbols being reduced, and their result. */
1169 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1170 << " (line " << yylno
<< "):" << std::endl
;
1171 /* The symbols being reduced. */
1172 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1173 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1174 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1175 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1176 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1180 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1181 ]b4_parser_class_name
[::token_number_type
1182 ]b4_parser_class_name
[::yytranslate_ (int t
)
1185 const token_number_type
1190 if ((unsigned int) t
<= yyuser_token_number_max_
)
1191 return translate_table
[t
];
1193 return yyundef_token_
;
1196 const int ]b4_parser_class_name
[::yyeof_
= 0;
1197 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1198 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1199 const int ]b4_parser_class_name
[::yyempty_
= -2;
1200 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1201 const int ]b4_parser_class_name
[::yyterror_
= 1;
1202 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1203 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1205 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1206 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1208 ]b4_namespace_close
[
1212 @
output(b4_dir_prefix
[]stack
.hh@
)@
1213 b4_copyright([Stack handling
for Bison parsers in C
++])[
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
1311 m4_popdef([b4_copyright_years
])dnl