mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 21:03:04 +00:00
%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:
@@ -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}])
|
||||
|
||||
Reference in New Issue
Block a user