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
])
22 # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
23 # --------------------------------------------------------------
24 # Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
25 m4_define([b4_integral_parser_table_declare
],
26 [m4_ifval([$
3], [b4_c_comment([$
3], [ ])
28 static const b4_int_type_for([$
2]) yy$
1_
[[]];dnl
31 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
32 # ---------------------------------------------
33 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
34 m4_define([b4_integral_parser_table_define
],
35 [ const b4_int_type_for([$
2])
36 b4_parser_class_name::yy$
1_
[[]] =
43 # b4_symbol_value_template(VAL, [TYPE])
44 # -------------------------------------
45 # Same as b4_symbol_value, but used in a template method. It makes
46 # a difference when using variants.
47 m4_copy([b4_symbol_value
], [b4_symbol_value_template
])
50 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
51 # ----------------------------------------------------------------
52 m4_define([b4_lex_symbol_if
],
53 [b4_percent_define_ifdef([[lex_symbol]], [$
1], [$
2])])
56 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
57 # ------------------------------------------------
58 m4_define([b4_assert_if
],
59 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
62 # b4_lhs_value([TYPE])
63 # --------------------
64 # Expansion of $<TYPE>$.
65 m4_define([b4_lhs_value
],
66 [b4_symbol_value([yylhs
.value
], [$
1])])
72 m4_define([b4_lhs_location
],
76 # b4_rhs_data(RULE-LENGTH, NUM)
77 # -----------------------------
78 # Return the data corresponding to the symbol #NUM, where the current
79 # rule has RULE-LENGTH symbols on RHS.
80 m4_define([b4_rhs_data
],
81 [yystack_@
{b4_subtract($@
)@
}])
84 # b4_rhs_state(RULE-LENGTH, NUM)
85 # ------------------------------
86 # The state corresponding to the symbol #NUM, where the current
87 # rule has RULE-LENGTH symbols on RHS.
88 m4_define([b4_rhs_state
],
89 [b4_rhs_data([$
1], [$
2]).state
])
92 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
93 # --------------------------------------
94 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
96 m4_define([b4_rhs_value
],
97 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
100 # b4_rhs_location(RULE-LENGTH, NUM)
101 # ---------------------------------
102 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
104 m4_define([b4_rhs_location
],
105 [b4_rhs_data([$
1], [$
2]).location
])
108 # b4_symbol_action(SYMBOL-NUM, KIND)
109 # ----------------------------------
110 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
111 # Same as in C, but using references instead of pointers.
112 m4_define([b4_symbol_action
],
113 [b4_symbol_if([$
1], [has_$
2],
114 [m4_pushdef([b4_dollar_dollar
],
115 [b4_symbol_value_template([yysym
.value
],
116 b4_symbol_if([$
1], [has_type
],
117 [b4_symbol([$
1], [type
])]))])dnl
118 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
119 b4_symbol_case_([$
1])
120 b4_syncline([b4_symbol([$
1], [$
2_line
])], ["b4_symbol([$1], [$2_file])"])
121 b4_symbol([$
1], [$
2])
122 b4_syncline([@oline@
], [@ofile@
])
125 m4_popdef([b4_at_dollar
])dnl
126 m4_popdef([b4_dollar_dollar
])dnl
129 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
130 # -------------------------------------------------
131 # Declare the overloaded version of make_symbol for the (common) type of
132 # these SYMBOL-NUMBERS. Use at class-level.
133 m4_define([b4_symbol_constructor_declaration_
],
134 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
137 make_
[]b4_symbol_([$
1], [id
]) (dnl
138 b4_args(b4_symbol_if([$
1], [has_type
],
139 [const b4_symbol([$
1], [type
])& v
]),
140 b4_locations_if([const location_type
& l
])));
145 # b4_symbol_constructor_declarations
146 # ----------------------------------
147 # Declare symbol constructors for all the value types.
148 # Use at class-level.
149 m4_define([b4_symbol_constructor_declarations
],
151 // Symbol constructors declarations.
152 b4_symbol_foreach([b4_symbol_constructor_declaration_
])])])
156 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
157 # ------------------------------------------------
158 # Define symbol constructor for this SYMBOL-NUMBER.
159 m4_define([b4_symbol_constructor_definition_
],
160 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
161 [ b4_parser_class_name::symbol_type
162 b4_parser_class_name::make_
[]b4_symbol_([$
1], [id
]) (dnl
163 b4_args(b4_symbol_if([$
1], [has_type
],
164 [const b4_symbol([$
1], [type
])& v
]),
165 b4_locations_if([const location_type
& l
])))
167 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$
1], [id
]))],
168 b4_symbol_if([$
1], [has_type
], [v
]),
169 b4_locations_if([l
])));
175 # b4_symbol_constructor_definitions
176 # ----------------------------------
177 # Define the overloaded versions of make_symbol for all the value types.
178 m4_define([b4_symbol_constructor_definitions
],
179 [[ // symbol_base_type.
180 template <typename Exact
>
181 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
182 : value()]b4_locations_if([
187 template <typename Exact
>
188 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
194 template <typename Exact
>
195 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
196 [const semantic_type
& v
],
197 b4_locations_if([const location_type
& l
]))[)
198 : value(v
)]b4_locations_if([
203 template <typename Exact
>
205 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
207 return static_cast<const Exact
&>(*this);
210 template <typename Exact
>
212 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
214 return static_cast<Exact
&>(*this);
217 template <typename Exact
>
219 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
221 return self ().type_get_ ();
225 ]b4_parser_class_name
[::symbol_type::symbol_type ()
231 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
233 b4_locations_if([const location_type
& l
]))[)
234 : super_type (]b4_locations_if([l
])[)
239 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
241 [const semantic_type
& v
],
242 b4_locations_if([const location_type
& l
]))[)
243 : super_type (v
]b4_locations_if([, l
])[)
249 ]b4_parser_class_name
[::symbol_type::type_get_ () const
254 ]b4_parser_class_name
[::token_type
255 ]b4_parser_class_name
[::symbol_type::token () const
257 // YYTOKNUM[NUM] -- (External) token number corresponding to the
258 // (internal) symbol number NUM (which must be that of a token). */
260 const ]b4_int_type_for([b4_toknum
])[
265 return static_cast<token_type
> (yytoken_number_
[type
]);
270 [ // Implementation of make_symbol for each symbol type.
271 b4_symbol_foreach([b4_symbol_constructor_definition_
])])])
274 # b4_yytranslate_definition
275 # -------------------------
276 # Define yytranslate_. Sometimes we want it in the header file,
277 # sometimes the cc file suffices.
278 m4_define([b4_yytranslate_definition
],
279 [[ // Symbol number corresponding to token number t.
280 ]b4_parser_class_name
[::token_number_type
281 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
285 const token_number_type
290 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
291 const token_number_type undef_token_
= ]b4_undef_token_number
[;
293 if (static_cast<int>(t
) <= yyeof_
)
295 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
296 return translate_table
[t
];
303 m4_pushdef([b4_copyright_years
],
304 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
306 m4_define([b4_parser_class_name
],
307 [b4_percent_define_get([[parser_class_name]])])
309 # The header is mandatory.
311 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
314 [# Backward compatibility.
315 m4_define([b4_location_constructors
])
316 m4_include(b4_pkgdatadir
/[location
.cc
])])
317 m4_include(b4_pkgdatadir
/[stack
.hh
])
318 b4_variant_if([m4_include(b4_pkgdatadir
/[variant
.hh
])])
320 # We do want M4 expansion after # for CPP macros.
323 @
output(b4_spec_defines_file@
)@
324 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
325 dnl FIXME
: This is wrong
, we want computed header guards
.
327 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
329 #ifndef PARSER_HEADER_H
330 # define PARSER_HEADER_H
332 ]b4_percent_code_get([[requires]])[
334 ]b4_assert_if([#include <cassert>])[
340 ]b4_locations_if([ class position
;
342 ]b4_variant_if([b4_variant_definition
])[
345 ]b4_locations_if([#include "location.hh"])[
347 /* Enabling traces. */
349 # define YYDEBUG ]b4_debug_flag[
352 /* Enabling verbose error messages. */
353 #ifdef YYERROR_VERBOSE
354 # undef YYERROR_VERBOSE
355 # define YYERROR_VERBOSE 1
357 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
360 /* Enabling the token table. */
361 #ifndef YYTOKEN_TABLE
362 # define YYTOKEN_TABLE ]b4_token_table[
365 ]b4_locations_if([dnl
366 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
367 If N is 0, then set CURRENT to the empty location which ends
368 the previous symbol: RHS[0] (always defined). */
370 #ifndef YYLLOC_DEFAULT
371 # define YYLLOC_DEFAULT(Current, Rhs, N) \
375 (Current).begin = (Rhs)[1].location.begin; \
376 (Current).end = (Rhs)[N].location.end; \
380 (Current).begin = (Current).end = (Rhs)[0].location.end; \
388 class ]b4_parser_class_name
[
393 [ /// An auxiliary type to compute the largest semantic type.
395 {]b4_type_foreach([b4_char_sizeof
])[};
397 /// Symbol semantic values.
398 typedef variant
<sizeof(union_type
)> semantic_type
;],
399 [ /// Symbol semantic values.
401 [ union semantic_type
404 [m4_if(b4_tag_seen_flag
, 0,
405 [[ typedef int semantic_type
;]],
406 [[ typedef YYSTYPE semantic_type
;]])])])[
408 typedef YYSTYPE semantic_type
;
409 #endif]b4_locations_if([
410 /// Symbol locations.
411 typedef b4_percent_define_get([[location_type]]) location_type
;])[
415 ]b4_token_enums(b4_tokens
)[
418 typedef token::yytokentype token_type
;
420 /// Build a parser object.
421 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
422 virtual ~]b4_parser_class_name
[ ();
425 /// \returns 0 iff parsing succeeded.
426 virtual int parse ();
429 /// The current debugging stream.
430 std::ostream
& debug_stream () const;
431 /// Set the current debugging stream.
432 void set_debug_stream (std::ostream
&);
434 /// Type for debugging levels.
435 typedef int debug_level_type
;
436 /// The current debugging level.
437 debug_level_type
debug_level () const;
438 /// Set the current debugging level.
439 void set_debug_level (debug_level_type l
);
442 /// Report a syntax error.]b4_locations_if([
443 /// \param loc where the syntax error is found.])[
444 /// \param msg a description of the syntax error.
445 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
448 /// Generate an error message.
449 /// \param state the state where the error occurred.
450 /// \param tok the lookahead token.
451 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
454 typedef int state_type
;
456 /// Internal symbol numbers.
457 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
458 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
459 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
462 ]b4_parser_tables_declare
[
464 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
465 /// For a symbol, its name in clear.
466 static const char* const yytname_
[];
467 #endif]b4_error_verbose_if([
469 /// Convert the symbol name \a n to a form suitable for a diagnostic.
470 static std::string
yytnamerr_ (const char *n
);])[
473 ]b4_integral_parser_table_declare([rline
], [b4_rline
],
474 [YYRLINE
[YYN
] -- Source line where rule number YYN was defined
.])[
475 /// Report on the debug stream that the rule \a r is going to be reduced.
476 virtual void yy_reduce_print_ (int r
);
477 /// Print the state stack on the debug stream.
478 virtual void yystack_print_ ();
482 std::ostream
* yycdebug_
;
485 /// Convert a scanner token number \a t to a symbol number.
486 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
488 /// A complete symbol, with its type.
489 template <typename Exact
>
490 struct symbol_base_type
492 /// Default constructor.
493 inline symbol_base_type ();
495 /// Constructor.]b4_locations_if([
496 inline symbol_base_type (const location_type
& l
)])[;
497 inline symbol_base_type (]b4_args(
498 [const semantic_type
& v
],
499 b4_locations_if([const location_type
& l
]))[);
501 /// Return this with its exact type.
502 const Exact
& self () const;
505 /// Return the type of this symbol.
506 int type_get () const;
508 /// The semantic value.
509 semantic_type value
;]b4_locations_if([
512 location_type location
;])[
516 /// \brief Display a symbol type, value and location.
517 /// \param yyo The output stream.
518 /// \param yysym The symbol.
519 template <typename Exact
>
520 void yy_print_ (std::ostream
& yyo
,
521 const symbol_base_type
<Exact
>& yysym
) const;
524 /// \brief Reclaim the memory associated to a symbol.
525 /// \param yymsg Why this token is reclaimed.
526 /// If null, print nothing.
527 /// \param s The symbol.
528 template <typename Exact
>
529 inline void yy_destroy_ (const char* yymsg
,
530 symbol_base_type
<Exact
>& yysym
) const;
533 /// External form of a symbol: its type and attributes.
534 struct symbol_type
: symbol_base_type
<symbol_type
>
536 /// The parent class.
537 typedef symbol_base_type
<symbol_type
> super_type
;
539 /// Default constructor.
540 inline symbol_type ();
543 inline symbol_type (]b4_args([int t
],
544 [const semantic_type
& v
],
545 b4_locations_if([const location_type
& l
]))[);
547 inline symbol_type (]b4_args([int t
],
548 b4_locations_if([const location_type
& l
]))[);
553 /// Return the type corresponding to this state.
554 inline int type_get_ () const;
557 inline token_type
token () const;
560 ]b4_symbol_constructor_declarations
[
563 /// Element of the stack: a state and its attributes.
564 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
566 /// The parent class.
567 typedef symbol_base_type
<stack_symbol_type
> super_type
;
569 /// Default constructor.
570 inline stack_symbol_type ();
573 inline stack_symbol_type (]b4_args([state_type s
],
574 [const semantic_type
& v
],
575 b4_locations_if([const location_type
& l
]))[);
580 /// Return the type corresponding to this state.
581 inline int type_get_ () const;
585 typedef stack
<stack_symbol_type
> stack_type
;
590 /// Push a new state on the stack.
591 /// \param m a debug message to display
592 /// if null, no trace is output.
593 /// \param s the symbol
594 /// \warning the contents of \a s.value is stolen.
595 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
597 /// Push a new look ahead token on the state on the stack.
598 /// \param m a debug message to display
599 /// if null, no trace is output.
600 /// \param s the state
601 /// \param sym the symbol (for its value and location).
602 /// \warning the contents of \a s.value is stolen.
603 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
605 /// Pop \a n symbols the three stacks.
606 inline void yypop_ (unsigned int n
= 1);
612 yylast_
= ]b4_last
[, //< Last index in yytable_.
613 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
615 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
618 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
621 ]b4_parse_param_vars
[
624 ]b4_lex_symbol_if([b4_yytranslate_definition
])[
625 ]b4_lex_symbol_if([b4_symbol_constructor_definitions
])[
628 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
629 [b4_token_defines(b4_tokens
)
632 /* Redirection for backward compatibility. */
633 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
636 b4_percent_code_get([[provides]])[]dnl
638 [#endif /* ! defined PARSER_HEADER_H */]
639 @
output(b4_parser_file_name@
)@
640 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
641 b4_percent_code_get([[top]])[]dnl
642 m4_if(b4_prefix
, [yy
], [],
644 // Take the name prefix into account.
645 #define yylex b4_prefix[]lex])[
647 /* First part of user declarations. */
648 ]b4_user_pre_prologue
[
650 #include "@basename(]b4_spec_defines_file[@)"
652 /* User implementation prologue. */
653 ]b4_user_post_prologue
654 b4_percent_code_get
[]dnl
659 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
660 # define YY_(msgid) dgettext ("bison-runtime", msgid)
664 # define YY_(msgid) msgid
668 /* Suppress unused-variable warnings by "using" E. */
669 #define YYUSE(e) ((void) (e))
671 /* Enable debugging if requested. */
674 /* A pseudo ostream that takes yydebug_ into account. */
675 # define YYCDEBUG if (yydebug_) (*yycdebug_)
677 # define YY_SYMBOL_PRINT(Title, Symbol) \
681 *yycdebug_ << Title << ' '; \
682 yy_print_ (*yycdebug_, Symbol); \
683 *yycdebug_ << std::endl; \
687 # define YY_REDUCE_PRINT(Rule) \
690 yy_reduce_print_ (Rule); \
693 # define YY_STACK_PRINT() \
701 # define YYCDEBUG if (false) std::cerr
702 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
703 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
704 # define YY_STACK_PRINT() static_cast<void>(0)
706 #endif /* !YYDEBUG */
708 #define yyerrok (yyerrstatus_ = 0)
709 #define yyclearin (yyempty = true)
711 #define YYACCEPT goto yyacceptlab
712 #define YYABORT goto yyabortlab
713 #define YYERROR goto yyerrorlab
714 #define YYRECOVERING() (!!yyerrstatus_)
716 ]b4_namespace_open
[]b4_error_verbose_if([[
718 /* Return YYSTR after stripping away unnecessary quotes and
719 backslashes, so that it's suitable for yyerror. The heuristic is
720 that double-quoting is unnecessary unless the string contains an
721 apostrophe, a comma, or backslash (other than backslash-backslash).
722 YYSTR is taken from yytname. */
724 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
728 std::string yyr
= "";
729 char const *yyp
= yystr
;
736 goto do_not_strip_quotes
;
740 goto do_not_strip_quotes
;
749 do_not_strip_quotes
: ;
756 /// Build a parser object.
757 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
760 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
761 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
762 #endif]b4_parse_param_cons[
766 ]b4_parser_class_name::~b4_parser_class_name
[ ()
775 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions
])[
777 // stack_symbol_type.
778 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
784 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
786 [const semantic_type
& v
],
787 b4_locations_if([const location_type
& l
]))[)
788 : super_type (v
]b4_locations_if([, l
])[)
794 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
796 return yystos_
[state
];
800 template <typename Exact
>
802 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
803 symbol_base_type
<Exact
>& yysym
) const
805 int yytype
= yysym
.type_get ();
808 YY_SYMBOL_PRINT (yymsg
, yysym
);
813 ]b4_symbol_foreach([b4_symbol_destructor
])dnl
819 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
823 template <typename Exact
>
825 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
826 const symbol_base_type
<Exact
>& yysym
) const
828 int yytype
= yysym
.type_get ();
829 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
830 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
831 << yysym
.location
<< ": "])[;
834 ]b4_symbol_foreach([b4_symbol_printer
])dnl
843 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
847 YY_SYMBOL_PRINT (m
, sym
);
849 [[ yystack_
.push (stack_symbol_type (]b4_args(
852 b4_locations_if([sym
.location
]))[));
853 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
854 [build
], [sym
.value
])],
855 [[ yystack_
.push (stack_symbol_type (]b4_args(
858 b4_locations_if([sym
.location
]))[));]])[
862 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
865 YY_SYMBOL_PRINT (m
, s
);
867 [[ yystack_
.push (stack_symbol_type (]b4_args(
870 b4_locations_if([s
.location
]))[));
871 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
872 [build
], [s
.value
])],
873 [ yystack_
.push (s
);])[
877 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
884 ]b4_parser_class_name
[::debug_stream () const
890 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
896 ]b4_parser_class_name
[::debug_level_type
897 ]b4_parser_class_name
[::debug_level () const
903 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
910 ]b4_parser_class_name
[::parse ()
912 /// Whether yyla contains a lookahead.
920 /* Error handling. */
922 int yyerrstatus_
= 0;
924 /// The lookahead symbol.
925 symbol_type yyla
;]b4_locations_if([[
927 /// The locations where the error started and ended.
928 stack_symbol_type yyerror_range
[2];]])[
931 stack_symbol_type yylhs
;
933 /// The return value of parse().
936 YYCDEBUG
<< "Starting parse" << std::endl
;
938 ]m4_ifdef([b4_initial_action
], [
939 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
940 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
941 /* User initialization code. */
942 b4_user_initial_action
943 m4_popdef([b4_dollar_dollar
])dnl
944 m4_popdef([b4_at_dollar
])])dnl
946 [ /* Initialize the stack. The initial state will be set in
947 yynewstate, since the latter expects the semantical and the
948 location values to have been already stored, initialize these
949 stacks with a primary value. */
950 yystack_
= stack_type (0);
951 yypush_ (0, 0, yyla
);
953 // A new state was pushed on the stack.
954 // Invariant: yystate == yystack_[0].state, i.e.,
955 // yystate was just pushed onto the state stack.
957 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
960 if (yystate
== yyfinal_
)
968 /* Try to take a decision without lookahead. */
969 yyn
= yypact_
[yystate
];
970 if (yyn
== yypact_ninf_
)
973 /* Read a lookahead token. */
976 YYCDEBUG
<< "Reading a token: ";
978 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
979 m4_ifdef([b4_lex_param
], b4_lex_param
));],
980 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
981 [[YYSTYPE
*], [&yyla
.value
]][]dnl
982 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
983 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
986 YY_SYMBOL_PRINT ("Next token is", yyla
);
988 /* If the proper action on seeing token YYLA.TYPE is to reduce or
989 to detect an error, take that action. */
991 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
994 /* Reduce or error. */
998 if (yyn
== 0 || yyn
== yytable_ninf_
)
1004 /* Discard the token being shifted. */
1007 /* Count tokens shifted since error; after three, turn off error
1012 /* Shift the lookahead token. */
1014 yypush_ ("Shifting", yystate
, yyla
);
1017 /*-----------------------------------------------------------.
1018 | yydefault -- do the default action for the current state. |
1019 `-----------------------------------------------------------*/
1021 yyn
= yydefact_
[yystate
];
1026 /*-----------------------------.
1027 | yyreduce -- Do a reduction. |
1028 `-----------------------------*/
1030 yylen
= yyr2_
[yyn
];]b4_variant_if([
1031 /* Variants are always initialized to an empty instance of the
1032 correct type. The default $$=$1 action is NOT applied when using
1034 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
]),[
1035 /* If YYLEN is nonzero, implement the default value of the action:
1036 `$$ = $1'. Otherwise, use the top of the stack.
1038 Otherwise, the following line sets YYLHS.VALUE to garbage.
1039 This behavior is undocumented and Bison
1040 users should not rely upon it. */
1042 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1044 yylhs
.value
= yystack_@
{0@
}.value
;])[
1045 ]b4_locations_if([dnl
1047 // Compute the default @@$.
1049 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1050 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1053 // Perform the reduction.
1054 YY_REDUCE_PRINT (yyn
);
1061 // Compute post-reduction state.
1063 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1064 if (0 <= yystate
&& yystate
<= yylast_
1065 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1066 yystate
= yytable_
[yystate
];
1068 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1069 yylhs
.state
= yystate
;
1070 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1072 // Destroy the rhs symbols.
1073 for (int i
= 0; i
< yylen
; ++i
)
1074 // Destroy a variant which value may have been swapped with
1075 // yylhs.value (for instance if the action was "std::swap($$,
1076 // $1)"). The value of yylhs.value (hence possibly one of these
1077 // rhs symbols) depends on the default contruction for this
1078 // type. In the case of pointers for instance, no
1079 // initialization is done, so the value is junk. Therefore do
1080 // not try to report the value of symbols about to be destroyed
1081 // in the debug trace, it's possibly junk. Hence yymsg = 0.
1082 // Besides, that keeps exactly the same traces as with the other
1084 yy_destroy_ (0, yystack_
[i
]);]])[
1090 /* Shift the result of the reduction. */
1094 /*--------------------------------------.
1095 | yyerrlab -- here on detecting error. |
1096 `--------------------------------------*/
1098 /* If not already recovering from an error, report this error. */
1102 error (]b4_args(b4_locations_if([yyla
.location
]),
1103 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1107 yyerror_range
[0].location
= yyla
.location
;]])[
1108 if (yyerrstatus_
== 3)
1110 /* If just tried and failed to reuse lookahead token after an
1111 error, discard it. */
1113 /* Return failure if at end of input. */
1114 if (yyla
.type
== yyeof_
)
1118 yy_destroy_ ("Error: discarding", yyla
);
1123 /* Else will try to reuse lookahead token after shifting the error
1128 /*---------------------------------------------------.
1129 | yyerrorlab -- error raised explicitly by YYERROR. |
1130 `---------------------------------------------------*/
1133 /* Pacify compilers like GCC when the user code never invokes
1134 YYERROR and the label yyerrorlab therefore never appears in user
1140 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1141 /* Do not reclaim the symbols of the rule which action triggered
1145 yystate
= yystack_
[0].state
;
1148 /*-------------------------------------------------------------.
1149 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1150 `-------------------------------------------------------------*/
1152 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1154 stack_symbol_type error_token
;
1157 yyn
= yypact_
[yystate
];
1158 if (yyn
!= yypact_ninf_
)
1161 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1163 yyn
= yytable_
[yyn
];
1169 // Pop the current state because it cannot handle the error token.
1170 if (yystack_
.size () == 1)
1173 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1174 yy_destroy_ ("Error: popping", yystack_
[0]);
1176 yystate
= yystack_
[0].state
;
1180 yyerror_range
[1].location
= yyla
.location
;
1181 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1183 /* Shift the error token. */
1184 error_token
.state
= yystate
= yyn
;
1185 yypush_ ("Shifting", error_token
);
1201 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1203 /* Do not reclaim the symbols of the rule which action triggered
1204 this YYABORT or YYACCEPT. */
1206 while (yystack_
.size () != 1)
1208 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1215 // Generate an error message.
1217 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1218 b4_error_verbose_if([int yystate
, int yytoken
],
1221 std::string yyres
;]b4_error_verbose_if([[
1222 int yyn
= yypact_
[yystate
];
1223 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1225 /* Start YYX at -YYN if negative to avoid negative indexes in
1227 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1229 /* Stay within bounds of both yycheck and yytname. */
1230 int yychecklim
= yylast_
- yyn
+ 1;
1231 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1233 // Number of reported tokens (one for the "unexpected", one per
1237 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1238 // Arguments of yyformat.
1239 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1240 yyarg
[yycount
++] = yytname_
[yytoken
];
1241 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1242 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1244 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1250 yyarg
[yycount
++] = yytname_
[yyx
];
1253 char const* yyformat
= 0;
1256 #define YYCASE_(N, S) \
1260 YYCASE_(1, YY_("syntax error, unexpected %s"));
1261 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1262 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1263 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1264 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1269 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1270 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1272 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1280 [ yyres
= YY_("syntax error");
1285 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1287 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1289 ]b4_parser_tables_define
[
1291 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1292 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1293 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1295 const ]b4_parser_class_name
[::yytname_
[] =
1302 ]b4_integral_parser_table_define([rline
], [b4_rline
])[
1304 // Print the state stack on the debug stream.
1306 ]b4_parser_class_name
[::yystack_print_ ()
1308 *yycdebug_
<< "Stack now";
1309 for (stack_type::const_iterator
1310 i
= yystack_
.begin (),
1311 i_end
= yystack_
.end ();
1313 *yycdebug_
<< ' ' << i
->state
;
1314 *yycdebug_
<< std::endl
;
1317 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1319 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1321 unsigned int yylno
= yyrline_
[yyrule
];
1322 int yynrhs
= yyr2_
[yyrule
];
1323 /* Print the symbols being reduced, and their result. */
1324 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1325 << " (line " << yylno
<< "):" << std::endl
;
1326 /* The symbols being reduced. */
1327 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1328 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1329 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1333 ]b4_lex_symbol_if([], [b4_yytranslate_definition
])[
1334 ]b4_namespace_close
[
1337 m4_popdef([b4_copyright_years
])dnl