On Mon, Sep 25, 2006 at 11:15:50PM -0700, Paul Eggert wrote:
> Bob Rossi <[EMAIL PROTECTED]> writes:
>
> >> I have a small patch that get's me this far:
> >> status = yypushparse (ctx, ch, &yylval);
> >>
> >> What should I do about yylval?
>
> Sorry, I don't understand the question; perhaps you meant yyloc?
Wow, I must have been having a bad day. Yes, I did mean yyloc.
> >> I can attempt to make yypushparse have an extra parameter when locations
> >> are enabled. Does that sound correct?
>
> Yes, that sounds fine.
OK, great.
> > Here, is a patch I'm posting just for you to tell me if this is the
> > appropriate solution.
>
> Sorry, I'm a bit lost. That patch modifies yacc.c and puts a bunch of
> push-parser stuff in it; but yacc.c differs from push.c afterwards.
> Is this intended? I thought the patch would just affect push.c.
Again, sorry. I only meant to send a patch to push.c in. I 'cp push.c
yacc.c' when I run the testsuite, to make sure that nothing regressed.
> The push.c patch looks OK, except there still seems to be some
> confusion about YYLTYPE_IS_TRIVIAL versus b4_locations_if.
> YYLTYPE_IS_TRIVIAL is defined if it is known that YYLTYPE is a trivial
> type (in the C++ sense: it's just a bunch of bytes). But in the patch
> YYLTYPE_IS_TRIVIAL seems to be used for some other purpose.
Yes, I knew I was still doing this. I am going to do this the correct
way once I understand what that is. I think I finally get it now. If
locations are being used, then yylloc is available? I was using
YYLTYPE_IS_TRIVIAL for that :(.
Here is another posting of the patch, if you like how it looks I'll
resend with ChangeLog.
Thanks,
Bob Rossi
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 26 Sep 2006 13:06:09 -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,13 +1704,11 @@
{[
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 ();
+]b4_locations_if([status = yypushparse (ctx, ch, &yylval, &yylloc);],
+ [status = yypushparse (ctx, ch, &yylval);])[
} while (status == YYPUSH_MORE);
free (ctx);
return status;