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_rhs_value(RULE-LENGTH, NUM, [TYPE])
33 # --------------------------------------
34 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
36 m4_define([b4_rhs_value
],
37 [b4_symbol_value([yystack_@
{($
1) - ($
2)@
}.value
], [$
3])])
39 # b4_rhs_location(RULE-LENGTH, NUM)
40 # ---------------------------------
41 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
43 m4_define([b4_rhs_location
],
44 [(yystack_@
{($
1) - ($
2)@
}.location
)])
47 # b4_symbol_actions(FILENAME, LINENO,
48 # SYMBOL-TAG, SYMBOL-NUM,
49 # SYMBOL-ACTION, SYMBOL-TYPENAME)
50 # -------------------------------------------------
51 # Same as in C, but using references instead of pointers.
52 m4_define([b4_symbol_actions
],
53 [m4_pushdef([b4_dollar_dollar
],
54 [b4_symbol_value([yyvalue
], [$
6])])dnl
55 m4_pushdef([b4_at_dollar
], [yylocation
])dnl
57 b4_syncline([$
2], [$
1])
59 b4_syncline([@oline@
], [@ofile@
])
61 m4_popdef([b4_at_dollar
])dnl
62 m4_popdef([b4_dollar_dollar
])dnl
66 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
67 # ----------------------------------------------------------
68 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
69 m4_define([b4_symbol_action_
],
77 # b4_symbol_variant(YYTYPE, YYVAL, ACTION)
78 # ----------------------------------------
79 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
81 m4_define([b4_symbol_variant
],
82 [m4_pushdef([b4_dollar_dollar
],
86 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
90 m4_popdef([b4_dollar_dollar
])dnl
94 # _b4_char_sizeof_counter
95 # -----------------------
96 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
97 m4_define([_b4_char_sizeof_counter
],
100 # _b4_char_sizeof_dummy
101 # ---------------------
102 # At each call return a new C++ identifier.
103 m4_define([_b4_char_sizeof_dummy
],
104 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
105 dummy
[]_b4_char_sizeof_counter
])
108 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
109 # -------------------------------------------------------
110 # To be mapped on the list of type names to produce:
112 # char dummy1[sizeof(type_name_1)];
113 # char dummy2[sizeof(type_name_2)];
115 # for defined type names.
116 # $3 is doubly-quoted, do not quote it again.
117 m4_define([b4_char_sizeof
],
120 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
124 m4_define([b4_parser_class_name
],
125 [b4_percent_define_get([[parser_class_name]])])
127 # The header is mandatory.
129 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
131 # Backward compatibility.
132 m4_define([b4_location_constructors
])
133 m4_include(b4_pkgdatadir
/[location
.cc
])
135 # We do want M4 expansion after # for CPP macros.
139 [@
output(b4_spec_defines_file@
)
140 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++],
141 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
142 dnl FIXME
: This is wrong
, we want computed header guards
.
144 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
146 #ifndef PARSER_HEADER_H
147 # define PARSER_HEADER_H
149 ]b4_percent_code_get([[requires]])[
159 /// A char[S] buffer to store and retrieve objects.
161 /// Sort of a variant, but does not keep track of the nature
162 /// of the stored data, since that knowledge is available
163 /// via the current state.
167 /// Instantiate a \a T in here.
168 template <typename T
>
175 /// Destroy the stored \a T.
176 template <typename T
>
180 reinterpret_cast<T
&>(buffer
).~T();
183 /// Accessor to a built \a T.
184 template <typename T
>
188 return reinterpret_cast<T
&>(buffer
);
191 /// Const accessor to a built \a T (for %printer).
192 template <typename T
>
196 return reinterpret_cast<const T
&>(buffer
);
199 /// A buffer large enough to store any of the semantic values.
205 #include "location.hh"
207 /* Enabling traces. */
209 # define YYDEBUG ]b4_debug_flag[
212 /* Enabling verbose error messages. */
213 #ifdef YYERROR_VERBOSE
214 # undef YYERROR_VERBOSE
215 # define YYERROR_VERBOSE 1
217 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
220 /* Enabling the token table. */
221 #ifndef YYTOKEN_TABLE
222 # define YYTOKEN_TABLE ]b4_token_table[
225 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
226 If N is 0, then set CURRENT to the empty location which ends
227 the previous symbol: RHS[0] (always defined). */
229 #ifndef YYLLOC_DEFAULT
230 # define YYLLOC_DEFAULT(Current, Rhs, N) \
234 (Current).begin = (Rhs)[1].location.begin; \
235 (Current).end = (Rhs)[N].location.end; \
239 (Current).begin = (Current).end = (Rhs)[0].location.end; \
247 class ]b4_parser_class_name
[
252 [ /// An auxiliary type to compute the largest semantic type.
254 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
257 /// Symbol semantic values.
258 typedef variant
<sizeof(union_type
)> semantic_type
;],
259 [ /// Symbol semantic values.
261 [ union semantic_type
264 [m4_if(b4_tag_seen_flag
, 0,
265 [[ typedef int semantic_type
;]],
266 [[ typedef YYSTYPE semantic_type
;]])])])[
268 typedef YYSTYPE semantic_type
;
270 /// Symbol locations.
271 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
275 ]b4_token_enums(b4_tokens
)[
278 typedef token::yytokentype token_type
;
280 /// Build a parser object.
281 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
282 virtual ~]b4_parser_class_name
[ ();
285 /// \returns 0 iff parsing succeeded.
286 virtual int parse ();
289 /// The current debugging stream.
290 std::ostream
& debug_stream () const;
291 /// Set the current debugging stream.
292 void set_debug_stream (std::ostream
&);
294 /// Type for debugging levels.
295 typedef int debug_level_type
;
296 /// The current debugging level.
297 debug_level_type
debug_level () const;
298 /// Set the current debugging level.
299 void set_debug_level (debug_level_type l
);
303 /// Report a syntax error.
304 /// \param loc where the syntax error is found.
305 /// \param msg a description of the syntax error.
306 virtual void error (const location_type
& loc
, const std::string
& msg
);
308 /// Generate an error message.
309 /// \param state the state where the error occurred.
310 /// \param tok the lookahead token.
311 virtual std::string
yysyntax_error_ (int yystate
]dnl
312 b4_error_verbose_if([, int tok
])[);
315 /// \brief Report a symbol value on the debug stream.
316 /// \param yytype The token type.
317 /// \param yyvalue Its semantic value.
318 /// \param yylocation Its location.
319 virtual void yy_symbol_value_print_ (int yytype
,
320 const semantic_type
& yyvalue
,
321 const location_type
& yylocation
);
322 /// \brief Report a symbol on the debug stream.
323 /// \param yytype The token type.
324 /// \param yyvalue Its semantic value.
325 /// \param yylocation Its location.
326 virtual void yy_symbol_print_ (int yytype
,
327 const semantic_type
& yyvalue
,
328 const location_type
& yylocation
);
332 typedef int state_type
;
334 /// Internal symbol numbers.
335 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
337 /// For a state, the index in \a yytable_ of its portion.
338 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
339 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
341 /// For a state, default rule to reduce.
342 /// Unless\a yytable_ specifies something else to do.
343 /// Zero means the default is an error.
344 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
346 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
347 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
349 /// What to do in a state.
350 /// \a yytable_[yypact_[s]]: what to do in state \a s.
351 /// - if positive, shift that token.
352 /// - if negative, reduce the rule which number is the opposite.
353 /// - if zero, do what YYDEFACT says.
354 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
355 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
357 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
359 /// For a state, its accessing symbol.
360 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
362 /// For a rule, its LHS.
363 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
364 /// For a rule, its RHS length.
365 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
367 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
368 /// For a symbol, its name in clear.
369 static const char* const yytname_
[];
373 /// Convert the symbol name \a n to a form suitable for a diagnostic.
374 virtual std::string
yytnamerr_ (const char *n
);
378 /// A type to store symbol numbers and -1.
379 typedef ]b4_int_type_for([b4_rhs
])[ rhs_number_type
;
380 /// A `-1'-separated list of the rules' RHS.
381 static const rhs_number_type yyrhs_
[];
382 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
383 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
384 /// For each rule, its source line number.
385 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
386 /// For each scanner token number, its symbol number.
387 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
388 /// Report on the debug stream that the rule \a r is going to be reduced.
389 virtual void yy_reduce_print_ (int r
);
390 /// Print the state stack on the debug stream.
391 virtual void yystack_print_ ();
395 std::ostream
* yycdebug_
;
398 /// Convert a scanner token number \a t to a symbol number.
399 token_number_type
yytranslate_ (int t
);
401 /// \brief Reclaim the memory associated to a symbol.
402 /// \param yymsg Why this token is reclaimed.
403 /// \param yytype The symbol type.
404 /// \param yyvalue Its semantic value.
405 /// \param yylocation Its location.
406 inline void yydestruct_ (const char* yymsg
,
408 semantic_type
& yyvalue
,
409 location_type
& yylocation
);
411 /// Element of the stack: a state and its attributes.
414 /// Default constructor.
418 data_type (state_type s
, const semantic_type
& v
, const location_type
& l
);
423 /// The semantic value.
427 location_type location
;
431 typedef stack
<data_type
> stack_type
;
436 /// Push a new state on the stack.
437 /// \warning the contents of \a v is stolen.
438 inline void yypush_ (state_type s
,
439 semantic_type
& v
, const location_type
& l
);
441 /// Pop \a n symbols the three stacks.
442 inline void yypop_ (unsigned int n
= 1);
445 static const int yyeof_
;
446 /* LAST_ -- Last index in TABLE_. */
447 static const int yylast_
;
448 static const int yynnts_
;
449 static const int yyempty_
;
450 static const int yyfinal_
;
451 static const int yyterror_
;
452 static const int yyerrcode_
;
453 static const int yyntokens_
;
454 static const unsigned int yyuser_token_number_max_
;
455 static const token_number_type yyundef_token_
;
456 ]b4_parse_param_vars
[
460 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
461 [b4_token_defines(b4_tokens
)
464 /* Redirection for backward compatibility. */
465 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
468 b4_percent_code_get([[provides]])[]dnl
470 [#endif /* ! defined PARSER_HEADER_H */]
472 @
output(b4_parser_file_name@
)
473 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++],
474 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
475 b4_percent_code_get([[top]])[]dnl
476 m4_if(b4_prefix
, [yy
], [],
478 // Take the name prefix into account.
479 #define yylex b4_prefix[]lex])[
481 /* First part of user declarations. */
482 ]b4_user_pre_prologue
485 #include "@basename(]b4_spec_defines_file[@)"]])[
487 /* User implementation prologue. */
488 ]b4_user_post_prologue
489 b4_percent_code_get
[]dnl
494 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
495 # define YY_(msgid) dgettext ("bison-runtime", msgid)
499 # define YY_(msgid) msgid
503 /* Suppress unused-variable warnings by "using" E. */
504 #define YYUSE(e) ((void) (e))
506 /* Enable debugging if requested. */
509 /* A pseudo ostream that takes yydebug_ into account. */
510 # define YYCDEBUG if (yydebug_) (*yycdebug_)
512 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
516 *yycdebug_ << Title << ' '; \
517 yy_symbol_print_ ((Type), (Value), (Location)); \
518 *yycdebug_ << std::endl; \
522 # define YY_REDUCE_PRINT(Rule) \
525 yy_reduce_print_ (Rule); \
528 # define YY_STACK_PRINT() \
536 # define YYCDEBUG if (false) std::cerr
537 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
538 # define YY_REDUCE_PRINT(Rule)
539 # define YY_STACK_PRINT()
541 #endif /* !YYDEBUG */
543 #define yyerrok (yyerrstatus_ = 0)
544 #define yyclearin (yychar = yyempty_)
546 #define YYACCEPT goto yyacceptlab
547 #define YYABORT goto yyabortlab
548 #define YYERROR goto yyerrorlab
549 #define YYRECOVERING() (!!yyerrstatus_)
554 /* Return YYSTR after stripping away unnecessary quotes and
555 backslashes, so that it's suitable for yyerror. The heuristic is
556 that double-quoting is unnecessary unless the string contains an
557 apostrophe, a comma, or backslash (other than backslash-backslash).
558 YYSTR is taken from yytname. */
560 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
564 std::string yyr
= "";
565 char const *yyp
= yystr
;
572 goto do_not_strip_quotes
;
576 goto do_not_strip_quotes
;
585 do_not_strip_quotes
: ;
593 /// Build a parser object.
594 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
597 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
598 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
599 #endif]b4_parse_param_cons[
603 ]b4_parser_class_name::~b4_parser_class_name
[ ()
608 /*--------------------------------.
609 | Print this symbol on YYOUTPUT. |
610 `--------------------------------*/
613 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
614 const semantic_type
& yyvalue
, const location_type
& yylocation
)
620 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
628 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
629 const semantic_type
& yyvalue
, const location_type
& yylocation
)
631 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
632 << ' ' << yytname_
[yytype
] << " ("
633 << yylocation
<< ": ";
634 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
640 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
641 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
647 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
651 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
657 ]b4_parser_class_name
[::data_type::data_type ()
664 ]b4_parser_class_name
[::data_type::data_type (state_type s
,
665 const semantic_type
& v
, const location_type
& l
)
673 ]b4_parser_class_name
[::yypush_ (state_type s
,
674 semantic_type
& v
, const location_type
& l
)
676 yystack_
.push (data_type (s
, v
, l
));
680 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
687 ]b4_parser_class_name
[::debug_stream () const
693 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
699 ]b4_parser_class_name
[::debug_level_type
700 ]b4_parser_class_name
[::debug_level () const
706 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
713 ]b4_parser_class_name
[::parse ()
715 /// Lookahead and lookahead in internal form.
716 int yychar
= yyempty_
;
724 /* Error handling. */
726 int yyerrstatus_
= 0;
728 /// Semantic value of the lookahead.
729 semantic_type yylval
;
730 /// Location of the lookahead.
731 location_type yylloc
;
732 /// The locations where the error started and ended.
733 data_type yyerror_range
[2];
742 YYCDEBUG
<< "Starting parse" << std::endl
;
744 ]m4_ifdef([b4_initial_action
], [
745 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
746 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
747 /* User initialization code. */
748 b4_user_initial_action
749 m4_popdef([b4_dollar_dollar
])dnl
750 m4_popdef([b4_at_dollar
])])dnl
752 [ /* Initialize the stack. The initial state will be set in
753 yynewstate, since the latter expects the semantical and the
754 location values to have been already stored, initialize these
755 stacks with a primary value. */
756 yystack_
= stack_type (0);
757 yypush_ (yystate
, yylval
, yylloc
);
759 // A new state was pushed on the stack.
760 // Invariant: yystate == yystack_[0].state, i.e.,
761 // yystate was just pushed onto the state stack.
763 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
766 if (yystate
== yyfinal_
)
774 /* Try to take a decision without lookahead. */
775 yyn
= yypact_
[yystate
];
776 if (yyn
== yypact_ninf_
)
779 /* Read a lookahead token. */
780 if (yychar
== yyempty_
)
782 YYCDEBUG
<< "Reading a token: ";
783 yychar
= ]b4_c_function_call([yylex
], [int],
784 [[YYSTYPE
*], [&yylval
]][]dnl
785 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
786 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
790 /* Convert token to internal form. */
791 if (yychar
<= yyeof_
)
793 yychar
= yytoken
= yyeof_
;
794 YYCDEBUG
<< "Now at end of input." << std::endl
;
798 yytoken
= yytranslate_ (yychar
);
799 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
802 /* If the proper action on seeing token YYTOKEN is to reduce or to
803 detect an error, take that action. */
805 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
808 /* Reduce or error. */
812 if (yyn
== 0 || yyn
== yytable_ninf_
)
818 /* Shift the lookahead token. */
819 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylval
, yylloc
);
821 /* Discard the token being shifted. */
824 /* Count tokens shifted since error; after three, turn off error
830 yypush_ (yystate
, yylval
, yylloc
);
833 /*-----------------------------------------------------------.
834 | yydefault -- do the default action for the current state. |
835 `-----------------------------------------------------------*/
837 yyn
= yydefact_
[yystate
];
842 /*-----------------------------.
843 | yyreduce -- Do a reduction. |
844 `-----------------------------*/
846 yylen
= yyr2_
[yyn
];]b4_variant_if([
847 /* Variants are always initialized to an empty instance of the
848 correct type. The default $$=$1 rule is NOT applied when using
850 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
851 /* If YYLEN is nonzero, implement the default value of the action:
852 `$$ = $1'. Otherwise, use the top of the stack.
854 Otherwise, the following line sets YYVAL to garbage.
855 This behavior is undocumented and Bison
856 users should not rely upon it. */
858 yyval
= yystack_@
{yylen
- 1@
}.value
;
860 yyval
= yystack_@
{0@
}.value
;])[
863 slice
<data_type
, stack_type
> slice (yystack_
, yylen
);
864 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
866 YY_REDUCE_PRINT (yyn
);
873 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], yyval
, yyloc
);
879 /* Shift the result of the reduction. */
881 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[0].state
;
882 if (0 <= yystate
&& yystate
<= yylast_
883 && yycheck_
[yystate
] == yystack_
[0].state
)
884 yystate
= yytable_
[yystate
];
886 yystate
= yydefgoto_
[yyn
- yyntokens_
];
887 yypush_ (yystate
, yyval
, yyloc
);
890 /*------------------------------------.
891 | yyerrlab -- here on detecting error |
892 `------------------------------------*/
894 /* If not already recovering from an error, report this error. */
898 error (yylloc
, yysyntax_error_ (yystate
]dnl
899 b4_error_verbose_if([, yytoken
])[));
902 yyerror_range
[0].location
= yylloc
;
903 if (yyerrstatus_
== 3)
905 /* If just tried and failed to reuse lookahead token after an
906 error, discard it. */
908 if (yychar
<= yyeof_
)
910 /* Return failure if at end of input. */
911 if (yychar
== yyeof_
)
916 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
921 /* Else will try to reuse lookahead token after shifting the error
926 /*---------------------------------------------------.
927 | yyerrorlab -- error raised explicitly by YYERROR. |
928 `---------------------------------------------------*/
931 /* Pacify compilers like GCC when the user code never invokes
932 YYERROR and the label yyerrorlab therefore never appears in user
937 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
938 /* Do not reclaim the symbols of the rule which action triggered
942 yystate
= yystack_
[0].state
;
945 /*-------------------------------------------------------------.
946 | yyerrlab1 -- common code for both syntax error and YYERROR. |
947 `-------------------------------------------------------------*/
949 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
953 yyn
= yypact_
[yystate
];
954 if (yyn
!= yypact_ninf_
)
957 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
965 // Pop the current state because it cannot handle the error token.
966 if (yystack_
.size () == 1)
969 yyerror_range
[0].location
= yystack_
[0].location
;
970 yydestruct_ ("Error: popping",
972 yystack_
[0].value
, yystack_
[0].location
);
974 yystate
= yystack_
[0].state
;
978 yyerror_range
[1].location
= yylloc
;
979 // Using YYLLOC is tempting, but would change the location of
980 // the lookahead. YYLOC is available though.
981 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
983 /* Shift the error token. */
984 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
985 yystack_
[0].value
, yystack_
[0].location
);
988 yypush_ (yystate
, yylval
, yyloc
);
1002 if (yychar
!= yyempty_
)
1003 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
1005 /* Do not reclaim the symbols of the rule which action triggered
1006 this YYABORT or YYACCEPT. */
1008 while (yystack_
.size () != 1)
1010 yydestruct_ ("Cleanup: popping",
1011 yystos_
[yystack_
[0].state
],
1012 yystack_
[0].value
, yystack_
[0].location
);
1019 // Generate an error message.
1021 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
]dnl
1022 b4_error_verbose_if([, int tok
])[)
1027 int yyn
= yypact_
[yystate
];
1028 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1030 /* Start YYX at -YYN if negative to avoid negative indexes in
1032 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1034 /* Stay within bounds of both yycheck and yytname. */
1035 int yychecklim
= yylast_
- yyn
+ 1;
1036 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1038 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1039 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1042 // FIXME: This method of building the message is not compatible
1043 // with internationalization. It should work like yacc.c does it.
1044 // That is, first build a string that looks like this:
1045 // "syntax error, unexpected %s or %s or %s"
1046 // Then, invoke YY_ on this string.
1047 // Finally, use the string as a format to output
1048 // yytname_[tok], etc.
1049 // Until this gets fixed, this message appears in English only.
1050 res
= "syntax error, unexpected ";
1051 res
+= yytnamerr_ (yytname_
[tok
]);
1055 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1056 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1058 res
+= (!count
++) ? ", expecting " : " or ";
1059 res
+= yytnamerr_ (yytname_
[x
]);
1065 res
= YY_("syntax error");
1070 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1072 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1073 const ]b4_int_type_for([b4_pact
])[
1074 ]b4_parser_class_name
[::yypact_
[] =
1079 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1080 doesn't specify something else to do. Zero means the default is an
1082 const ]b4_int_type_for([b4_defact
])[
1083 ]b4_parser_class_name
[::yydefact_
[] =
1088 /* YYPGOTO[NTERM-NUM]. */
1089 const ]b4_int_type_for([b4_pgoto
])[
1090 ]b4_parser_class_name
[::yypgoto_
[] =
1095 /* YYDEFGOTO[NTERM-NUM]. */
1096 const ]b4_int_type_for([b4_defgoto
])[
1097 ]b4_parser_class_name
[::yydefgoto_
[] =
1102 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1103 positive, shift that token. If negative, reduce the rule which
1104 number is the opposite. If zero, do what YYDEFACT says. */
1105 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1106 const ]b4_int_type_for([b4_table
])[
1107 ]b4_parser_class_name
[::yytable_
[] =
1113 const ]b4_int_type_for([b4_check
])[
1114 ]b4_parser_class_name
[::yycheck_
[] =
1119 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1120 symbol of state STATE-NUM. */
1121 const ]b4_int_type_for([b4_stos
])[
1122 ]b4_parser_class_name
[::yystos_
[] =
1128 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1130 const ]b4_int_type_for([b4_toknum
])[
1131 ]b4_parser_class_name
[::yytoken_number_
[] =
1137 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1138 const ]b4_int_type_for([b4_r1
])[
1139 ]b4_parser_class_name
[::yyr1_
[] =
1144 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1145 const ]b4_int_type_for([b4_r2
])[
1146 ]b4_parser_class_name
[::yyr2_
[] =
1151 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1152 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1153 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1155 const ]b4_parser_class_name
[::yytname_
[] =
1162 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1163 const ]b4_parser_class_name
[::rhs_number_type
1164 ]b4_parser_class_name
[::yyrhs_
[] =
1169 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1171 const ]b4_int_type_for([b4_prhs
])[
1172 ]b4_parser_class_name
[::yyprhs_
[] =
1177 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1178 const ]b4_int_type_for([b4_rline
])[
1179 ]b4_parser_class_name
[::yyrline_
[] =
1184 // Print the state stack on the debug stream.
1186 ]b4_parser_class_name
[::yystack_print_ ()
1188 *yycdebug_
<< "Stack now";
1189 for (stack_type::const_iterator
1190 i
= yystack_
.begin (),
1191 i_end
= yystack_
.end ();
1193 *yycdebug_
<< ' ' << i
->state
;
1194 *yycdebug_
<< std::endl
;
1197 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1199 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1201 unsigned int yylno
= yyrline_
[yyrule
];
1202 int yynrhs
= yyr2_
[yyrule
];
1203 /* Print the symbols being reduced, and their result. */
1204 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1205 << " (line " << yylno
<< "):" << std::endl
;
1206 /* The symbols being reduced. */
1207 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1208 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1209 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1210 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1211 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1215 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1216 ]b4_parser_class_name
[::token_number_type
1217 ]b4_parser_class_name
[::yytranslate_ (int t
)
1220 const token_number_type
1225 if ((unsigned int) t
<= yyuser_token_number_max_
)
1226 return translate_table
[t
];
1228 return yyundef_token_
;
1231 const int ]b4_parser_class_name
[::yyeof_
= 0;
1232 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1233 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1234 const int ]b4_parser_class_name
[::yyempty_
= -2;
1235 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1236 const int ]b4_parser_class_name
[::yyterror_
= 1;
1237 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1238 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1240 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1241 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1243 ]b4_namespace_close
[
1247 @
output(b4_dir_prefix
[]stack
.hh@
)
1248 b4_copyright([Stack handling
for Bison parsers in C
++],
1249 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1251 #ifndef BISON_STACK_HH
1252 # define BISON_STACK_HH
1257 template <class T
, class S
= std::deque
<T
> >
1262 // Hide our reversed order.
1263 typedef typename
S::reverse_iterator iterator
;
1264 typedef typename
S::const_reverse_iterator const_iterator
;
1270 stack (unsigned int n
) : seq_ (n
)
1276 operator [] (unsigned int i
)
1283 operator [] (unsigned int i
) const
1292 seq_
.push_front (t
);
1297 pop (unsigned int n
= 1)
1304 typename
S::size_type
1307 return seq_
.size ();
1310 inline const_iterator
begin () const { return seq_
.rbegin (); }
1311 inline const_iterator
end () const { return seq_
.rend (); }
1314 /// The wrapped container.
1318 /// Present a slice of the top of a stack.
1319 template <class T
, class S
= stack
<T
> >
1324 slice (const S
& stack
,
1325 unsigned int range
) : stack_ (stack
),
1332 operator [] (unsigned int i
) const
1334 return stack_
[range_
- i
];
1340 unsigned int range_
;
1342 ]b4_namespace_close
[
1344 #endif // not BISON_STACK_HH[]dnl