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.
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_
;
679 ]b4_parser_tables_declare
[
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_integral_parser_table_declare([rline
], [b4_rline
],
691 [YYRLINE
[YYN
] -- Source line where rule number YYN was defined
.])[
692 /// Report on the debug stream that the rule \a r is going to be reduced.
693 virtual void yy_reduce_print_ (int r
);
694 /// Print the state stack on the debug stream.
695 virtual void yystack_print_ ();
699 std::ostream
* yycdebug_
;
702 /// Convert a scanner token number \a t to a symbol number.
703 static inline token_number_type
yytranslate_ (]b4_lex_symbol_if([token_type
], [int])[ t
);
705 /// A complete symbol, with its type.
706 template <typename Exact
>
707 struct symbol_base_type
709 /// Default constructor.
710 inline symbol_base_type ();
712 /// Constructor.]b4_locations_if([
713 inline symbol_base_type (const location_type
& l
)])[;
714 inline symbol_base_type (]b4_args(
715 [const semantic_type
& v
],
716 b4_locations_if([const location_type
& l
]))[);
718 /// Return this with its exact type.
719 const Exact
& self () const;
722 /// Return the type of this symbol.
723 int type_get () const;
725 /// The semantic value.
726 semantic_type value
;]b4_locations_if([
729 location_type location
;])[
733 /// \brief Display a symbol type, value and location.
734 /// \param yyo The output stream.
735 /// \param yysym The symbol.
736 template <typename Exact
>
737 void yy_print_ (std::ostream
& yyo
,
738 const symbol_base_type
<Exact
>& yysym
) const;
741 /// \brief Reclaim the memory associated to a symbol.
742 /// \param yymsg Why this token is reclaimed.
743 /// If null, print nothing.
744 /// \param s The symbol.
745 template <typename Exact
>
746 inline void yy_destroy_ (const char* yymsg
,
747 symbol_base_type
<Exact
>& yysym
) const;
750 /// Element of the stack: a state and its attributes.
751 struct symbol_type
: symbol_base_type
<symbol_type
>
753 /// The parent class.
754 typedef symbol_base_type
<symbol_type
> super_type
;
756 /// Default constructor.
757 inline symbol_type ();
760 inline symbol_type (]b4_args([int t
],
761 [const semantic_type
& v
],
762 b4_locations_if([const location_type
& l
]))[);
764 inline symbol_type (]b4_args([int t
],
765 b4_locations_if([const location_type
& l
]))[);
770 /// Return the type corresponding to this state.
771 inline int type_get_ () const;
774 inline token_type
token () const;
777 ]b4_symbol_constructor_declarations
[
780 /// Element of the stack: a state and its attributes.
781 struct stack_symbol_type
: symbol_base_type
<stack_symbol_type
>
783 /// The parent class.
784 typedef symbol_base_type
<stack_symbol_type
> super_type
;
786 /// Default constructor.
787 inline stack_symbol_type ();
790 inline stack_symbol_type (]b4_args([state_type s
],
791 [const semantic_type
& v
],
792 b4_locations_if([const location_type
& l
]))[);
797 /// Return the type corresponding to this state.
798 inline int type_get_ () const;
802 typedef stack
<stack_symbol_type
> stack_type
;
807 /// Push a new state on the stack.
808 /// \param m a debug message to display
809 /// if null, no trace is output.
810 /// \param s the symbol
811 /// \warning the contents of \a s.value is stolen.
812 inline void yypush_ (const char* m
, stack_symbol_type
& s
);
814 /// Push a new look ahead token on the state on the stack.
815 /// \param m a debug message to display
816 /// if null, no trace is output.
817 /// \param s the state
818 /// \param sym the symbol (for its value and location).
819 /// \warning the contents of \a s.value is stolen.
820 inline void yypush_ (const char* m
, state_type s
, symbol_type
& sym
);
822 /// Pop \a n symbols the three stacks.
823 inline void yypop_ (unsigned int n
= 1);
829 yylast_
= ]b4_last
[, //< Last index in yytable_.
830 yynnts_
= ]b4_nterms_number
[, //< Number of nonterminal symbols.
832 yyfinal_
= ]b4_final_state_number
[, //< Termination state number.
835 yyntokens_
= ]b4_tokens_number
[, //< Number of tokens.
838 ]b4_parse_param_vars
[
841 ]b4_lex_symbol_if([b4_yytranslate_definition
])[
842 ]b4_lex_symbol_if([b4_symbol_constructor_definitions
])[
845 ]b4_percent_define_flag_if([[global_tokens_and_yystype]],
846 [b4_token_defines(b4_tokens
)
849 /* Redirection for backward compatibility. */
850 # define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
853 b4_percent_code_get([[provides]])[]dnl
855 [#endif /* ! defined PARSER_HEADER_H */]
856 @
output(b4_parser_file_name@
)@
857 b4_copyright([Skeleton implementation
for Bison
LALR(1) parsers in C
++])
858 b4_percent_code_get([[top]])[]dnl
859 m4_if(b4_prefix
, [yy
], [],
861 // Take the name prefix into account.
862 #define yylex b4_prefix[]lex])[
864 /* First part of user declarations. */
865 ]b4_user_pre_prologue
[
867 #include "@basename(]b4_spec_defines_file[@)"
869 /* User implementation prologue. */
870 ]b4_user_post_prologue
871 b4_percent_code_get
[]dnl
876 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
877 # define YY_(msgid) dgettext ("bison-runtime", msgid)
881 # define YY_(msgid) msgid
885 /* Suppress unused-variable warnings by "using" E. */
886 #define YYUSE(e) ((void) (e))
888 /* Enable debugging if requested. */
891 /* A pseudo ostream that takes yydebug_ into account. */
892 # define YYCDEBUG if (yydebug_) (*yycdebug_)
894 # define YY_SYMBOL_PRINT(Title, Symbol) \
898 *yycdebug_ << Title << ' '; \
899 yy_print_ (*yycdebug_, Symbol); \
900 *yycdebug_ << std::endl; \
904 # define YY_REDUCE_PRINT(Rule) \
907 yy_reduce_print_ (Rule); \
910 # define YY_STACK_PRINT() \
918 # define YYCDEBUG if (false) std::cerr
919 # define YY_SYMBOL_PRINT(Title, Symbol) static_cast<void>(0)
920 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
921 # define YY_STACK_PRINT() static_cast<void>(0)
923 #endif /* !YYDEBUG */
925 #define yyerrok (yyerrstatus_ = 0)
926 #define yyclearin (yyempty = true)
928 #define YYACCEPT goto yyacceptlab
929 #define YYABORT goto yyabortlab
930 #define YYERROR goto yyerrorlab
931 #define YYRECOVERING() (!!yyerrstatus_)
933 ]b4_namespace_open
[]b4_error_verbose_if([[
935 /* Return YYSTR after stripping away unnecessary quotes and
936 backslashes, so that it's suitable for yyerror. The heuristic is
937 that double-quoting is unnecessary unless the string contains an
938 apostrophe, a comma, or backslash (other than backslash-backslash).
939 YYSTR is taken from yytname. */
941 ]b4_parser_class_name
[::yytnamerr_ (const char *yystr
)
945 std::string yyr
= "";
946 char const *yyp
= yystr
;
953 goto do_not_strip_quotes
;
957 goto do_not_strip_quotes
;
966 do_not_strip_quotes
: ;
973 /// Build a parser object.
974 ]b4_parser_class_name::b4_parser_class_name
[ (]b4_parse_param_decl
[)]m4_ifset([b4_parse_param
], [
977 ]m4_ifset([b4_parse_param
], [ ], [ :])[yydebug_ (false),
978 yycdebug_ (&std::cerr
)]m4_ifset([b4_parse_param
], [,])[
979 #endif]b4_parse_param_cons[
983 ]b4_parser_class_name::~b4_parser_class_name
[ ()
992 ]b4_lex_symbol_if([], [b4_symbol_constructor_definitions
])[
994 // stack_symbol_type.
995 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type ()
1001 ]b4_parser_class_name
[::stack_symbol_type::stack_symbol_type (]b4_args(
1003 [const semantic_type
& v
],
1004 b4_locations_if([const location_type
& l
]))[)
1005 : super_type (v
]b4_locations_if([, l
])[)
1011 ]b4_parser_class_name
[::stack_symbol_type::type_get_ () const
1013 return yystos_
[state
];
1017 template <typename Exact
>
1019 ]b4_parser_class_name
[::yy_destroy_ (const char* yymsg
,
1020 symbol_base_type
<Exact
>& yysym
) const
1022 int yytype
= yysym
.type_get ();
1025 YY_SYMBOL_PRINT (yymsg
, yysym
);
1030 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_destructors
]))[
1036 b4_symbol_variant([[yytype]], [[yysym
.value
]], [[template destroy]])])[
1040 template <typename Exact
>
1042 ]b4_parser_class_name
[::yy_print_ (std::ostream
& yyo
,
1043 const symbol_base_type
<Exact
>& yysym
) const
1045 int yytype
= yysym
.type_get ();
1046 yyo
<< (yytype
< yyntokens_
? "token" : "nterm")
1047 << ' ' << yytname_
[yytype
] << " ("]b4_locations_if([
1048 << yysym
.location
<< ": "])[;
1051 ]m4_map([b4_symbol_actions
], m4_defn([b4_symbol_printers
]))[
1060 ]b4_parser_class_name
[::yypush_ (const char* m
, state_type s
,
1064 YY_SYMBOL_PRINT (m
, sym
);
1066 [[ yystack_
.push (stack_symbol_type (]b4_args(
1069 b4_locations_if([sym
.location
]))[));
1070 ]b4_symbol_variant([[yystos_
[s
]]], [[yystack_
[0].value
]],
1071 [build
], [sym
.value
])],
1072 [[ yystack_
.push (stack_symbol_type (]b4_args(
1075 b4_locations_if([sym
.location
]))[));]])[
1079 ]b4_parser_class_name
[::yypush_ (const char* m
, stack_symbol_type
& s
)
1082 YY_SYMBOL_PRINT (m
, s
);
1084 [[ yystack_
.push (stack_symbol_type (]b4_args(
1087 b4_locations_if([s
.location
]))[));
1088 ]b4_symbol_variant([[yystos_
[s
.state
]]], [[yystack_
[0].value
]],
1089 [build
], [s
.value
])],
1090 [ yystack_
.push (s
);])[
1094 ]b4_parser_class_name
[::yypop_ (unsigned int n
)
1101 ]b4_parser_class_name
[::debug_stream () const
1107 ]b4_parser_class_name
[::set_debug_stream (std::ostream
& o
)
1113 ]b4_parser_class_name
[::debug_level_type
1114 ]b4_parser_class_name
[::debug_level () const
1120 ]b4_parser_class_name
[::set_debug_level (debug_level_type l
)
1127 ]b4_parser_class_name
[::parse ()
1129 /// Whether yyla contains a lookahead.
1130 bool yyempty
= true;
1137 /* Error handling. */
1139 int yyerrstatus_
= 0;
1141 /// The lookahead symbol.
1142 symbol_type yyla
;]b4_locations_if([[
1144 /// The locations where the error started and ended.
1145 stack_symbol_type yyerror_range
[2];]])[
1148 stack_symbol_type yylhs
;
1150 /// The return value of parse().
1153 YYCDEBUG
<< "Starting parse" << std::endl
;
1155 ]m4_ifdef([b4_initial_action
], [
1156 m4_pushdef([b4_at_dollar
], [yyla
.location
])dnl
1157 m4_pushdef([b4_dollar_dollar
], [yyla
.value
])dnl
1158 /* User initialization code. */
1159 b4_user_initial_action
1160 m4_popdef([b4_dollar_dollar
])dnl
1161 m4_popdef([b4_at_dollar
])])dnl
1163 [ /* Initialize the stack. The initial state will be set in
1164 yynewstate, since the latter expects the semantical and the
1165 location values to have been already stored, initialize these
1166 stacks with a primary value. */
1167 yystack_
= stack_type (0);
1168 yypush_ (0, 0, yyla
);
1170 // A new state was pushed on the stack.
1171 // Invariant: yystate == yystack_[0].state, i.e.,
1172 // yystate was just pushed onto the state stack.
1174 YYCDEBUG
<< "Entering state " << yystate
<< std::endl
;
1177 if (yystate
== yyfinal_
)
1185 /* Try to take a decision without lookahead. */
1186 yyn
= yypact_
[yystate
];
1187 if (yyn
== yypact_ninf_
)
1190 /* Read a lookahead token. */
1193 YYCDEBUG
<< "Reading a token: ";
1195 [ yyla
= b4_c_function_call([yylex
], [symbol_type
],
1196 m4_ifdef([b4_lex_param
], b4_lex_param
));],
1197 [ yyla
.type
= yytranslate_ (b4_c_function_call([yylex
], [int],
1198 [[YYSTYPE
*], [&yyla
.value
]][]dnl
1199 b4_locations_if([, [[location
*], [&yyla
.location
]]])dnl
1200 m4_ifdef([b4_lex_param
], [, ]b4_lex_param
)));])[
1203 YY_SYMBOL_PRINT ("Next token is", yyla
);
1205 /* If the proper action on seeing token YYLA.TYPE is to reduce or
1206 to detect an error, take that action. */
1208 if (yyn
< 0 || yylast_
< yyn
|| yycheck_
[yyn
] != yyla
.type
)
1211 /* Reduce or error. */
1212 yyn
= yytable_
[yyn
];
1215 if (yyn
== 0 || yyn
== yytable_ninf_
)
1221 /* Discard the token being shifted. */
1224 /* Count tokens shifted since error; after three, turn off error
1229 /* Shift the lookahead token. */
1231 yypush_ ("Shifting", yystate
, yyla
);
1234 /*-----------------------------------------------------------.
1235 | yydefault -- do the default action for the current state. |
1236 `-----------------------------------------------------------*/
1238 yyn
= yydefact_
[yystate
];
1243 /*-----------------------------.
1244 | yyreduce -- Do a reduction. |
1245 `-----------------------------*/
1247 yylen
= yyr2_
[yyn
];]b4_variant_if([
1248 /* Variants are always initialized to an empty instance of the
1249 correct type. The default $$=$1 rule is NOT applied when using
1251 ]b4_symbol_variant([[yyr1_@
{yyn@
}]], [yylhs
.value
], [build
])[],[
1252 /* If YYLEN is nonzero, implement the default value of the action:
1253 `$$ = $1'. Otherwise, use the top of the stack.
1255 Otherwise, the following line sets YYLHS.VALUE to garbage.
1256 This behavior is undocumented and Bison
1257 users should not rely upon it. */
1259 yylhs
.value
= yystack_@
{yylen
- 1@
}.value
;
1261 yylhs
.value
= yystack_@
{0@
}.value
;])[
1262 ]b4_locations_if([dnl
1264 // Compute the default @@$.
1266 slice
<stack_symbol_type
, stack_type
> slice (yystack_
, yylen
);
1267 YYLLOC_DEFAULT (yylhs
.location
, slice
, yylen
);
1270 // Perform the reduction.
1271 YY_REDUCE_PRINT (yyn
);
1278 // Compute post-reduction state.
1280 yystate
= yypgoto_
[yyn
- yyntokens_
] + yystack_
[yylen
].state
;
1281 if (0 <= yystate
&& yystate
<= yylast_
1282 && yycheck_
[yystate
] == yystack_
[yylen
].state
)
1283 yystate
= yytable_
[yystate
];
1285 yystate
= yydefgoto_
[yyn
- yyntokens_
];
1286 yylhs
.state
= yystate
;
1287 YY_SYMBOL_PRINT ("-> $$ =", yylhs
);
1289 // Destroy the lhs symbols.
1290 for (int i
= 0; i
< yylen
; ++i
)
1291 // Destroy a variant which value may have be swapped with
1292 // yylhs.value. The value of yylhs.value (hence maybe one of
1293 // these lhs symbols) depends on what does the default
1294 // contruction for this type. In the case of pointers for
1295 // instance, nothing is done, so the value is junk. Therefore
1296 // do not try to report the content in the debug trace, it's
1297 // junk. Hence yymsg = 0. Besides, that keeps exactly the same
1298 // traces as with the other Bison skeletons.
1299 yy_destroy_ (0, yystack_
[i
]);]])[
1305 /* Shift the result of the reduction. */
1309 /*------------------------------------.
1310 | yyerrlab -- here on detecting error |
1311 `------------------------------------*/
1313 /* If not already recovering from an error, report this error. */
1317 error (]b4_args(b4_locations_if([yyla
.location
]),
1318 [yysyntax_error_ (yystate
, yyla
.type
)])[);
1322 yyerror_range
[0].location
= yyla
.location
;]])[
1323 if (yyerrstatus_
== 3)
1325 /* If just tried and failed to reuse lookahead token after an
1326 error, discard it. */
1328 /* Return failure if at end of input. */
1329 if (yyla
.type
== yyeof_
)
1333 yy_destroy_ ("Error: discarding", yyla
);
1338 /* Else will try to reuse lookahead token after shifting the error
1343 /*---------------------------------------------------.
1344 | yyerrorlab -- error raised explicitly by YYERROR. |
1345 `---------------------------------------------------*/
1348 /* Pacify compilers like GCC when the user code never invokes
1349 YYERROR and the label yyerrorlab therefore never appears in user
1355 yyerror_range
[0].location
= yystack_
[yylen
- 1].location
;]])[
1356 /* Do not reclaim the symbols of the rule which action triggered
1360 yystate
= yystack_
[0].state
;
1363 /*-------------------------------------------------------------.
1364 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1365 `-------------------------------------------------------------*/
1367 yyerrstatus_
= 3; /* Each real token shifted decrements this. */
1369 stack_symbol_type error_token
;
1372 yyn
= yypact_
[yystate
];
1373 if (yyn
!= yypact_ninf_
)
1376 if (0 <= yyn
&& yyn
<= yylast_
&& yycheck_
[yyn
] == yyterror_
)
1378 yyn
= yytable_
[yyn
];
1384 // Pop the current state because it cannot handle the error token.
1385 if (yystack_
.size () == 1)
1388 yyerror_range
[0].location
= yystack_
[0].location
;]])[
1389 yy_destroy_ ("Error: popping", yystack_
[0]);
1391 yystate
= yystack_
[0].state
;
1395 yyerror_range
[1].location
= yyla
.location
;
1396 YYLLOC_DEFAULT (error_token
.location
, (yyerror_range
- 1), 2);]])[
1398 /* Shift the error token. */
1399 error_token
.state
= yystate
= yyn
;
1400 yypush_ ("Shifting", error_token
);
1416 yy_destroy_ ("Cleanup: discarding lookahead", yyla
);
1418 /* Do not reclaim the symbols of the rule which action triggered
1419 this YYABORT or YYACCEPT. */
1421 while (yystack_
.size () != 1)
1423 yy_destroy_ ("Cleanup: popping", yystack_
[0]);
1430 // Generate an error message.
1432 ]b4_parser_class_name
[::yysyntax_error_ (]dnl
1433 b4_error_verbose_if([int yystate
, int yytoken
],
1436 std::string yyres
;]b4_error_verbose_if([[
1437 int yyn
= yypact_
[yystate
];
1438 if (yypact_ninf_
< yyn
&& yyn
<= yylast_
)
1440 /* Start YYX at -YYN if negative to avoid negative indexes in
1442 int yyxbegin
= yyn
< 0 ? -yyn
: 0;
1444 /* Stay within bounds of both yycheck and yytname. */
1445 int yychecklim
= yylast_
- yyn
+ 1;
1446 int yyxend
= yychecklim
< yyntokens_
? yychecklim
: yyntokens_
;
1448 // Number of "expected" tokens.
1451 enum { YYERROR_VERBOSE_ARGS_MAXIMUM
= 5 };
1452 // Arguments of yyformat.
1453 char const *yyarg
[YYERROR_VERBOSE_ARGS_MAXIMUM
];
1454 yyarg
[yycount
++] = yytname_
[yytoken
];
1455 for (int yyx
= yyxbegin
; yyx
< yyxend
; ++yyx
)
1456 if (yycheck_
[yyx
+ yyn
] == yyx
&& yyx
!= yyterror_
)
1458 if (yycount
== YYERROR_VERBOSE_ARGS_MAXIMUM
)
1464 yyarg
[yycount
++] = yytname_
[yyx
];
1467 char const* yyformat
= 0;
1470 #define YYCASE_(N, S) \
1474 YYCASE_(1, YY_("syntax error, unexpected %s"));
1475 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1476 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1477 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1478 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1483 for (char const* yyp
= yyformat
; *yyp
; ++yyp
)
1484 if (yyp
[0] == '%' && yyp
[1] == 's' && yyi
< yycount
)
1486 yyres
+= yytnamerr_ (yyarg
[yyi
++]);
1494 [ yyres
= YY_("syntax error");
1499 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) b4_parser_class_name::yypact_ninf_
= b4_pact_ninf
[;
1501 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) b4_parser_class_name::yytable_ninf_
= b4_table_ninf
[;
1503 ]b4_parser_tables_define
[
1505 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
1506 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1507 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
1509 const ]b4_parser_class_name
[::yytname_
[] =
1516 ]b4_integral_parser_table_define([rline
], [b4_rline
])[
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