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_table_declare(TABLE-NAME, CONTENT, COMMENT)
23 # ----------------------------------------------
24 # Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
25 m4_define([b4_table_declare
],
26 [m4_ifval([$
3], [b4_c_comment([$
3], [ ])
28 static const b4_int_type_for([$
2]) yy$
1_
[[]];dnl
31 # b4_table_define(TABLE-NAME, CONTENT, COMMENT)
32 # ---------------------------------------------
33 # Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
34 m4_define([b4_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.
46 m4_copy([b4_symbol_value
], [b4_symbol_value_template
])
48 # How the semantic value is extracted when using variants.
50 # b4_symbol_value(VAL, [TYPE])
51 # ----------------------------
52 m4_define([b4_symbol_value
],
57 # b4_symbol_value_template(VAL, [TYPE])
58 # -------------------------------------
59 # Same as b4_symbol_value, but used in a template method.
60 m4_define([b4_symbol_value_template
],
62 [$
1.template as
< $
2 >()],
67 # b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
68 # ----------------------------------------------------------------
69 m4_define([b4_lex_symbol_if
],
70 [b4_percent_define_ifdef([[lex_symbol]], [$
1], [$
2])])
73 # b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
74 # ------------------------------------------------
75 m4_define([b4_assert_if
],
76 [b4_percent_define_ifdef([[assert]], [$
1], [$
2])])
79 # b4_lhs_value([TYPE])
80 # --------------------
81 # Expansion of $<TYPE>$.
82 m4_define([b4_lhs_value
],
83 [b4_symbol_value([yylhs
.value
], [$
1])])
89 m4_define([b4_lhs_location
],
93 # b4_rhs_data(RULE-LENGTH, NUM)
94 # -----------------------------
95 # Return the data corresponding to the symbol #NUM, where the current
96 # rule has RULE-LENGTH symbols on RHS.
97 m4_define([b4_rhs_data
],
98 [yystack_@
{b4_subtract($@
)@
}])
101 # b4_rhs_state(RULE-LENGTH, NUM)
102 # -----------------------------
103 # The state corresponding to the symbol #NUM, where the current
104 # rule has RULE-LENGTH symbols on RHS.
105 m4_define([b4_rhs_state
],
106 [b4_rhs_data([$
1], [$
2]).state
])
109 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
110 # --------------------------------------
111 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
113 m4_define([b4_rhs_value
],
114 [b4_symbol_value([b4_rhs_data([$
1], [$
2]).value
], [$
3])])
117 # b4_rhs_location(RULE-LENGTH, NUM)
118 # ---------------------------------
119 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
121 m4_define([b4_rhs_location
],
122 [b4_rhs_data([$
1], [$
2]).location
])
125 # b4_symbol_(NUM, FIELD)
126 # ----------------------
127 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
129 m4_define([b4_symbol_
],
130 [m4_indir([b4_symbol($
1, $
2)])])
133 # b4_symbol(NUM, FIELD)
134 # ---------------------
135 # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
136 # undefined. If FIELD = id, prepend the prefix.
137 m4_define([b4_symbol
],
139 [id
], [m4_do([b4_percent_define_get([token
.prefix
])],
140 [b4_symbol_([$
1], [id
])])],
144 # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
145 # -------------------------------------------
146 # If FIELD about symbol #NUM is 1 expand IF-TRUE, if is 0, expand IF-FALSE.
147 # Otherwise an error.
148 m4_define([b4_symbol_if
],
149 [m4_case(b4_symbol([$
1], [$
2]),
152 [m4_fatal([$
0: field $
2 of $
1 is
not a Boolean
:] b4_symbol([$
1], [$
2]))])])
155 # b4_symbol_actions(FILENAME, LINENO,
156 # SYMBOL-TAG, SYMBOL-NUM,
157 # SYMBOL-ACTION, SYMBOL-TYPENAME)
158 # -------------------------------------------------
159 # Same as in C, but using references instead of pointers.
160 m4_define([b4_symbol_actions
],
161 [m4_pushdef([b4_dollar_dollar
],
162 [b4_symbol_value_template([yysym
.value
], [$
6])])dnl
163 m4_pushdef([b4_at_dollar
], [yysym
.location
])dnl
165 b4_syncline([$
2], [$
1])
167 b4_syncline([@oline@
], [@ofile@
])
169 m4_popdef([b4_at_dollar
])dnl
170 m4_popdef([b4_dollar_dollar
])dnl
174 # b4_symbol_case_(SYMBOL-NUM)
175 # ---------------------------
176 # Issue a "case NUM" for SYMBOL-NUM.
177 m4_define([b4_symbol_case_
],
178 [ case b4_symbol([$
1], [number
]): // b4_symbol([$1], [tag])
182 # b4_type_action_(NUMS)
183 # ---------------------
184 # Run actions for the symbol NUMS that all have the same type-name.
185 # Skip NUMS that have no type-name.
186 m4_define([b4_type_action_
],
187 [b4_symbol_if([$
1], [has_type
],
188 [m4_map([b4_symbol_case_
], [$@
])[]dnl
189 b4_dollar_dollar([b4_symbol([$
1], [number
])],
190 [b4_symbol([$
1], [tag
])],
191 [b4_symbol([$
1], [type
])]);
197 # b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
198 # -------------------------------------------------
199 # Declare the overloaded version of make_symbol for the (common) type of
200 # these SYMBOL-NUMBERS. Use at class-level.
201 m4_define([b4_symbol_constructor_declaration_
],
202 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
205 make_
[]b4_symbol_([$
1], [id
]) (dnl
206 b4_args(b4_symbol_if([$
1], [has_type
],
207 [const b4_symbol([$
1], [type
])& v
]),
208 b4_locations_if([const location_type
& l
])));
213 # b4_symbol_constructor_declarations
214 # ----------------------------------
215 # Declare symbol constructors for all the value types.
216 # Use at class-level.
217 m4_define([b4_symbol_constructor_declarations
],
219 // Symbol constructors declarations.
220 m4_map([b4_symbol_constructor_declaration_
], m4_defn([b4_symbol_numbers
]))])])
224 # b4_symbol_constructor_definition_(SYMBOL-NUMBER)
225 # ------------------------------------------------
226 # Define symbol constructor for this SYMBOL-NUMBER.
227 m4_define([b4_symbol_constructor_definition_
],
228 [b4_symbol_if([$
1], [is_token
], [b4_symbol_if([$
1], [has_id
],
229 [ b4_parser_class_name::symbol_type
230 b4_parser_class_name::make_
[]b4_symbol_([$
1], [id
]) (dnl
231 b4_args(b4_symbol_if([$
1], [has_type
],
232 [const b4_symbol([$
1], [type
])& v
]),
233 b4_locations_if([const location_type
& l
])))
235 return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$
1], [id
]))],
236 b4_symbol_if([$
1], [has_type
], [v
]),
237 b4_locations_if([l
])));
243 # b4_symbol_constructor_definitions
244 # ----------------------------------
245 # Define the overloaded versions of make_symbol for all the value types.
246 m4_define([b4_symbol_constructor_definitions
],
247 [[ // symbol_base_type.
248 template <typename Exact
>
249 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type ()
250 : value()]b4_locations_if([
255 template <typename Exact
>
256 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (const location_type
& l
)
262 template <typename Exact
>
263 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::symbol_base_type (]b4_args(
264 [const semantic_type
& v
],
265 b4_locations_if([const location_type
& l
]))[)
266 : value(v
)]b4_locations_if([
271 template <typename Exact
>
273 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self () const
275 return static_cast<const Exact
&>(*this);
278 template <typename Exact
>
280 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::self ()
282 return static_cast<Exact
&>(*this);
285 template <typename Exact
>
287 ]b4_parser_class_name
[::symbol_base_type
<Exact
>::type_get () const
289 return self ().type_get_ ();
293 ]b4_parser_class_name
[::symbol_type::symbol_type ()
299 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
301 b4_locations_if([const location_type
& l
]))[)
302 : super_type (]b4_locations_if([l
])[)
307 ]b4_parser_class_name
[::symbol_type::symbol_type (]b4_args(
309 [const semantic_type
& v
],
310 b4_locations_if([const location_type
& l
]))[)
311 : super_type (v
]b4_locations_if([, l
])[)
317 ]b4_parser_class_name
[::symbol_type::type_get_ () const
322 ]b4_parser_class_name
[::token_type
323 ]b4_parser_class_name
[::symbol_type::token () const
325 // YYTOKNUM[NUM] -- (External) token number corresponding to the
326 // (internal) symbol number NUM (which must be that of a token). */
328 const ]b4_int_type_for([b4_toknum
])[
333 return static_cast<token_type
> (yytoken_number_
[type
]);
338 [ // Implementation of make_symbol for each symbol type.
339 m4_map([b4_symbol_constructor_definition_
], m4_defn([b4_symbol_numbers
]))])])
342 # b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
343 # ------------------------------------------------
344 # Run some ACTION ("build", or "destroy") on YYVAL of symbol type
346 m4_define([b4_symbol_variant
],
347 [m4_pushdef([b4_dollar_dollar
],
348 [$
2.$
3< $
][3 >(m4_shift3($@
))])dnl
351 m4_map([b4_type_action_
], m4_defn([b4_type_names
]))[]dnl
355 m4_popdef([b4_dollar_dollar
])dnl
359 # _b4_char_sizeof_counter
360 # -----------------------
361 # A counter used by _b4_char_sizeof_dummy to create fresh symbols.
362 m4_define([_b4_char_sizeof_counter
],
365 # _b4_char_sizeof_dummy
366 # ---------------------
367 # At each call return a new C++ identifier.
368 m4_define([_b4_char_sizeof_dummy
],
369 [m4_define([_b4_char_sizeof_counter
], m4_incr(_b4_char_sizeof_counter
))dnl
370 dummy
[]_b4_char_sizeof_counter
])
373 # b4_char_sizeof_(SYMBOL-NUM)
374 # ---------------------------
375 # A comment describing this symbol.
376 m4_define([b4_char_sizeof_
],
377 [ // b4_symbol([$1], [tag])
380 # b4_char_sizeof(SYMBOL-NUMS)
381 # --------------------------
382 # To be mapped on the list of type names to produce:
384 # char dummy1[sizeof(type_name_1)];
385 # char dummy2[sizeof(type_name_2)];
387 # for defined type names.
388 m4_define([b4_char_sizeof
],
389 [b4_symbol_if([$
1], [has_type
],
391 m4_map([b4_char_sizeof_
], [$@
])dnl
392 char _b4_char_sizeof_dummy@
{sizeof([b4_symbol([$
1], [type
])])@
};
396 # b4_yytranslate_definition
397 # -------------------------
398 # Define yytranslate_. Sometimes we want it in the header file,
399 # sometimes the cc file suffices.
400 m4_define([b4_yytranslate_definition
],
401 [[ // Symbol number corresponding to token number t.
402 ]b4_parser_class_name
[::token_number_type
403 ]b4_parser_class_name
[::yytranslate_ (]b4_lex_symbol_if([token_type
],
407 const token_number_type
412 const unsigned int user_token_number_max_
= ]b4_user_token_number_max
[;
413 const token_number_type undef_token_
= ]b4_undef_token_number
[;
415 if (static_cast<int>(t
) <= yyeof_
)
417 else if (static_cast<unsigned int> (t
) <= user_token_number_max_
)
418 return translate_table
[t
];
425 m4_pushdef([b4_copyright_years
],
426 [2002, 2003, 2004, 2005, 2006, 2007, 2008])
428 m4_define([b4_parser_class_name
],
429 [b4_percent_define_get([[parser_class_name]])])
431 # The header is mandatory.
433 [b4_fatal([b4_skeleton
[: using %%defines is mandatory
]])])
436 [# Backward compatibility.
437 m4_define([b4_location_constructors
])
438 m4_include(b4_pkgdatadir
/[location
.cc
])])
440 # We do want M4 expansion after # for CPP macros.
443 @
output(b4_spec_defines_file@
)@
444 b4_copyright([Skeleton interface
for Bison
LALR(1) parsers in C
++])
445 dnl FIXME
: This is wrong
, we want computed header guards
.
447 /* C++ LALR(1) parser skeleton written by Akim Demaille. */
449 #ifndef PARSER_HEADER_H
450 # define PARSER_HEADER_H
452 ]b4_percent_code_get([[requires]])[
454 ]b4_assert_if([#include <cassert>])[
460 ]b4_locations_if([ class position
;
464 /// A char[S] buffer to store and retrieve objects.
466 /// Sort of a variant, but does not keep track of the nature
467 /// of the stored data, since that knowledge is available
468 /// via the current state.
472 /// Whether something is contained.
475 /// Empty construction.
477 variant ()]b4_assert_if([
481 /// Instantiate a \a T in here.
482 template <typename T
>
488 return *new (buffer
) T
;
491 /// Instantiate a \a T in here from \a t.
492 template <typename T
>
498 return *new (buffer
) T(t
);
501 /// Construct and fill.
502 template <typename T
>
504 variant (const T
& t
)]b4_assert_if([
510 /// Accessor to a built \a T.
511 template <typename T
>
516 return reinterpret_cast<T
&>(buffer
);
519 /// Const accessor to a built \a T (for %printer).
520 template <typename T
>
525 return reinterpret_cast<const T
&>(buffer
);
528 /// Swap the content with \a other.
529 template <typename T
>
531 swap(variant
<S
>& other
)
533 std::swap(as
<T
>(), other
.as
<T
>());
536 /// Assign the content of \a other to this.
537 /// Destroys \a other.
538 template <typename T
>
540 build(variant
<S
>& other
)
547 /// Destroy the stored \a T.
548 template <typename T
>
552 as
<T
>().~T();]b4_assert_if([
556 /// A buffer large enough to store any of the semantic values.
562 ]b4_locations_if([#include "location.hh"])[
564 /* Enabling traces. */
566 # define YYDEBUG ]b4_debug_flag[
569 /* Enabling verbose error messages. */
570 #ifdef YYERROR_VERBOSE
571 # undef YYERROR_VERBOSE
572 # define YYERROR_VERBOSE 1
574 # define YYERROR_VERBOSE ]b4_error_verbose_flag[
577 /* Enabling the token table. */
578 #ifndef YYTOKEN_TABLE
579 # define YYTOKEN_TABLE ]b4_token_table[
582 ]b4_locations_if([dnl
583 [/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
584 If N is 0, then set CURRENT to the empty location which ends
585 the previous symbol: RHS[0] (always defined). */
587 #ifndef YYLLOC_DEFAULT
588 # define YYLLOC_DEFAULT(Current, Rhs, N) \
592 (Current).begin = (Rhs)[1].location.begin; \
593 (Current).end = (Rhs)[N].location.end; \
597 (Current).begin = (Current).end = (Rhs)[0].location.end; \
605 class ]b4_parser_class_name
[
610 [ /// An auxiliary type to compute the largest semantic type.
612 {]m4_map([b4_char_sizeof
], m4_defn([b4_type_names
]))[};
614 /// Symbol semantic values.
615 typedef variant
<sizeof(union_type
)> semantic_type
;],
616 [ /// Symbol semantic values.
618 [ union semantic_type
621 [m4_if(b4_tag_seen_flag
, 0,
622 [[ typedef int semantic_type
;]],
623 [[ typedef YYSTYPE semantic_type
;]])])])[
625 typedef YYSTYPE semantic_type
;
626 #endif]b4_locations_if([
627 /// Symbol locations.
628 typedef b4_percent_define_get([[location_type]]) location_type
;])[
632 ]b4_token_enums(b4_tokens
)[
635 typedef token::yytokentype token_type
;
637 /// Build a parser object.
638 ]b4_parser_class_name
[ (]b4_parse_param_decl
[);
639 virtual ~]b4_parser_class_name
[ ();
642 /// \returns 0 iff parsing succeeded.
643 virtual int parse ();
646 /// The current debugging stream.
647 std::ostream
& debug_stream () const;
648 /// Set the current debugging stream.
649 void set_debug_stream (std::ostream
&);
651 /// Type for debugging levels.
652 typedef int debug_level_type
;
653 /// The current debugging level.
654 debug_level_type
debug_level () const;
655 /// Set the current debugging level.
656 void set_debug_level (debug_level_type l
);
660 /// Report a syntax error.]b4_locations_if([
661 /// \param loc where the syntax error is found.])[
662 /// \param msg a description of the syntax error.
663 virtual void error (]b4_locations_if([const location_type
& loc
, ])[const std::string
& msg
);
665 /// Generate an error message.
666 /// \param state the state where the error occurred.
667 /// \param tok the lookahead token.
668 virtual std::string
yysyntax_error_ (int yystate
, int tok
);
671 typedef int state_type
;
673 /// Internal symbol numbers.
674 typedef ]b4_int_type_for([b4_translate
])[ token_number_type
;
675 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ yypact_ninf_
;
676 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ yytable_ninf_
;
681 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
682 /// For a symbol, its name in clear.
683 static const char* const yytname_
[];
684 #endif]b4_error_verbose_if([
686 /// Convert the symbol name \a n to a form suitable for a diagnostic.
687 static std::string
yytnamerr_ (const char *n
);])[
690 ]b4_table_declare([rline
], [b4_rline
])[
691 /// Report on the debug stream that the rule \a r is going to be reduced.
692 virtual void yy_reduce_print_ (int r
);
693 /// Print the state stack on the debug stream.
694 virtual void yystack_print_ ();
698 std::ostream
* yycdebug_
;
701 /// Convert a scanner token number \a t to a symbol number.
702 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
704 /// A complete symbol, with its type.
705 template <typename Exact
>
706 struct symbol_base_type
708 /// Default constructor.
709 inline symbol_base_type ();
711 /// Constructor.]b4_locations_if([
712 inline symbol_base_type (const location_type
& l
)])[;
713 inline symbol_base_type (]b4_args(
714 [const semantic_type
& v
],
715 b4_locations_if([const location_type
& l
]))[);
717 /// Return this with its exact type.
718 const Exact
& self () const;
721 /// Return the type of this symbol.
722 int type_get () const;
724 /// The semantic value.
725 semantic_type value
;]b4_locations_if([
728 location_type location
;])[
732 /// \brief Display a symbol type, value and location.
733 /// \param yyo The output stream.
734 /// \param yysym The symbol.
735 template <typename Exact
>
736 void yy_print_ (std::ostream
& yyo
,
737 const symbol_base_type
<Exact
>& yysym
) const;
740 /// \brief Reclaim the memory associated to a symbol.
741 /// \param yymsg Why this token is reclaimed.
742 /// If null, print nothing.
743 /// \param s The symbol.
744 template <typename Exact
>
745 inline void yy_destroy_ (const char* yymsg
,
746 symbol_base_type
<Exact
>& yysym
) const;
749 /// Element of the stack: a state and its attributes.
750 struct symbol_type
: symbol_base_type
<symbol_type
>
752 /// The parent class.
753 typedef symbol_base_type
<symbol_type
> super_type
;
755 /// Default constructor.
756 inline symbol_type ();
759 inline symbol_type (]b4_args([int t
],
760 [const semantic_type
& v
],
761 b4_locations_if([const location_type
& l
]))[);
763 inline symbol_type (]b4_args([int t
],
764 b4_locations_if([const location_type
& l
]))[);
769 /// Return the type corresponding to this state.
770 inline int type_get_ () const;
773 inline token_type
token () const;
776 ]b4_symbol_constructor_declarations
[
779 /// Element of the stack: a state and its attributes.
780 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
782 /// The parent class.
783 typedef symbol_base_type
<stack_symbol_type
> super_type
;
785 /// Default constructor.
786 inline stack_symbol_type ();
789 inline stack_symbol_type (]b4_args([state_type s
],
790 [const semantic_type
& v
],
791 b4_locations_if([const location_type
& l
]))[);
796 /// Return the type corresponding to this state.
797 inline int type_get_ () const;
801 typedef stack
<stack_symbol_type
> stack_type
;
806 /// Push a new state on the stack.
807 /// \param m a debug message to display
808 /// if null, no trace is output.
809 /// \param s the symbol
810 /// \warning the contents of \a s.value is stolen.
811 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
813 /// Push a new look ahead token on the state on the stack.
814 /// \param m a debug message to display
815 /// if null, no trace is output.
816 /// \param s the state
817 /// \param sym the symbol (for its value and location).
818 /// \warning the contents of \a s.value is stolen.
819 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
821 /// Pop \a n symbols the three stacks.
822 inline void yypop_ (unsigned int n
= 1);
828 yylast_
= ]b4_last
[, //< Last index in yytable_.
829 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
831 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
834 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
837 ]b4_parse_param_vars
[
840 ]b4_lex_symbol_if([b4_yytranslate_definition
])[
841 ]b4_lex_symbol_if([b4_symbol_constructor_definitions
])[
844 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
845 [b4_token_defines(b4_tokens
)
848 /* Redirection for backward compatibility. */
849 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
852 b4_percent_code_get([[provides]])[]dnl
854 [#endif /* ! defined PARSER_HEADER_H */]
855 @
output(b4_parser_file_name@
)@
856 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
857 b4_percent_code_get([[top]])[]dnl
858 m4_if(b4_prefix
, [yy
], [],
860 // Take the name prefix into account.
861 #define yylex b4_prefix[]lex])[
863 /* First part of user declarations. */
864 ]b4_user_pre_prologue
[
866 #include "@basename(]b4_spec_defines_file[@)"
868 /* User implementation prologue. */
869 ]b4_user_post_prologue
870 b4_percent_code_get
[]dnl
875 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
876 # define YY_(msgid) dgettext ("bison-runtime", msgid)
880 # define YY_(msgid) msgid
884 /* Suppress unused-variable warnings by "using" E. */
885 #define YYUSE(e) ((void) (e))
887 /* Enable debugging if requested. */
890 /* A pseudo ostream that takes yydebug_ into account. */
891 # define YYCDEBUG if (yydebug_) (*yycdebug_)
893 # define YY_SYMBOL_PRINT(Title, Symbol) \
897 *yycdebug_ << Title << ' '; \
898 yy_print_ (*yycdebug_, Symbol); \
899 *yycdebug_ << std::endl; \
903 # define YY_REDUCE_PRINT(Rule) \
906 yy_reduce_print_ (Rule); \
909 # define YY_STACK_PRINT() \
917 # define YYCDEBUG if (false) std::cerr
918 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
919 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
920 # define YY_STACK_PRINT() static_cast<void>(0)
922 #endif /* !YYDEBUG */
924 #define yyerrok (yyerrstatus_ = 0)
925 #define yyclearin (yyempty = true)
927 #define YYACCEPT goto yyacceptlab
928 #define YYABORT goto yyabortlab
929 #define YYERROR goto yyerrorlab
930 #define YYRECOVERING() (!!yyerrstatus_)
932 ]b4_namespace_open
[]b4_error_verbose_if([[
934 /* Return YYSTR after stripping away unnecessary quotes and
935 backslashes, so that it's suitable for yyerror. The heuristic is
936 that double-quoting is unnecessary unless the string contains an
937 apostrophe, a comma, or backslash (other than backslash-backslash).
938 YYSTR is taken from yytname. */
940 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
944 std::string yyr
= "";
945 char const *yyp
= yystr
;
952 goto do_not_strip_quotes
;
956 goto do_not_strip_quotes
;
965 do_not_strip_quotes
: ;
972 /// Build a parser object.
973 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
976 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
977 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
978 #endif]b4_parse_param_cons[
982 ]b4_parser_class_name::~b4_parser_class_name
[ ()
991 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions
])[
993 // stack_symbol_type.
994 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
1000 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
1002 [const semantic_type
& v
],
1003 b4_locations_if([const location_type
& l
]))[)
1004 : super_type (v
]b4_locations_if([, l
])[)
1010 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
1012 return yystos_
[state
];
1016 template <typename Exact
>
1018 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
1019 symbol_base_type
<Exact
>& yysym
) const
1021 int yytype
= yysym
.type_get ();
1024 YY_SYMBOL_PRINT (yymsg
, yysym
);
1029 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
1035 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1039 template <typename Exact
>
1041 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1042 const symbol_base_type
<Exact
>& yysym
) const
1044 int yytype
= yysym
.type_get ();
1045 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1046 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1047 << yysym
.location
<< ": "])[;
1050 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1059 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1063 YY_SYMBOL_PRINT (m
, sym
);
1065 [[ yystack_
.push (stack_symbol_type (]b4_args(
1068 b4_locations_if([sym
.location
]))[));
1069 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1070 [build
], [sym
.value
])],
1071 [[ yystack_
.push (stack_symbol_type (]b4_args(
1074 b4_locations_if([sym
.location
]))[));]])[
1078 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1081 YY_SYMBOL_PRINT (m
, s
);
1083 [[ yystack_
.push (stack_symbol_type (]b4_args(
1086 b4_locations_if([s
.location
]))[));
1087 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1088 [build
], [s
.value
])],
1089 [ yystack_
.push (s
);])[
1093 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1100 ]b4_parser_class_name
[::debug_stream () const
1106 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1112 ]b4_parser_class_name
[::debug_level_type
1113 ]b4_parser_class_name
[::debug_level () const
1119 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1126 ]b4_parser_class_name
[::parse ()
1128 /// Whether yyla contains a lookahead.
1129 bool yyempty
= true;
1136 /* Error handling. */
1138 int yyerrstatus_
= 0;
1140 /// The lookahead symbol.
1141 symbol_type yyla
;]b4_locations_if([[
1143 /// The locations where the error started and ended.
1144 stack_symbol_type yyerror_range
[2];]])[
1147 stack_symbol_type yylhs
;
1149 /// The return value of parse().
1152 YYCDEBUG
<< "Starting parse" << std::endl
;
1154 ]m4_ifdef([b4_initial_action
], [
1155 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1156 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1157 /* User initialization code. */
1158 b4_user_initial_action
1159 m4_popdef([b4_dollar_dollar
])dnl
1160 m4_popdef([b4_at_dollar
])])dnl
1162 [ /* Initialize the stack. The initial state will be set in
1163 yynewstate, since the latter expects the semantical and the
1164 location values to have been already stored, initialize these
1165 stacks with a primary value. */
1166 yystack_
= stack_type (0);
1167 yypush_ (0, 0, yyla
);
1169 // A new state was pushed on the stack.
1170 // Invariant: yystate == yystack_[0].state, i.e.,
1171 // yystate was just pushed onto the state stack.
1173 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1176 if (yystate
== yyfinal_
)
1184 /* Try to take a decision without lookahead. */
1185 yyn
= yypact_
[yystate
];
1186 if (yyn
== yypact_ninf_
)
1189 /* Read a lookahead token. */
1192 YYCDEBUG
<< "Reading a token: ";
1194 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1195 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1196 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1197 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1198 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1199 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1202 YY_SYMBOL_PRINT ("Next token is", yyla
);
1204 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1205 to detect an error, take that action. */
1207 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1210 /* Reduce or error. */
1211 yyn
= yytable_
[yyn
];
1214 if (yyn
== 0 || yyn
== yytable_ninf_
)
1220 /* Discard the token being shifted. */
1223 /* Count tokens shifted since error; after three, turn off error
1228 /* Shift the lookahead token. */
1230 yypush_ ("Shifting", yystate
, yyla
);
1233 /*-----------------------------------------------------------.
1234 | yydefault -- do the default action for the current state. |
1235 `-----------------------------------------------------------*/
1237 yyn
= yydefact_
[yystate
];
1242 /*-----------------------------.
1243 | yyreduce -- Do a reduction. |
1244 `-----------------------------*/
1246 yylen
= yyr2_
[yyn
];]b4_variant_if([
1247 /* Variants are always initialized to an empty instance of the
1248 correct type. The default $$=$1 rule is NOT applied when using
1250 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1251 /* If YYLEN is nonzero, implement the default value of the action:
1252 `$$ = $1'. Otherwise, use the top of the stack.
1254 Otherwise, the following line sets YYLHS.VALUE to garbage.
1255 This behavior is undocumented and Bison
1256 users should not rely upon it. */
1258 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1260 yylhs
.value
= yystack_@
{0@
}.value
;])[
1261 ]b4_locations_if([dnl
1263 // Compute the default @@$.
1265 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1266 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1269 // Perform the reduction.
1270 YY_REDUCE_PRINT (yyn
);
1277 // Compute post-reduction state.
1279 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1280 if (0 <= yystate
&& yystate
<= yylast_
1281 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1282 yystate
= yytable_
[yystate
];
1284 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1285 yylhs
.state
= yystate
;
1286 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1288 // Destroy the lhs symbols.
1289 for (int i
= 0; i
< yylen
; ++i
)
1290 // Destroy a variant which value may have be swapped with
1291 // yylhs.value. The value of yylhs.value (hence maybe one of
1292 // these lhs symbols) depends on what does the default
1293 // contruction for this type. In the case of pointers for
1294 // instance, nothing is done, so the value is junk. Therefore
1295 // do not try to report the content in the debug trace, it's
1296 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1297 // traces as with the other Bison skeletons.
1298 yy_destroy_ (0, yystack_
[i
]);]])[
1304 /* Shift the result of the reduction. */
1308 /*------------------------------------.
1309 | yyerrlab -- here on detecting error |
1310 `------------------------------------*/
1312 /* If not already recovering from an error, report this error. */
1316 error (]b4_args(b4_locations_if([yyla
.location
]),
1317 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1321 yyerror_range
[0].location
= yyla
.location
;]])[
1322 if (yyerrstatus_
== 3)
1324 /* If just tried and failed to reuse lookahead token after an
1325 error, discard it. */
1327 /* Return failure if at end of input. */
1328 if (yyla
.type
== yyeof_
)
1332 yy_destroy_ ("Error: discarding", yyla
);
1337 /* Else will try to reuse lookahead token after shifting the error
1342 /*---------------------------------------------------.
1343 | yyerrorlab -- error raised explicitly by YYERROR. |
1344 `---------------------------------------------------*/
1347 /* Pacify compilers like GCC when the user code never invokes
1348 YYERROR and the label yyerrorlab therefore never appears in user
1354 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1355 /* Do not reclaim the symbols of the rule which action triggered
1359 yystate
= yystack_
[0].state
;
1362 /*-------------------------------------------------------------.
1363 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1364 `-------------------------------------------------------------*/
1366 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1368 stack_symbol_type error_token
;
1371 yyn
= yypact_
[yystate
];
1372 if (yyn
!= yypact_ninf_
)
1375 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1377 yyn
= yytable_
[yyn
];
1383 // Pop the current state because it cannot handle the error token.
1384 if (yystack_
.size () == 1)
1387 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1388 yy_destroy_ ("Error: popping", yystack_
[0]);
1390 yystate
= yystack_
[0].state
;
1394 yyerror_range
[1].location
= yyla
.location
;
1395 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1397 /* Shift the error token. */
1398 error_token
.state
= yystate
= yyn
;
1399 yypush_ ("Shifting", error_token
);
1415 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1417 /* Do not reclaim the symbols of the rule which action triggered
1418 this YYABORT or YYACCEPT. */
1420 while (yystack_
.size () != 1)
1422 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1429 // Generate an error message.
1431 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1432 b4_error_verbose_if([int yystate
, int yytoken
],
1435 std::string yyres
;]b4_error_verbose_if([[
1436 int yyn
= yypact_
[yystate
];
1437 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1439 /* Start YYX at -YYN if negative to avoid negative indexes in
1441 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1443 /* Stay within bounds of both yycheck and yytname. */
1444 int yychecklim
= yylast_
- yyn
+ 1;
1445 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1447 // Number of "expected" tokens.
1450 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1451 // Arguments of yyformat.
1452 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1453 yyarg
[yycount
++] = yytname_
[yytoken
];
1454 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1455 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1457 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1463 yyarg
[yycount
++] = yytname_
[yyx
];
1466 char const* yyformat
= 0;
1469 #define YYCASE_(N, S) \
1473 YYCASE_(1, YY_("syntax error, unexpected %s"));
1474 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1475 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1476 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1477 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1482 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1483 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1485 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1493 [ yyres
= YY_("syntax error");
1498 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1500 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1504 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1505 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1506 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1508 const ]b4_parser_class_name
[::yytname_
[] =
1515 ]b4_table_define([rline
], [b4_rline
],
1516 [YYRLINE
[YYN
] -- Source line where rule number YYN was defined
.])[
1518 // Print the state stack on the debug stream.
1520 ]b4_parser_class_name
[::yystack_print_ ()
1522 *yycdebug_
<< "Stack now";
1523 for (stack_type::const_iterator
1524 i
= yystack_
.begin (),
1525 i_end
= yystack_
.end ();
1527 *yycdebug_
<< ' ' << i
->state
;
1528 *yycdebug_
<< std::endl
;
1531 // Report on the debug stream that the rule \a yyrule is going to be reduced.
1533 ]b4_parser_class_name
[::yy_reduce_print_ (int yyrule
)
1535 unsigned int yylno
= yyrline_
[yyrule
];
1536 int yynrhs
= yyr2_
[yyrule
];
1537 /* Print the symbols being reduced, and their result. */
1538 *yycdebug_
<< "Reducing stack by rule " << yyrule
- 1
1539 << " (line " << yylno
<< "):" << std::endl
;
1540 /* The symbols being reduced. */
1541 for (int yyi
= 0; yyi
< yynrhs
; yyi
++)
1542 YY_SYMBOL_PRINT (" $" << yyi
+ 1 << " =",
1543 ]b4_rhs_data(yynrhs
, yyi
+ 1)[);
1547 ]b4_lex_symbol_if([], [b4_yytranslate_definition
])[
1548 ]b4_namespace_close
[
1551 @
output(b4_dir_prefix
[]stack
.hh@
)@
1552 b4_copyright([Stack handling
for Bison parsers in C
++])[
1554 #ifndef BISON_STACK_HH
1555 # define BISON_STACK_HH
1560 template <class T
, class S
= std::deque
<T
> >
1565 // Hide our reversed order.
1566 typedef typename
S::reverse_iterator iterator
;
1567 typedef typename
S::const_reverse_iterator const_iterator
;
1573 stack (unsigned int n
) : seq_ (n
)
1579 operator [] (unsigned int i
)
1586 operator [] (unsigned int i
) const
1595 seq_
.push_front (t
);
1600 pop (unsigned int n
= 1)
1607 typename
S::size_type
1610 return seq_
.size ();
1613 inline const_iterator
begin () const { return seq_
.rbegin (); }
1614 inline const_iterator
end () const { return seq_
.rend (); }
1617 /// The wrapped container.
1621 /// Present a slice of the top of a stack.
1622 template <class T
, class S
= stack
<T
> >
1627 slice (const S
& stack
,
1628 unsigned int range
) : stack_ (stack
),
1635 operator [] (unsigned int i
) const
1637 return stack_
[range_
- i
];
1643 unsigned int range_
;
1645 ]b4_namespace_close
[
1647 #endif // not BISON_STACK_HH[]dnl
1650 m4_popdef([b4_copyright_years
])dnl