# ----------------------------------
# Define the overloaded versions of make_symbol for all the value types.
m4_define([b4_symbol_constructor_definitions],
-[[ // symbol_base_type.
- template <typename Exact>
- ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type ()
- : value()]b4_locations_if([
- , location()])[
- {
- }]b4_locations_if([[
-
- template <typename Exact>
- ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (const location_type& l)
- : value()
- , location(l)
- {
- }]])[
-
- template <typename Exact>
- ]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type (]b4_args(
- [const semantic_type& v],
- b4_locations_if([const location_type& l]))[)
- : value(v)]b4_locations_if([
- , location(l)])[
- {
- }
-
- template <typename Exact>
- const Exact&
- ]b4_parser_class_name[::symbol_base_type<Exact>::self () const
- {
- return static_cast<const Exact&>(*this);
- }
-
- template <typename Exact>
- Exact&
- ]b4_parser_class_name[::symbol_base_type<Exact>::self ()
- {
- return static_cast<Exact&>(*this);
- }
-
- template <typename Exact>
- int
- ]b4_parser_class_name[::symbol_base_type<Exact>::type_get () const
- {
- return self ().type_get_ ();
- }
-
- // symbol_type.
- ]b4_parser_class_name[::symbol_type::symbol_type ()
- : super_type ()
- , type ()
- {
- }
-
- ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
- [int t],
- b4_locations_if([const location_type& l]))[)
- : super_type (]b4_locations_if([l])[)
- , type (t)
- {
- }
-
- ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args(
- [int t],
- [const semantic_type& v],
- b4_locations_if([const location_type& l]))[)
- : super_type (v]b4_locations_if([, l])[)
- , type (t)
- {
- }
-
- int
- ]b4_parser_class_name[::symbol_type::type_get_ () const
- {
- return type;
- }
-]b4_lex_symbol_if([[
- ]b4_parser_class_name[::token_type
- ]b4_parser_class_name[::symbol_type::token () const
- {
- // YYTOKNUM[NUM] -- (External) token number corresponding to the
- // (internal) symbol number NUM (which must be that of a token). */
- static
- const ]b4_int_type_for([b4_toknum])[
- yytoken_number_[] =
- {
- ]b4_toknum[
- };
- return static_cast<token_type> (yytoken_number_[type]);
- }
-]])[
-
-]b4_variant_if(
-[ // Implementation of make_symbol for each symbol type.
+[b4_variant_if([
+ // Implementation of make_symbol for each symbol type.
b4_symbol_foreach([b4_symbol_constructor_definition_])])])
class ]b4_parser_class_name[
{
public:
-#ifndef YYSTYPE
-]b4_variant_if(
-[ /// An auxiliary type to compute the largest semantic type.
- union union_type
- {]b4_type_foreach([b4_char_sizeof])[};
-
- /// Symbol semantic values.
- typedef variant<sizeof(union_type)> semantic_type;],
-[ /// Symbol semantic values.
-m4_ifdef([b4_stype],
-[ union semantic_type
- {b4_user_stype
- };],
-[m4_if(b4_tag_seen_flag, 0,
-[[ typedef int semantic_type;]],
-[[ typedef YYSTYPE semantic_type;]])])])[
-#else
- typedef YYSTYPE semantic_type;
-#endif]b4_locations_if([
- /// Symbol locations.
- typedef b4_percent_define_get([[location_type]]) location_type;])[
- /// Tokens.
- struct token
- {
- ]b4_token_enums(b4_tokens)[
- };
- /// Token type.
- typedef token::yytokentype token_type;
-
+]b4_public_types_declare[
+]b4_symbol_constructor_declarations[
/// Build a parser object.
]b4_parser_class_name[ (]b4_parse_param_decl[);
virtual ~]b4_parser_class_name[ ();
/// Convert a scanner token number \a t to a symbol number.
static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
- /// A complete symbol, with its type.
- template <typename Exact>
- struct symbol_base_type
- {
- /// Default constructor.
- inline symbol_base_type ();
-
- /// Constructor.]b4_locations_if([
- inline symbol_base_type (const location_type& l)])[;
- inline symbol_base_type (]b4_args(
- [const semantic_type& v],
- b4_locations_if([const location_type& l]))[);
-
- /// Return this with its exact type.
- const Exact& self () const;
- Exact& self ();
-
- /// Return the type of this symbol.
- int type_get () const;
-
- /// The semantic value.
- semantic_type value;]b4_locations_if([
-
- /// The location.
- location_type location;])[
- };
-
#if YYDEBUG
/// \brief Display a symbol type, value and location.
/// \param yyo The output stream.
inline void yy_destroy_ (const char* yymsg,
symbol_base_type<Exact>& yysym) const;
- public:
- /// Element of the stack: a state and its attributes.
- struct symbol_type : symbol_base_type<symbol_type>
- {
- /// The parent class.
- typedef symbol_base_type<symbol_type> super_type;
-
- /// Default constructor.
- inline symbol_type ();
-
- /// Constructor.
- inline symbol_type (]b4_args([int t],
- [const semantic_type& v],
- b4_locations_if([const location_type& l]))[);
-
- inline symbol_type (]b4_args([int t],
- b4_locations_if([const location_type& l]))[);
-
- /// The symbol type.
- int type;
-
- /// Return the type corresponding to this state.
- inline int type_get_ () const;
-
- /// Its token.
- inline token_type token () const;
- };
-
-]b4_symbol_constructor_declarations[
-
private:
/// Element of the stack: a state and its attributes.
struct stack_symbol_type : symbol_base_type<stack_symbol_type>
]b4_parse_param_vars[
};
-]b4_lex_symbol_if([b4_yytranslate_definition])[
-]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
+]b4_lex_symbol_if([b4_yytranslate_definition
+b4_public_types_define
+b4_symbol_constructor_definitions])[
]b4_namespace_close[
]b4_percent_define_flag_if([[global_tokens_and_yystype]],
| Symbol types. |
`---------------*/
-]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[
+]b4_lex_symbol_if([], [b4_public_types_define
+b4_symbol_constructor_definitions])[
// stack_symbol_type.
]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
yyreduce:
yylen = yyr2_[yyn];]b4_variant_if([
/* Variants are always initialized to an empty instance of the
- correct type. The default $$=$1 rule is NOT applied when using
- variants */
+ correct type. The default $$=$1 action is NOT applied when using
+ variants. */
]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build]),[
/* If YYLEN is nonzero, implement the default value of the action:
`$$ = $1'. Otherwise, use the top of the stack.