%parse-param support for lalr1.cc.

* data/lalr1.cc (b4_parse_param_decl, b4_parse_param_cons,
b4_cc_constructor_calls, b4_cc_constructor_call,
b4_parse_param_vars, b4_cc_var_decls, b4_cc_var_decl): New m4
definitions.
(yy::b4_parser_class_name::b4_parser_class_name): Take extra
parse-param arguments.
(yy::b4_parser_class_name): Declare instance variables to
hold parse-param arguments.
* tests/calc.at: s/value/semantic_value/ because value clashes
with a member of yy::b4_parser_class_name.  Adjust C++ code
to handle %parse-param.  Enable %parse-param test in C++.
This commit is contained in:
Alexandre Duret-Lutz
2003-05-14 18:41:48 +00:00
parent 3ab370773d
commit caf37a3666
3 changed files with 66 additions and 16 deletions

View File

@@ -1,3 +1,19 @@
2003-05-14 Alexandre Duret-Lutz <adl@gnu.org>
%parse-param support for lalr1.cc.
* data/lalr1.cc (b4_parse_param_decl, b4_parse_param_cons,
b4_cc_constructor_calls, b4_cc_constructor_call,
b4_parse_param_vars, b4_cc_var_decls, b4_cc_var_decl): New m4
definitions.
(yy::b4_parser_class_name::b4_parser_class_name): Take extra
parse-param arguments.
(yy::b4_parser_class_name): Declare instance variables to
hold parse-param arguments.
* tests/calc.at: s/value/semantic_value/ because value clashes
with a member of yy::b4_parser_class_name. Adjust C++ code
to handle %parse-param. Enable %parse-param test in C++.
2003-05-12 Paul Eggert <eggert@twinsun.com>
* doc/bison.texinfo (How Can I Reset @code{yyparse}): Reword the

View File

@@ -81,6 +81,39 @@ m4_define([b4_constructor],
[])])
# b4_parse_param_decl
# -------------------
# Constructor's extra arguments.
m4_define([b4_parse_param_decl],
[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
# b4_parse_param_cons
# -------------------
# constructor's extra initialisations.
m4_define([b4_parse_param_cons],
[m4_ifset([b4_parse_param],
[,
b4_cc_constructor_calls(b4_parse_param)])])
m4_define([b4_cc_constructor_calls],
[m4_map_sep([b4_cc_constructor_call], [,
], [$@])])
m4_define([b4_cc_constructor_call],
[$2($2)])
# b4_parse_param_vars
# -------------------
# Extra instance variables.
m4_define([b4_parse_param_vars],
[m4_ifset([b4_parse_param],
[
/* User arguments. */
b4_cc_var_decls(b4_parse_param)])])
m4_define([b4_cc_var_decls],
[m4_map_sep([b4_cc_var_decl], [
], [$@])])
m4_define([b4_cc_var_decl],
[ $1;])
# We do want M4 expansion after # for CPP macros.
m4_changecom()
m4_divert(0)dnl
@@ -178,14 +211,14 @@ namespace yy
#if YYLSP_NEEDED
]b4_parser_class_name[ (bool debug,
LocationType initlocation][]b4_param[) :
LocationType initlocation][]b4_param[]b4_parse_param_decl[) :
]b4_constructor[][debug_ (debug),
cdebug_ (std::cerr),
initlocation_ (initlocation)
initlocation_ (initlocation)]b4_parse_param_cons[
#else
]b4_parser_class_name[ (bool debug][]b4_param[) :
]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) :
]b4_constructor[][debug_ (debug),
cdebug_ (std::cerr)
cdebug_ (std::cerr)]b4_parse_param_cons[
#endif
{
}
@@ -274,6 +307,7 @@ namespace yy
/* Initial location. */
LocationType initlocation_;
]b4_parse_param_vars[
};
}

View File

@@ -50,16 +50,16 @@ AT_DATA_GRAMMAR([calc.y],
extern void perror (const char *s);
/* Exercise pre-prologue dependency to %union. */
typedef int value;
typedef int semantic_value;
static value global_result = 0;
static semantic_value global_result = 0;
static int global_count = 0;
%}
/* Exercise %union. */
%union
{
value ival;
semantic_value ival;
};
%{
@@ -69,7 +69,7 @@ static int power (int base, int exponent);
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])
AT_PARAM_IF([value *result, int *count, ])
AT_PARAM_IF([semantic_value *result, int *count, ])
const char *s
);])[
static int yylex (]AT_LEX_FORMALS[);
@@ -139,15 +139,15 @@ yy::Parser::error_ ()
}
int
yyparse (void)
yyparse (AT_PARAM_IF([semantic_value *result, int *count]))
{
yy::Parser parser (!!YYDEBUG[]AT_LOCATION_IF([, yy::Location::Location ()]));
yy::Parser parser (!!YYDEBUG[]AT_LOCATION_IF([, yy::Location::Location ()])AT_PARAM_IF([, result, count]));
return parser.parse ();
}
],
[static void
yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])
AT_PARAM_IF([value *result, int *count, ])
AT_PARAM_IF([semantic_value *result, int *count, ])
const char *s)
{
AT_PARAM_IF([(void) result; (void) count;])
@@ -299,7 +299,7 @@ power (int base, int exponent)
int
main (int argc, const char **argv)
{
value result = 0;
semantic_value result = 0;
int count = 0;
int status;
@@ -546,7 +546,7 @@ AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix="calc
AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])
AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}])
AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
# ----------------------- #
@@ -582,7 +582,7 @@ AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix="calc"
AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])
AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}])
AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
# ----------------------------- #
@@ -594,7 +594,7 @@ AT_BANNER([[Simple LALR1 C++ Calculator.]])
# AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS])
# ---------------------------------------
# Start a testing chunk which compiles `calc' grammar with
# BISON-OPTIONS and %glr-parser, and performs several tests over the parser.
# the C++ skeleton, and performs several tests over the parser.
m4_define([AT_CHECK_CALC_LALR1_CC],
[AT_CHECK_CALC([%skeleton "lalr1.cc"] $@)])
@@ -619,4 +619,4 @@ AT_CHECK_CALC_LALR1_CC([%error-verbose %debug %locations %defines %name-prefix="
AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])
# AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}])
AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])