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 # b4_table_define(TABLE-NAME, CONTENT)
22 # ------------------------------------
23 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
24 m4_define([b4_table_define
],
25 [const b4_int_type_for([$
2])
26 b4_parser_class_name::yy$
1_
[[]] =
32 # How the semantic value is extracted when using variants.
34 # b4_symbol_value(VAL, [TYPE])
35 # ----------------------------
36 m4_define([b4_symbol_value
],
43 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
44 # --------------------------------------
45 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
47 m4_define([b4_rhs_value
],
48 [b4_symbol_value([yystack_@
{($
1) - ($
2)@
}.value
], [$
3])])
50 # b4_rhs_location(RULE-LENGTH, NUM)
51 # ---------------------------------
52 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
54 m4_define([b4_rhs_location
],
55 [(yystack_@
{($
1) - ($
2)@
}.location
)])
58 # b4_symbol_actions(FILENAME, LINENO,
59 # SYMBOL-TAG, SYMBOL-NUM,
60 # SYMBOL-ACTION, SYMBOL-TYPENAME)
61 # -------------------------------------------------
62 # Same as in C, but using references instead of pointers.
63 m4_define([b4_symbol_actions
],
64 [m4_pushdef([b4_dollar_dollar
],
65 [b4_symbol_value([yyvalue
], [$
6])])dnl
66 m4_pushdef([b4_at_dollar
], [yylocation
])dnl
68 b4_syncline([$
2], [$
1])
70 b4_syncline([@oline@
], [@ofile@
])
72 m4_popdef([b4_at_dollar
])dnl
73 m4_popdef([b4_dollar_dollar
])dnl
77 # b4_symbol_action_(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
78 # ----------------------------------------------------------
79 # Invoke b4_dollar_dollar(SYMBOL_TYPENAME) for each symbol.
80 m4_define([b4_symbol_action_
],
88 # b4_symbol_variant(YYTYPE, YYVAL, ACTION)
89 # ----------------------------------------
90 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
92 m4_define([b4_symbol_variant
],
93 [m4_pushdef([b4_dollar_dollar
],
97 m4_map([b4_symbol_action_
], m4_defn([b4_type_names
]))
101 m4_popdef([b4_dollar_dollar
])dnl
105 # _b4_char_sizeof_counter
106 # -----------------------
107 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
108 m4_define([_b4_char_sizeof_counter
],
111 # _b4_char_sizeof_dummy
112 # ---------------------
113 # At each call return a new C++ identifier.
114 m4_define([_b4_char_sizeof_dummy
],
115 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
116 dummy
[]_b4_char_sizeof_counter
])
119 # b4_char_sizeof(SYMBOL-TAG, SYMBOL-NUM, SYMBOL-TYPENAME)
120 # -------------------------------------------------------
121 # To be mapped on the list of type names to produce:
123 # char dummy1[sizeof(type_name_1)];
124 # char dummy2[sizeof(type_name_2)];
126 # for defined type names.
127 # $3 is doubly-quoted, do not quote it again.
128 m4_define([b4_char_sizeof
],
131 char _b4_char_sizeof_dummy@
{sizeof($
3)@
}; // $1])dnl
135 m4_define([b4_parser_class_name
],
136 [b4_percent_define_get([[parser_class_name]])])
138 # The header is mandatory.
140 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
142 # Backward compatibility.
143 m4_define([b4_location_constructors
])
144 m4_include(b4_pkgdatadir
/[location
.cc
])
146 # We do want M4 expansion after # for CPP macros.
150 [@
output(b4_spec_defines_file@
)@
151 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++],
152 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
153 dnl FIXME
: This is wrong
, we want computed header guards
.
155 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
157 #ifndef PARSER_HEADER_H
158 # define PARSER_HEADER_H
160 ]b4_percent_code_get([[requires]])[
171 /// A char[S] buffer to store and retrieve objects.
173 /// Sort of a variant, but does not keep track of the nature
174 /// of the stored data, since that knowledge is available
175 /// via the current state.
179 /// Instantiate a \a T in here.
180 template <typename T
>
184 return *new (buffer
) T
;
187 /// Destroy the stored \a T.
188 template <typename T
>
192 reinterpret_cast<T
&>(buffer
).~T();
195 /// Accessor to a built \a T.
196 template <typename T
>
200 return reinterpret_cast<T
&>(buffer
);
203 /// Const accessor to a built \a T (for %printer).
204 template <typename T
>
208 return reinterpret_cast<const T
&>(buffer
);
211 /// A buffer large enough to store any of the semantic values.
217 #include "location.hh"
219 /* Enabling traces. */
221 # define YYDEBUG ]b4_debug_flag[
224 /* Enabling verbose error messages. */
225 #ifdef YYERROR_VERBOSE
226 # undef YYERROR_VERBOSE
227 # define YYERROR_VERBOSE 1
229 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
232 /* Enabling the token table. */
233 #ifndef YYTOKEN_TABLE
234 # define YYTOKEN_TABLE ]b4_token_table[
237 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
238 If N is 0, then set CURRENT to the empty location which ends
239 the previous symbol: RHS[0] (always defined). */
241 #ifndef YYLLOC_DEFAULT
242 # define YYLLOC_DEFAULT(Current, Rhs, N) \
246 (Current).begin = (Rhs)[1].location.begin; \
247 (Current).end = (Rhs)[N].location.end; \
251 (Current).begin = (Current).end = (Rhs)[0].location.end; \
259 class ]b4_parser_class_name
[
264 [ /// An auxiliary type to compute the largest semantic type.
266 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[
269 /// Symbol semantic values.
270 typedef variant
<sizeof(union_type
)> semantic_type
;],
271 [ /// Symbol semantic values.
273 [ union semantic_type
276 [m4_if(b4_tag_seen_flag
, 0,
277 [[ typedef int semantic_type
;]],
278 [[ typedef YYSTYPE semantic_type
;]])])])[
280 typedef YYSTYPE semantic_type
;
282 /// Symbol locations.
283 typedef ]b4_percent_define_get([[location_type]])[ location_type
;
287 ]b4_token_enums(b4_tokens
)[
290 typedef token::yytokentype token_type
;
292 /// Build a parser object.
293 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
294 virtual ~]b4_parser_class_name
[ ();
297 /// \returns 0 iff parsing succeeded.
298 virtual int parse ();
301 /// The current debugging stream.
302 std::ostream
& debug_stream () const;
303 /// Set the current debugging stream.
304 void set_debug_stream (std::ostream
&);
306 /// Type for debugging levels.
307 typedef int debug_level_type
;
308 /// The current debugging level.
309 debug_level_type
debug_level () const;
310 /// Set the current debugging level.
311 void set_debug_level (debug_level_type l
);
315 /// Report a syntax error.
316 /// \param loc where the syntax error is found.
317 /// \param msg a description of the syntax error.
318 virtual void error (const location_type
& loc
, const std::string
& msg
);
320 /// Generate an error message.
321 /// \param state the state where the error occurred.
322 /// \param tok the lookahead token.
323 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
326 /// \brief Report a symbol value on the debug stream.
327 /// \param yytype The token type.
328 /// \param yyvalue Its semantic value.
329 /// \param yylocation Its location.
330 virtual void yy_symbol_value_print_ (int yytype
,
331 const semantic_type
& yyvalue
,
332 const location_type
& yylocation
);
333 /// \brief Report a symbol on the debug stream.
334 /// \param yytype The token type.
335 /// \param yyvalue Its semantic value.
336 /// \param yylocation Its location.
337 virtual void yy_symbol_print_ (int yytype
,
338 const semantic_type
& yyvalue
,
339 const location_type
& yylocation
);
343 typedef int state_type
;
345 /// Internal symbol numbers.
346 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
348 /// For a state, the index in \a yytable_ of its portion.
349 static const ]b4_int_type_for([b4_pact
])[ yypact_
[];
350 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
352 /// For a state, default rule to reduce.
353 /// Unless\a yytable_ specifies something else to do.
354 /// Zero means the default is an error.
355 static const ]b4_int_type_for([b4_defact
])[ yydefact_
[];
357 static const ]b4_int_type_for([b4_pgoto
])[ yypgoto_
[];
358 static const ]b4_int_type_for([b4_defgoto
])[ yydefgoto_
[];
360 /// What to do in a state.
361 /// \a yytable_[yypact_[s]]: what to do in state \a s.
362 /// - if positive, shift that token.
363 /// - if negative, reduce the rule which number is the opposite.
364 /// - if zero, do what YYDEFACT says.
365 static const ]b4_int_type_for([b4_table
])[ yytable_
[];
366 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
368 static const ]b4_int_type_for([b4_check
])[ yycheck_
[];
370 /// For a state, its accessing symbol.
371 static const ]b4_int_type_for([b4_stos
])[ yystos_
[];
373 /// For a rule, its LHS.
374 static const ]b4_int_type_for([b4_r1
])[ yyr1_
[];
375 /// For a rule, its RHS length.
376 static const ]b4_int_type_for([b4_r2
])[ yyr2_
[];
378 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
379 /// For a symbol, its name in clear.
380 static const char* const yytname_
[];
384 /// Convert the symbol name \a n to a form suitable for a diagnostic.
385 virtual std::string
yytnamerr_ (const char *n
);
389 /// A `-1'-separated list of the rules' RHS.
390 static const ]b4_int_type_for([b4_rhs
])[ yyrhs_
[];
391 /// For each rule, the index of the first RHS symbol in \a yyrhs_.
392 static const ]b4_int_type_for([b4_prhs
])[ yyprhs_
[];
393 /// For each rule, its source line number.
394 static const ]b4_int_type_for([b4_rline
])[ yyrline_
[];
395 /// For each scanner token number, its symbol number.
396 static const ]b4_int_type_for([b4_toknum
])[ yytoken_number_
[];
397 /// Report on the debug stream that the rule \a r is going to be reduced.
398 virtual void yy_reduce_print_ (int r
);
399 /// Print the state stack on the debug stream.
400 virtual void yystack_print_ ();
404 std::ostream
* yycdebug_
;
407 /// Convert a scanner token number \a t to a symbol number.
408 token_number_type
yytranslate_ (int t
);
410 /// \brief Reclaim the memory associated to a symbol.
411 /// \param yymsg Why this token is reclaimed.
412 /// \param yytype The symbol type.
413 /// \param yyvalue Its semantic value.
414 /// \param yylocation Its location.
415 inline void yydestruct_ (const char* yymsg
,
417 semantic_type
& yyvalue
,
418 location_type
& yylocation
);
420 /// Element of the stack: a state and its attributes.
423 /// Default constructor.
427 data_type (state_type s
, const semantic_type
& v
, const location_type
& l
);
432 /// The semantic value.
436 location_type location
;
440 typedef stack
<data_type
> stack_type
;
445 /// Push a new state on the stack.
446 /// \warning the contents of \a v is stolen.
447 inline void yypush_ (state_type s
,
448 semantic_type
& v
, const location_type
& l
);
450 /// Pop \a n symbols the three stacks.
451 inline void yypop_ (unsigned int n
= 1);
454 static const int yyeof_
;
455 /* LAST_ -- Last index in TABLE_. */
456 static const int yylast_
;
457 static const int yynnts_
;
458 static const int yyempty_
;
459 static const int yyfinal_
;
460 static const int yyterror_
;
461 static const int yyerrcode_
;
462 static const int yyntokens_
;
463 static const unsigned int yyuser_token_number_max_
;
464 static const token_number_type yyundef_token_
;
465 ]b4_parse_param_vars
[
469 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
470 [b4_token_defines(b4_tokens
)
473 /* Redirection for backward compatibility. */
474 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
477 b4_percent_code_get([[provides]])[]dnl
479 [#endif /* ! defined PARSER_HEADER_H */]
481 @
output(b4_parser_file_name@
)@
482 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++],
483 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
484 b4_percent_code_get([[top]])[]dnl
485 m4_if(b4_prefix
, [yy
], [],
487 // Take the name prefix into account.
488 #define yylex b4_prefix[]lex])[
490 /* First part of user declarations. */
491 ]b4_user_pre_prologue
494 #include "@basename(]b4_spec_defines_file[@)"]])[
496 /* User implementation prologue. */
497 ]b4_user_post_prologue
498 b4_percent_code_get
[]dnl
503 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
504 # define YY_(msgid) dgettext ("bison-runtime", msgid)
508 # define YY_(msgid) msgid
512 /* Suppress unused-variable warnings by "using" E. */
513 #define YYUSE(e) ((void) (e))
515 /* Enable debugging if requested. */
518 /* A pseudo ostream that takes yydebug_ into account. */
519 # define YYCDEBUG if (yydebug_) (*yycdebug_)
521 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
525 *yycdebug_ << Title << ' '; \
526 yy_symbol_print_ ((Type), (Value), (Location)); \
527 *yycdebug_ << std::endl; \
531 # define YY_REDUCE_PRINT(Rule) \
534 yy_reduce_print_ (Rule); \
537 # define YY_STACK_PRINT() \
545 # define YYCDEBUG if (false) std::cerr
546 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
547 # define YY_REDUCE_PRINT(Rule)
548 # define YY_STACK_PRINT()
550 #endif /* !YYDEBUG */
552 #define yyerrok (yyerrstatus_ = 0)
553 #define yyclearin (yychar = yyempty_)
555 #define YYACCEPT goto yyacceptlab
556 #define YYABORT goto yyabortlab
557 #define YYERROR goto yyerrorlab
558 #define YYRECOVERING() (!!yyerrstatus_)
563 /* Return YYSTR after stripping away unnecessary quotes and
564 backslashes, so that it's suitable for yyerror. The heuristic is
565 that double-quoting is unnecessary unless the string contains an
566 apostrophe, a comma, or backslash (other than backslash-backslash).
567 YYSTR is taken from yytname. */
569 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
573 std::string yyr
= "";
574 char const *yyp
= yystr
;
581 goto do_not_strip_quotes
;
585 goto do_not_strip_quotes
;
594 do_not_strip_quotes
: ;
602 /// Build a parser object.
603 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
606 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
607 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
608 #endif]b4_parse_param_cons[
612 ]b4_parser_class_name::~b4_parser_class_name
[ ()
617 /*--------------------------------.
618 | Print this symbol on YYOUTPUT. |
619 `--------------------------------*/
622 ]b4_parser_class_name
[::yy_symbol_value_print_ (int yytype
,
623 const semantic_type
& yyvalue
, const location_type
& yylocation
)
629 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))dnl
637 ]b4_parser_class_name
[::yy_symbol_print_ (int yytype
,
638 const semantic_type
& yyvalue
, const location_type
& yylocation
)
640 *yycdebug_
<< (yytype
< yyntokens_
? "token" : "nterm")
641 << ' ' << yytname_
[yytype
] << " ("
642 << yylocation
<< ": ";
643 yy_symbol_value_print_ (yytype
, yyvalue
, yylocation
);
649 ]b4_parser_class_name
[::yydestruct_ (const char* yymsg
,
650 int yytype
, semantic_type
& yyvalue
, location_type
& yylocation
)
656 YY_SYMBOL_PRINT (yymsg
, yytype
, yyvalue
, yylocation
);
660 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
666 ]b4_parser_class_name
[::data_type::data_type ()
673 ]b4_parser_class_name
[::data_type::data_type (state_type s
,
674 const semantic_type
& v
, const location_type
& l
)
682 ]b4_parser_class_name
[::yypush_ (state_type s
,
683 semantic_type
& v
, const location_type
& l
)
685 yystack_
.push (data_type (s
, v
, l
));
689 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
696 ]b4_parser_class_name
[::debug_stream () const
702 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
708 ]b4_parser_class_name
[::debug_level_type
709 ]b4_parser_class_name
[::debug_level () const
715 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
722 ]b4_parser_class_name
[::parse ()
724 /// Lookahead and lookahead in internal form.
725 int yychar
= yyempty_
;
733 /* Error handling. */
735 int yyerrstatus_
= 0;
737 /// Semantic value of the lookahead.
738 semantic_type yylval
;
739 /// Location of the lookahead.
740 location_type yylloc
;
741 /// The locations where the error started and ended.
742 data_type yyerror_range
[2];
751 YYCDEBUG
<< "Starting parse" << std::endl
;
753 ]m4_ifdef([b4_initial_action
], [
754 m4_pushdef([b4_at_dollar
], [yylloc
])dnl
755 m4_pushdef([b4_dollar_dollar
], [yylval
])dnl
756 /* User initialization code. */
757 b4_user_initial_action
758 m4_popdef([b4_dollar_dollar
])dnl
759 m4_popdef([b4_at_dollar
])])dnl
761 [ /* Initialize the stack. The initial state will be set in
762 yynewstate, since the latter expects the semantical and the
763 location values to have been already stored, initialize these
764 stacks with a primary value. */
765 yystack_
= stack_type (0);
766 yypush_ (yystate
, yylval
, yylloc
);
768 // A new state was pushed on the stack.
769 // Invariant: yystate == yystack_[0].state, i.e.,
770 // yystate was just pushed onto the state stack.
772 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
775 if (yystate
== yyfinal_
)
783 /* Try to take a decision without lookahead. */
784 yyn
= yypact_
[yystate
];
785 if (yyn
== yypact_ninf_
)
788 /* Read a lookahead token. */
789 if (yychar
== yyempty_
)
791 YYCDEBUG
<< "Reading a token: ";
792 yychar
= ]b4_c_function_call([yylex
], [int],
793 [[YYSTYPE
*], [&yylval
]][]dnl
794 b4_locations_if([, [[location
*], [&yylloc
]]])dnl
795 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
))[;
799 /* Convert token to internal form. */
800 if (yychar
<= yyeof_
)
802 yychar
= yytoken
= yyeof_
;
803 YYCDEBUG
<< "Now at end of input." << std::endl
;
807 yytoken
= yytranslate_ (yychar
);
808 YY_SYMBOL_PRINT ("Next token is", yytoken
, yylval
, yylloc
);
811 /* If the proper action on seeing token YYTOKEN is to reduce or to
812 detect an error, take that action. */
814 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yytoken
)
817 /* Reduce or error. */
821 if (yyn
== 0 || yyn
== yytable_ninf_
)
827 /* Shift the lookahead token. */
828 YY_SYMBOL_PRINT ("Shifting", yytoken
, yylval
, yylloc
);
830 /* Discard the token being shifted. */
833 /* Count tokens shifted since error; after three, turn off error
839 yypush_ (yystate
, yylval
, yylloc
);
842 /*-----------------------------------------------------------.
843 | yydefault -- do the default action for the current state. |
844 `-----------------------------------------------------------*/
846 yyn
= yydefact_
[yystate
];
851 /*-----------------------------.
852 | yyreduce -- Do a reduction. |
853 `-----------------------------*/
855 yylen
= yyr2_
[yyn
];]b4_variant_if([
856 /* Variants are always initialized to an empty instance of the
857 correct type. The default $$=$1 rule is NOT applied when using
859 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yyval
], [build
])[],[
860 /* If YYLEN is nonzero, implement the default value of the action:
861 `$$ = $1'. Otherwise, use the top of the stack.
863 Otherwise, the following line sets YYVAL to garbage.
864 This behavior is undocumented and Bison
865 users should not rely upon it. */
867 yyval
= yystack_@
{yylen
- 1@
}.value
;
869 yyval
= yystack_@
{0@
}.value
;])[
871 // Compute the default @@$.
873 slice
<data_type
, stack_type
> slice (yystack_
, yylen
);
874 YYLLOC_DEFAULT (yyloc
, slice
, yylen
);
877 // Perform the reduction.
878 YY_REDUCE_PRINT (yyn
);
885 YY_SYMBOL_PRINT ("-> $$ =", yyr1_
[yyn
], yyval
, yyloc
);
888 // Destroy the lhs symbols.
889 for (int i
= 0; i
< yylen
; ++i
)
891 b4_symbol_variant([[yystos_
[yystack_@
{i@
}.state
]]],
892 [[yystack_@
{i@
}.value
]],
900 /* Shift the result of the reduction. */
902 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[0].state
;
903 if (0 <= yystate
&& yystate
<= yylast_
904 && yycheck_
[yystate
] == yystack_
[0].state
)
905 yystate
= yytable_
[yystate
];
907 yystate
= yydefgoto_
[yyn
- yyntokens_
];
908 yypush_ (yystate
, yyval
, yyloc
);
911 /*------------------------------------.
912 | yyerrlab -- here on detecting error |
913 `------------------------------------*/
915 /* If not already recovering from an error, report this error. */
919 error (yylloc
, yysyntax_error_ (yystate
, yytoken
));
922 yyerror_range
[0].location
= yylloc
;
923 if (yyerrstatus_
== 3)
925 /* If just tried and failed to reuse lookahead token after an
926 error, discard it. */
928 if (yychar
<= yyeof_
)
930 /* Return failure if at end of input. */
931 if (yychar
== yyeof_
)
936 yydestruct_ ("Error: discarding", yytoken
, yylval
, yylloc
);
941 /* Else will try to reuse lookahead token after shifting the error
946 /*---------------------------------------------------.
947 | yyerrorlab -- error raised explicitly by YYERROR. |
948 `---------------------------------------------------*/
951 /* Pacify compilers like GCC when the user code never invokes
952 YYERROR and the label yyerrorlab therefore never appears in user
957 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;
958 /* Do not reclaim the symbols of the rule which action triggered
962 yystate
= yystack_
[0].state
;
965 /*-------------------------------------------------------------.
966 | yyerrlab1 -- common code for both syntax error and YYERROR. |
967 `-------------------------------------------------------------*/
969 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
973 yyn
= yypact_
[yystate
];
974 if (yyn
!= yypact_ninf_
)
977 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
985 // Pop the current state because it cannot handle the error token.
986 if (yystack_
.size () == 1)
989 yyerror_range
[0].location
= yystack_
[0].location
;
990 yydestruct_ ("Error: popping",
992 yystack_
[0].value
, yystack_
[0].location
);
994 yystate
= yystack_
[0].state
;
998 yyerror_range
[1].location
= yylloc
;
999 // Using YYLLOC is tempting, but would change the location of
1000 // the lookahead. YYLOC is available though.
1001 YYLLOC_DEFAULT (yyloc
, (yyerror_range
- 1), 2);
1003 /* Shift the error token. */
1004 YY_SYMBOL_PRINT ("Shifting", yystos_
[yyn
],
1005 yystack_
[0].value
, yystack_
[0].location
);
1008 yypush_ (yystate
, yylval
, yyloc
);
1022 if (yychar
!= yyempty_
)
1023 yydestruct_ ("Cleanup: discarding lookahead", yytoken
, yylval
, yylloc
);
1025 /* Do not reclaim the symbols of the rule which action triggered
1026 this YYABORT or YYACCEPT. */
1028 while (yystack_
.size () != 1)
1030 yydestruct_ ("Cleanup: popping",
1031 yystos_
[yystack_
[0].state
],
1032 yystack_
[0].value
, yystack_
[0].location
);
1039 // Generate an error message.
1041 ]b4_parser_class_name
[::yysyntax_error_ (int yystate
, int]dnl
1042 b4_error_verbose_if([ tok
])[)
1047 int yyn
= yypact_
[yystate
];
1048 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1050 /* Start YYX at -YYN if negative to avoid negative indexes in
1052 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1054 /* Stay within bounds of both yycheck and yytname. */
1055 int yychecklim
= yylast_
- yyn
+ 1;
1056 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1058 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1059 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1062 // FIXME: This method of building the message is not compatible
1063 // with internationalization. It should work like yacc.c does it.
1064 // That is, first build a string that looks like this:
1065 // "syntax error, unexpected %s or %s or %s"
1066 // Then, invoke YY_ on this string.
1067 // Finally, use the string as a format to output
1068 // yytname_[tok], etc.
1069 // Until this gets fixed, this message appears in English only.
1070 res
= "syntax error, unexpected ";
1071 res
+= yytnamerr_ (yytname_
[tok
]);
1075 for (int x
= yyxbegin
; x
< yyxend
; ++x
)
1076 if (yycheck_
[x
+ yyn
] == x
&& x
!= yyterror_
)
1078 res
+= (!count
++) ? ", expecting " : " or ";
1079 res
+= yytnamerr_ (yytname_
[x
]);
1085 res
= YY_("syntax error");
1090 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1092 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1093 ]b4_table_define([pact
], [b4_pact
])[;
1095 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
1096 doesn't specify something else to do. Zero means the default is an
1098 ]b4_table_define([defact
], [b4_defact
])[;
1100 /* YYPGOTO[NTERM-NUM]. */
1101 ]b4_table_define([pgoto
], [b4_pgoto
])[;
1103 /* YYDEFGOTO[NTERM-NUM]. */
1104 ]b4_table_define([defgoto
], [b4_defgoto
])[;
1106 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
1107 positive, shift that token. If negative, reduce the rule which
1108 number is the opposite. If zero, do what YYDEFACT says. */
1109 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1110 ]b4_table_define([table
], [b4_table
])[;
1113 ]b4_table_define([check
], [b4_check
])[;
1115 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
1116 symbol of state STATE-NUM. */
1117 ]b4_table_define([stos
], [b4_stos
])[;
1120 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
1122 ]b4_table_define([token_number
], [b4_toknum
])[;
1125 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1126 ]b4_table_define([r1
], [b4_r1
])[;
1128 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
1129 ]b4_table_define([r2
], [b4_r2
])[;
1131 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1132 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1133 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1135 const ]b4_parser_class_name
[::yytname_
[] =
1142 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1143 ]b4_table_define([rhs
], [b4_rhs
])[;
1145 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1147 ]b4_table_define([prhs
], [b4_prhs
])[;
1149 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1150 ]b4_table_define([rline
], [b4_rline
])[;
1152 // Print the state stack on the debug stream.
1154 ]b4_parser_class_name
[::yystack_print_ ()
1156 *yycdebug_
<< "Stack now";
1157 for (stack_type::const_iterator
1158 i
= yystack_
.begin (),
1159 i_end
= yystack_
.end ();
1161 *yycdebug_
<< ' ' << i
->state
;
1162 *yycdebug_
<< std::endl
;
1165 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1167 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1169 unsigned int yylno
= yyrline_
[yyrule
];
1170 int yynrhs
= yyr2_
[yyrule
];
1171 /* Print the symbols being reduced, and their result. */
1172 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1173 << " (line " << yylno
<< "):" << std::endl
;
1174 /* The symbols being reduced. */
1175 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1176 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1177 yyrhs_
[yyprhs_
[yyrule
] + yyi
],
1178 ]b4_rhs_value(yynrhs
, yyi
+ 1)[,
1179 ]b4_rhs_location(yynrhs
, yyi
+ 1)[);
1183 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1184 ]b4_parser_class_name
[::token_number_type
1185 ]b4_parser_class_name
[::yytranslate_ (int t
)
1188 const token_number_type
1193 if ((unsigned int) t
<= yyuser_token_number_max_
)
1194 return translate_table
[t
];
1196 return yyundef_token_
;
1199 const int ]b4_parser_class_name
[::yyeof_
= 0;
1200 const int ]b4_parser_class_name
[::yylast_
= ]b4_last
[;
1201 const int ]b4_parser_class_name
[::yynnts_
= ]b4_nterms_number
[;
1202 const int ]b4_parser_class_name
[::yyempty_
= -2;
1203 const int ]b4_parser_class_name
[::yyfinal_
= ]b4_final_state_number
[;
1204 const int ]b4_parser_class_name
[::yyterror_
= 1;
1205 const int ]b4_parser_class_name
[::yyerrcode_
= 256;
1206 const int ]b4_parser_class_name
[::yyntokens_
= ]b4_tokens_number
[;
1208 const unsigned int ]b4_parser_class_name
[::yyuser_token_number_max_
= ]b4_user_token_number_max
[;
1209 const ]b4_parser_class_name
[::token_number_type
]b4_parser_class_name
[::yyundef_token_
= ]b4_undef_token_number
[;
1211 ]b4_namespace_close
[
1215 @
output(b4_dir_prefix
[]stack
.hh@
)@
1216 b4_copyright([Stack handling
for Bison parsers in C
++],
1217 [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
1219 #ifndef BISON_STACK_HH
1220 # define BISON_STACK_HH
1225 template <class T
, class S
= std::deque
<T
> >
1230 // Hide our reversed order.
1231 typedef typename
S::reverse_iterator iterator
;
1232 typedef typename
S::const_reverse_iterator const_iterator
;
1238 stack (unsigned int n
) : seq_ (n
)
1244 operator [] (unsigned int i
)
1251 operator [] (unsigned int i
) const
1260 seq_
.push_front (t
);
1265 pop (unsigned int n
= 1)
1272 typename
S::size_type
1275 return seq_
.size ();
1278 inline const_iterator
begin () const { return seq_
.rbegin (); }
1279 inline const_iterator
end () const { return seq_
.rend (); }
1282 /// The wrapped container.
1286 /// Present a slice of the top of a stack.
1287 template <class T
, class S
= stack
<T
> >
1292 slice (const S
& stack
,
1293 unsigned int range
) : stack_ (stack
),
1300 operator [] (unsigned int i
) const
1302 return stack_
[range_
- i
];
1308 unsigned int range_
;
1310 ]b4_namespace_close
[
1312 #endif // not BISON_STACK_HH[]dnl