On Tue, Sep 26, 2006 at 10:28:15AM -0700, Paul Eggert wrote:
> That looks good. Some minor comments:
>
> The usual style is to give local variables lower-case names.
> The patch uses upper-caes names for local vars, which looks a bit strange.
>
> > +]b4_locations_if([status = yypushparse (ctx, ch, &yylval, &yylloc);],
> > + [status = yypushparse (ctx, ch, &yylval);])[
>
> This won't be indented well, and has duplicate code. The usual style is:
>
> status = yypushparse (ctx, ch, &yylval]b4_locations_if([, &yylloc])[);
OK, here's another shot at it. Thanks for the suggestions. How is the
interface coming along? Do you see any other modifications that should
take place?
{
struct yypvars *ctx = yypvarsinit ();
int status, ch;
do {
ch = yylex ();
status = yypushparse (ctx, ch, &yylval, &yylloc);
} while (status == YYPUSH_MORE);
free (ctx);
return status;
}
One potential problem that I can think of is that the push parser still
allows the user to use the global variables yylval and yylloc. The push
parser also has it's own version of these variables in the yypvars
struct. I don't know if it's a good thing or a bad thing that we still
use the global variables. At a minimum, it will allow users to not have
to modify there lexers. What do you think?
The push parser should also work under multiple contexts (ie
aapushparse, bbpushparse). Can you think of a reason it currently
wouldn't?
Thanks,
Bob Rossi
2006-09-27 Bob Rossi <[EMAIL PROTECTED]>
* data/push.c (yychar_set, yylval_set, yylloc_set): Delete.
(yypushparse): Add YYPVARS, YYLVAL, YYLLOC parameters.
Use new parameters to setup ypvars structure.
(yypvarsinit): Add b4_locations_if around init code.
(yyparse): Modify user interface.
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.3
diff -u -r1.3 push.c
--- data/push.c 21 Sep 2006 17:45:21 -0000 1.3
+++ data/push.c 27 Sep 2006 13:28:10 -0000
@@ -161,11 +161,7 @@
#define yychar b4_prefix[]char
#define yydebug b4_prefix[]debug
#define yynerrs b4_prefix[]nerrs
-b4_locations_if([#define yylloc b4_prefix[]lloc])
-b4_push_if([
-#define yychar_set b4_prefix[]char_set
-#define yylval_set b4_prefix[]lval_set
-#define yylloc_set b4_prefix[]lloc_set])])[
+b4_locations_if([#define yylloc b4_prefix[]lloc])])[
/* Copy the first part of user declarations. */
]b4_pre_prologue[
@@ -974,14 +970,12 @@
]b4_push_if([
struct yypvars;
enum { YYPUSH_MORE = 4 };
-]b4_c_function_decl([yychar_set], [void], [[struct yypvars *YYPVARS],
[YYPVARS]], [[int yychar], [yychar]])[
-]b4_c_function_decl([yylval_set], [void], [[struct yypvars *YYPVARS],
[YYPVARS]], [[YYSTYPE yylval], [yylval]])[
-#ifdef YYLTYPE_IS_TRIVIAL
-]b4_c_function_decl([yylloc_set], [void], [[struct yypvars *YYPVARS],
[YYPVARS]], [[YYLTYPE yylloc], [yylloc]])[
-#endif
]b4_c_function_decl([yypvarsinit], [void *], [[void], []])[
]b4_c_function_decl([yypushparse], [int],
- [[struct yypvars *YYPVARS], [YYPVARS]])[
+ [[struct yypvars *YYPVARS], [YYPVARS]],
+ [[int YYCHAR], [YYCHAR]],
+ [[YYSTYPE *YYLVAL], [YYLVAL]]
+ b4_locations_if([,[[YYLTYPE *YYLLOC], [YYLLOC]]]))[
])[
]m4_divert_push([KILL])# ======================== M4 code.
@@ -1087,41 +1081,20 @@
pv->yyssp = pv->yyss;
pv->yyvsp = pv->yyvs;
+]b4_locations_if([
#if YYLTYPE_IS_TRIVIAL
/* Initialize the default location before parsing starts. */
pv->yylloc.first_line = pv->yylloc.last_line =
]b4_location_initial_line[;
pv->yylloc.first_column = pv->yylloc.last_column =
]b4_location_initial_column[;
#endif
+])[
pv->yynew = 1;
]b4_locations_if([ pv->yylsp = pv->yyls;])[
return (void *) pv;
-}
-
-void
-yychar_set (struct yypvars *YYPVARS, int yychar)
-{
- if (YYPVARS)
- YYPVARS->yychar = yychar;
-}
-
-void
-yylval_set (struct yypvars *YYPVARS, YYSTYPE yylval)
-{
- if (YYPVARS)
- YYPVARS->yylval = yylval;
-}
-
-#ifdef YYLTYPE_IS_TRIVIAL
-void
-yylloc_set (struct yypvars *YYPVARS, YYLTYPE yylloc)
-{
- if (YYPVARS)
- YYPVARS->yylloc = yylloc;
-}
-#endif])
+}])
m4_divert_pop([KILL])dnl# ====================== End of M4 code.
b4_pure_if([],
@@ -1134,7 +1107,10 @@
`-------------------------*/
b4_push_if([
-b4_c_function_def([yypushparse], [int], [[struct yypvars *YYPVARS],
[YYPVARS]])],[
+b4_c_function_def([yypushparse], [int], [[struct yypvars *YYPVARS],
[YYPVARS]],
+ [[int YYCHAR], [YYCHAR]],
+ [[YYSTYPE *YYLVAL], [YYLVAL]]
+ b4_locations_if([,[[YYLTYPE *YYLLOC],
[YYLLOC]]]))],[
#ifdef YYPARSE_PARAM
b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
#else /* ! YYPARSE_PARAM */
@@ -1202,7 +1178,13 @@
YYDPRINTF ((stderr, "Starting parse\n"));
- ]b4_push_if([pv = YYPVARS;])[
+ ]b4_push_if([pv = YYPVARS;
+ pv->yychar = YYCHAR;
+ if (YYLVAL)
+ pv->yylval = *YYLVAL;
+ ]b4_locations_if([
+ if (YYLLOC)
+ pv->yylloc = *YYLLOC;]))[
yystate = 0;
yyerrstatus = 0;
@@ -1722,17 +1704,14 @@
{[
struct yypvars *ctx = yypvarsinit ();
int status;
+ int ch;
do {
- yychar_set (ctx, yylex ());
- yylval_set (ctx, yylval);
-#ifdef YYLTYPE_IS_TRIVIAL
- yylloc_set (ctx, yylloc);
-#endif
- status = yypushparse (ctx);
+ ch = yylex ();
+ status = yypushparse (ctx, ch, &yylval]b4_locations_if([, &yylloc])[);]
} while (status == YYPUSH_MORE);
free (ctx);
return status;
-]}])
+}])
b4_epilogue