m4_include(b4_pkgdatadir/[c++.m4])
-# b4_subtract(LHS, RHS)
-# ---------------------
-# Evaluate LHS - RHS if they are integer literals, otherwise expand
-# to (LHS) - (RHS).
-m4_define([b4_subtract],
-[m4_bmatch([$1$2], [^[0123456789]*$],
- [m4_eval([$1 - $2])],
- [($1) - ($2)])])
-
-
-# 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
[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_constructor_declarations
-# ----------------------------------
-# Declare the overloaded versions of make_symbol 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
+[ 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_specializations
-# -------------------------------------
-# Declare specializations of make_symbol.
-m4_define([b4_symbol_constructor_specializations],
+
+# b4_symbol_constructor_declarations
+# ----------------------------------
+# Declare symbol constructors for all the value types.
+# Use at class-level.
+m4_define([b4_symbol_constructor_declarations],
[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])))
# 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
/// 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_[];
+]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.
};
]b4_lex_symbol_if([b4_yytranslate_definition])[
-]b4_symbol_constructor_specializations[
]b4_lex_symbol_if([b4_symbol_constructor_definitions])[
]b4_namespace_close[
}
- /* 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])[;
-
- /* 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