[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
%parse-param support for lalr1.cc
From: |
Alexandre Duret-Lutz |
Subject: |
%parse-param support for lalr1.cc |
Date: |
Wed, 14 May 2003 17:43:17 +0200 |
User-agent: |
Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3 (gnu/linux) |
Here is a tentative patch to add %parse-param support to lalr1.cc.
The extra parameters are passed to the constructor and stored in
instance variables.
(I mailed my assignment back to the FSF yesterday.)
2003-05-14 Alexandre Duret-Lutz <address@hidden>
%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++.
Index: data/lalr1.cc
===================================================================
RCS file: /cvsroot/bison/bison/data/lalr1.cc,v
retrieving revision 1.31
diff -u -r1.31 lalr1.cc
--- data/lalr1.cc 27 Apr 2003 05:56:34 -0000 1.31
+++ data/lalr1.cc 14 May 2003 15:34:37 -0000
@@ -81,6 +81,39 @@
[])])
+# 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], [,
+ ], address@hidden)])
+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], [
+], address@hidden)])
+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 @@
#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 @@
/* Initial location. */
LocationType initlocation_;
+]b4_parse_param_vars[
};
}
Index: tests/calc.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/calc.at,v
retrieving revision 1.55
diff -u -r1.55 calc.at
--- tests/calc.at 29 Apr 2003 08:41:13 -0000 1.55
+++ tests/calc.at 14 May 2003 15:34:37 -0000
@@ -50,16 +50,16 @@
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 @@
- %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 @@
}
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 @@
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([%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([%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_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([%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}])
--
Alexandre Duret-Lutz
- %parse-param support for lalr1.cc,
Alexandre Duret-Lutz <=