m4_include(b4_pkgdatadir/[c++.m4])
-# b4_args(ARG1, ...)
-# _b4_args(ARG1, ...)
-# -------------------
-# Join with comma, skipping empty arguments.
-# b4_args calls itself recursively until it sees the first non-empty
-# argument, then calls _b4_args which prepends each non-empty argument
-# with a comma.
-m4_define([b4_args],
-[m4_if([$#$1],
- [1], [],
- [m4_ifval([$1],
- [$1[]_$0(m4_shift($@))],
- [$0(m4_shift($@))])])])
-
-# _b4_args(ARGS1, ...)
-# --------------------
-m4_define([_b4_args],
-[m4_if([$#$1],
- [1], [],
- [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])])
-
+# b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
+# --------------------------------------------------------------
+# Declare "parser::yy<TABLE-NAME>_" which contents is CONTENT.
+m4_define([b4_integral_parser_table_declare],
+[m4_ifval([$3], [b4_c_comment([$3], [ ])
+])dnl
+ static const b4_int_type_for([$2]) yy$1_[[]];dnl
+])
-# b4_table_define(TABLE-NAME, CONTENT)
-# ------------------------------------
+# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
+# ---------------------------------------------
# Define "parser::yy<TABLE-NAME>_" which contents is CONTENT.
-m4_define([b4_table_define],
-[const b4_int_type_for([$2])
+m4_define([b4_integral_parser_table_define],
+[ const b4_int_type_for([$2])
b4_parser_class_name::yy$1_[[]] =
{
$2
- }dnl
+ };dnl
])
+
# b4_symbol_value_template(VAL, [TYPE])
# -------------------------------------
# Same as b4_symbol_value, but used in a template method.
# ----------------------------
m4_define([b4_symbol_value],
[m4_ifval([$2],
- [$1.as<$2>()],
+ [$1.as< $2 >()],
[$1])])
# b4_symbol_value_template(VAL, [TYPE])
# Same as b4_symbol_value, but used in a template method.
m4_define([b4_symbol_value_template],
[m4_ifval([$2],
- [$1.template as<$2>()],
+ [$1.template as< $2 >()],
[$1])])
]) # b4_variant_if
# Return the data corresponding to the symbol #NUM, where the current
# rule has RULE-LENGTH symbols on RHS.
m4_define([b4_rhs_data],
- [yystack_@{($1) - ($2)@}])
+ [yystack_@{b4_subtract($@)@}])
# b4_rhs_state(RULE-LENGTH, NUM)
[b4_rhs_data([$1], [$2]).location])
+# b4_symbol_(NUM, FIELD)
+# ----------------------
+# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
+# undefined.
+m4_define([b4_symbol_],
+[m4_indir([b4_symbol($1, $2)])])
+
+
# b4_symbol(NUM, FIELD)
# ---------------------
# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
-# undefined.
+# undefined. If FIELD = id, prepend the prefix.
m4_define([b4_symbol],
-[m4_indir([b4_symbol($1, $2)])])
+[m4_case([$2],
+ [id], [m4_do([b4_percent_define_get([token.prefix])],
+ [b4_symbol_([$1], [id])])],
+ [b4_symbol_($@)])])
# b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE)
])])
-# b4_symbol_constructor_declaration_(SYMBOL-NUMBERS)
-# ----------------------------------------------------
+# b4_symbol_constructor_declaration_(SYMBOL-NUMBER)
+# -------------------------------------------------
# Declare the overloaded version of make_symbol for the (common) type of
# these SYMBOL-NUMBERS. Use at class-level.
m4_define([b4_symbol_constructor_declaration_],
-[ template <token_type>
- static inline symbol_type
- make_symbol (b4_args(b4_symbol_if([$1], [has_type],
- [const b4_symbol([$1], [type])& v]),
- b4_locations_if([const location_type& l])));
+[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
+[ static inline
+ symbol_type
+ make_[]b4_symbol_([$1], [id]) (dnl
+b4_args(b4_symbol_if([$1], [has_type],
+ [const b4_symbol([$1], [type])& v]),
+ b4_locations_if([const location_type& l])));
+
+])])])
-])
# b4_symbol_constructor_declarations
# ----------------------------------
-# Declare the overloaded versions of make_symbol for all the value types.
+# Declare symbol constructors for all the value types.
# Use at class-level.
m4_define([b4_symbol_constructor_declarations],
[b4_variant_if([
- // Declaration of make_symbol for each value type.
-m4_map([b4_symbol_constructor_declaration_], m4_defn([b4_type_names]))])])
-
-
-
-# b4_symbol_constructor_specialization_(SYMBOL-NUMBER)
-# ----------------------------------------------------
-# Declare the specialization of make_symbol for this each SYMBOL-NUMBER.
-# Specializations cannot be declared at class-level, this must be done
-# at namespace-level.
-m4_define([b4_symbol_constructor_specialization_],
-[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
-[ template <>
- inline
- b4_parser_class_name::symbol_type
- b4_parser_class_name::make_symbol <b4_parser_class_name::token::b4_symbol([$1], [id])> (dnl
-b4_args(b4_symbol_if([$1], [has_type],
- [const b4_symbol([$1], [type])& v]),
- b4_locations_if([const b4_parser_class_name::location_type& l])));
-])])])
-
-# b4_symbol_constructor_specializations
-# -------------------------------------
-# Declare specializations of make_symbol.
-m4_define([b4_symbol_constructor_specializations],
-[b4_variant_if([
- // Specializations of make_symbol for each symbol type.
-m4_map([b4_symbol_constructor_specialization_],
- m4_defn([b4_symbol_numbers]))])dnl
-])
+ // Symbol constructors declarations.
+m4_map([b4_symbol_constructor_declaration_], m4_defn([b4_symbol_numbers]))])])
# b4_symbol_constructor_definition_(SYMBOL-NUMBER)
# ------------------------------------------------
-# Define make_symbol for this SYMBOL-NUMBER.
+# Define symbol constructor for this SYMBOL-NUMBER.
m4_define([b4_symbol_constructor_definition_],
[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id],
-[ template <>
- b4_parser_class_name::symbol_type
- b4_parser_class_name::make_symbol <b4_parser_class_name::token::b4_symbol([$1], [id])> (dnl
+[ b4_parser_class_name::symbol_type
+ b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl
b4_args(b4_symbol_if([$1], [has_type],
[const b4_symbol([$1], [type])& v]),
b4_locations_if([const location_type& l])))
])])])
-# b4_symbol_constructor_declarations
+# b4_symbol_constructor_definitions
# ----------------------------------
# Define the overloaded versions of make_symbol for all the value types.
m4_define([b4_symbol_constructor_definitions],
-[b4_variant_if(
+[[ // 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.
m4_map([b4_symbol_constructor_definition_], m4_defn([b4_symbol_numbers]))])])
# YYTYPE.
m4_define([b4_symbol_variant],
[m4_pushdef([b4_dollar_dollar],
- [$2.$3<$][3>(m4_shift3($@))])dnl
+ [$2.$3< $][3 >(m4_shift3($@))])dnl
switch ($1)
{
m4_map([b4_type_action_], m4_defn([b4_type_names]))[]dnl
])])
+# b4_yytranslate_definition
+# -------------------------
+# Define yytranslate_. Sometimes we want it in the header file,
+# sometimes the cc file suffices.
+m4_define([b4_yytranslate_definition],
+[[ // Symbol number corresponding to token number t.
+ ]b4_parser_class_name[::token_number_type
+ ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type],
+ [int])[ t)
+ {
+ static
+ const token_number_type
+ translate_table[] =
+ {
+]b4_translate[
+ };
+ const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
+ const token_number_type undef_token_ = ]b4_undef_token_number[;
+
+ if (static_cast<int>(t) <= yyeof_)
+ return yyeof_;
+ else if (static_cast<unsigned int> (t) <= user_token_number_max_)
+ return translate_table[t];
+ else
+ return undef_token_;
+ }
+]])
+
+
m4_pushdef([b4_copyright_years],
[2002, 2003, 2004, 2005, 2006, 2007, 2008])
/// Internal symbol numbers.
typedef ]b4_int_type_for([b4_translate])[ token_number_type;
- /* Tables. */
- /// For a state, the index in \a yytable_ of its portion.
- static const ]b4_int_type_for([b4_pact])[ yypact_[];
static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
-
- /// For a state, default rule to reduce.
- /// Unless\a yytable_ specifies something else to do.
- /// Zero means the default is an error.
- static const ]b4_int_type_for([b4_defact])[ yydefact_[];
-
- static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
- static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
-
- /// What to do in a state.
- /// \a yytable_[yypact_[s]]: what to do in state \a s.
- /// - if positive, shift that token.
- /// - if negative, reduce the rule which number is the opposite.
- /// - if zero, do what YYDEFACT says.
- static const ]b4_int_type_for([b4_table])[ yytable_[];
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
- static const ]b4_int_type_for([b4_check])[ yycheck_[];
-
- /// For a state, its accessing symbol.
- static const ]b4_int_type_for([b4_stos])[ yystos_[];
-
- /// For a rule, its LHS.
- static const ]b4_int_type_for([b4_r1])[ yyr1_[];
- /// For a rule, its RHS length.
- static const ]b4_int_type_for([b4_r2])[ yyr2_[];
+ /* Tables. */
+]b4_parser_tables_declare[
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/// For a symbol, its name in clear.
static std::string yytnamerr_ (const char *n);])[
#if YYDEBUG
- /// For each rule, its source line number.
- static const ]b4_int_type_for([b4_rline])[ yyrline_[];
- /// For each scanner token number, its symbol number.
- static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
+]b4_integral_parser_table_declare([rline], [b4_rline],
+ [YYRLINE[YYN] -- Source line where rule number YYN was defined.])[
/// Report on the debug stream that the rule \a r is going to be reduced.
virtual void yy_reduce_print_ (int r);
/// Print the state stack on the debug stream.
#endif
/// 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);
+ static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t);
/// A complete symbol, with its type.
template <typename Exact>
/// Return the type corresponding to this state.
inline int type_get_ () const;
+
+ /// Its token.
+ inline token_type token () const;
};
]b4_symbol_constructor_declarations[
]b4_parse_param_vars[
};
-]b4_symbol_constructor_specializations[
+
+]b4_lex_symbol_if([b4_yytranslate_definition])[
+]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
]b4_namespace_close[
]b4_percent_define_flag_if([[global_tokens_and_yystype]],
| Symbol types. |
`---------------*/
- // 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_symbol_constructor_definitions[
+]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[
// stack_symbol_type.
]b4_parser_class_name[::stack_symbol_type::stack_symbol_type ()
}
- /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
- STATE-NUM. */
const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
- ]b4_table_define([pact], [b4_pact])[;
- /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
- doesn't specify something else to do. Zero means the default is an
- error. */
- ]b4_table_define([defact], [b4_defact])[;
-
- /* YYPGOTO[NTERM-NUM]. */
- ]b4_table_define([pgoto], [b4_pgoto])[;
-
- /* YYDEFGOTO[NTERM-NUM]. */
- ]b4_table_define([defgoto], [b4_defgoto])[;
-
- /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
- positive, shift that token. If negative, reduce the rule which
- number is the opposite. If zero, do what YYDEFACT says. */
const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
- ]b4_table_define([table], [b4_table])[;
-
- /* YYCHECK. */
- ]b4_table_define([check], [b4_check])[;
-
- /* STOS_[STATE-NUM] -- The (internal number of the) accessing
- symbol of state STATE-NUM. */
- ]b4_table_define([stos], [b4_stos])[;
-
-#if YYDEBUG
- /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
- to YYLEX-NUM. */
- ]b4_table_define([token_number], [b4_toknum])[;
-#endif
- /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
- ]b4_table_define([r1], [b4_r1])[;
-
- /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
- ]b4_table_define([r2], [b4_r2])[;
+]b4_parser_tables_define[
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
#endif
#if YYDEBUG
- /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
- ]b4_table_define([rline], [b4_rline])[;
+]b4_integral_parser_table_define([rline], [b4_rline])[
// Print the state stack on the debug stream.
void
}
#endif // YYDEBUG
- /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
- ]b4_parser_class_name[::token_number_type
- ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type],
- [int])[ t)
- {
- static
- const token_number_type
- translate_table[] =
- {
-]b4_translate[
- };
- const unsigned int user_token_number_max_ = ]b4_user_token_number_max[;
- const token_number_type undef_token_ = ]b4_undef_token_number[;
-
- if (static_cast<int>(t) <= yyeof_)
- return yyeof_;
- else if (static_cast<unsigned int> (t) <= user_token_number_max_)
- return translate_table[t];
- else
- return undef_token_;
- }
-
+]b4_lex_symbol_if([], [b4_yytranslate_definition])[
]b4_namespace_close[
]b4_epilogue[]dnl