On Fri, Sep 29, 2006 at 09:42:37AM -0400, Bob Rossi wrote:
> On Wed, Sep 27, 2006 at 04:30:43PM -0700, Paul Eggert wrote:
> > Bob Rossi <[EMAIL PROTECTED]> writes:
> > 
> > > There are no need for global variables, you are correct. The patch I
> > > originally made simply did not do away with the 4 global variables that
> > > the user traditionally used. I was a afraid this would break backwards
> > > compatibility for many users.
> > 
> > OK, but we shouldn't need to worry about doing away with global
> > variables in push parsers, since they're supposed to be pure.  We need
> > to keep globals only for traditional, impure parsers.
> 
> OK, agreed. There are 4 globals of interest. 
>   int yychar;
>   YYSTYPE yylval;
>   int yynerrs;
>   YYLTYPE yylloc;
> I know what to do with yylval and yylloc. That's because we have the
> user declare them and pass them into the parser. I also know what to
> do with yychar, because the user also passes that data into the parser.
> What should I do with yynerrs?

Still wondering what to do with yynerrs. I simply made it a local
variable for now, and do not have the user pass it in. What do you think
of this patch for the other 3 variables?

One issue I had is, now the yyparse function (which calls yypushparse) 
depends on yylex to take 2 parameters. This breaks the small test I have
that is not in the test suite because my yylex takes nothing. Should we
force the user to have yylex take these parameters? or should we somehow
modify yyparse ()?

Now that I have run into this problem, I see this would have been a
problem in the reverse direction also. That is, it currently calls
yylex() and the user could have a different parameter profile for there
yylex ().

Thanks,
Bob Rossi

2006-09-29  Bob Rossi  <[EMAIL PROTECTED]>

        * data/push.c (yychar_set, yylval_set, yylloc_set): Delete.
        (yypushparse): Add yynchar, yynlval, yynlloc parameters.
        (struct yypvars): Remove b4_declare_parser_variables.
        (yypvarsinit): Remove init code for removed variables.
        (global scope): Do not declare b4_declare_parser_variables if
        push or pure mode.
        (yypushparse): Add b4_declare_parser_variables.
        Init new local variables, and remove init code for removed
        yypvars variables.
        (yyparse): Add local variables to pass to yypushparse.
        * tests/local.at (AT_PURE_IF): Rename to AT_PURE_OR_PUSH_IF and
        modify accordingly.
        (AT_PURE_AND_LOC_IF): Rename to AT_PURE_OR_PUSH_AND_LOC_IF and
        modify accordingly.
        (AT_YYERROR_ARG_LOC_IF): Use AT_PURE_OR_PUSH_AND_LOC_IF.
        (AT_YYERROR_SEES_LOC_IF): Use AT_PURE_OR_PUSH_IF.
        (AT_PURE_LEX_IF): Use AT_PURE_OR_PUSH_IF.
Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1571
diff -u -r1.1571 ChangeLog
--- ChangeLog   21 Sep 2006 17:45:21 -0000      1.1571
+++ ChangeLog   29 Sep 2006 14:51:15 -0000
@@ -1,3 +1,16 @@
+2006-09-29  Bob Rossi  <[EMAIL PROTECTED]>
+
+       * data/push.c (yychar_set, yylval_set, yylloc_set): Delete.
+       (yypushparse): Add yynchar, yynlval, yynlloc parameters.
+       (struct yypvars): Remove b4_declare_parser_variables.
+       (yypvarsinit): Remove init code for removed variables.
+       (global scope): Do not declare b4_declare_parser_variables if 
+       push or pure mode.
+       (yypushparse): Add b4_declare_parser_variables.
+       Init new local variables, and remove init code for removed
+       yypvars variables.
+       (yyparse): Add local variables to pass to yypushparse.
+
 2006-09-21  Paul Eggert  <[EMAIL PROTECTED]>
 
        * data/push.c (YYPUSH_MORE): Make it an enum instead.
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 29 Sep 2006 14:51:16 -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 yynchar], [yynchar]],
+   [[YYSTYPE *yynlval], [yynlval]]
+   b4_locations_if([,[[YYLTYPE *yynlloc], [yynlloc]]]))[
 ])[
 
 ]m4_divert_push([KILL])# ======================== M4 code.
@@ -1008,7 +1002,6 @@
 m4_define([b4_declare_yyparse_variables],
 [[struct yypvars
   {
-]]b4_declare_parser_variables[[
     int yystate;
     int yyn;
     int yyresult;
@@ -1087,45 +1080,16 @@
   pv->yyssp = pv->yyss;
   pv->yyvsp = pv->yyvs;
 
-#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([],
-          [b4_declare_parser_variables])
+b4_push_if([],[b4_pure_if([],
+          [b4_declare_parser_variables])])
 
 b4_push_if([b4_declare_yyparse_variables])
 
@@ -1134,7 +1098,9 @@
 `-------------------------*/
 
 b4_push_if([
-b4_c_function_def([yypushparse], [int], [[struct yypvars *YYPVARS], 
[YYPVARS]])],[
+b4_c_function_def([yypushparse], [int], [[struct yypvars *yypvars], 
[yypvars]], 
+                  [[int yynchar], [yynchar]], [[YYSTYPE *yynlval], [yynlval]]
+                 b4_locations_if([,[[YYLTYPE *yynlloc], [yynlloc]]]))],[
 #ifdef YYPARSE_PARAM
 b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
 #else /* ! YYPARSE_PARAM */
@@ -1142,6 +1108,7 @@
 #endif])
 {[
   ]b4_pure_if([b4_declare_parser_variables])[
+  ]b4_push_if([b4_declare_parser_variables])[
   ]b4_push_if([struct yypvars *pv;])[
   int yystate;
   int yyn;
@@ -1202,12 +1169,15 @@
 
   YYDPRINTF ((stderr, "Starting parse\n"));
 
-  ]b4_push_if([pv = YYPVARS;])[
-
   yystate = 0;
   yyerrstatus = 0;
   yynerrs = 0;
-  yychar = YYEMPTY;            /* Cause a token to be read.  */
+]b4_push_if([  yychar = yynchar;
+  pv = yypvars;
+  if (yynlval)
+    yylval = *yynlval;
+]b4_locations_if([  if (yynlloc)
+     yylloc = *yynlloc;])[],[yychar = YYEMPTY; /* Cause a token to be read.  
*/])[
 
   /* Initialize stack pointers.
      Waste one element of value and location stack
@@ -1237,12 +1207,6 @@
 ]])dnl
 [  ]b4_push_if([
        /* Initialize the locals to the current context. */
-       yychar = pv->yychar;
-       yylval = pv->yylval;
-       yynerrs = pv->yynerrs;
-       ]b4_locations_if([
-       yylloc = pv->yylloc;])[
-
        yystate = pv->yystate;
        yyn = pv->yyn;
        yyresult = pv->yyresult;
@@ -1382,12 +1346,6 @@
        YYDPRINTF ((stderr, "Return for a new token:\n"));
        yyresult = YYPUSH_MORE;
        /* Initialize the locals to the current context. */
-       pv->yychar = yychar;
-       pv->yylval = yylval;
-       pv->yynerrs = yynerrs;
-       ]b4_locations_if([
-       pv->yylloc = yylloc;])[
-
        pv->yystate = yystate;
        pv->yyn = yyn;
        pv->yyresult = yyresult;
@@ -1721,18 +1679,15 @@
 #endif
 {[
   struct yypvars *ctx = yypvarsinit ();
-  int status;
+  int status, ch;
+  YYSTYPE my_lval;
+  ]b4_locations_if([YYLTYPE my_lloc;])[
   do {
-    yychar_set (ctx, yylex ());
-    yylval_set (ctx, yylval);
-#ifdef YYLTYPE_IS_TRIVIAL
-    yylloc_set (ctx, yylloc);
-#endif
-    status = yypushparse (ctx);
+    status = yypushparse (ctx, yylex (&my_lval]b4_locations_if([, 
&my_lloc])[), &my_lval]b4_locations_if([, &my_lloc])[);]
   } while (status == YYPUSH_MORE);
   free (ctx);
   return status;
-]}])
+}])
 
 
 b4_epilogue
Index: tests/local.at
===================================================================
RCS file: /sources/bison/bison/tests/local.at,v
retrieving revision 1.16
diff -u -r1.16 local.at
--- tests/local.at      12 Mar 2006 15:26:05 -0000      1.16
+++ tests/local.at      29 Sep 2006 14:51:16 -0000
@@ -56,10 +56,10 @@
 [m4_bmatch([$3], [%parse-param], [$1], [$2])])
 m4_pushdef([AT_LOCATION_IF],
 [m4_bmatch([$3], [%locations], [$1], [$2])])
-m4_pushdef([AT_PURE_IF],
-[m4_bmatch([$3], [%pure-parser], [$1], [$2])])
-m4_pushdef([AT_PURE_AND_LOC_IF],
-[m4_bmatch([$3], [%locations.*%pure-parser\|%pure-parser.*%locations],
+m4_pushdef([AT_PURE_OR_PUSH_IF],
+[m4_bmatch([$3], [%pure-parser\|%push-parser], [$1], [$2])])
+m4_pushdef([AT_PURE_OR_PUSH_AND_LOC_IF],
+[m4_bmatch([$3], 
[%locations.*%pure-parser\|%pure-parser.*%locations\|%locations.*%push-parser\|%push-parser.*%locations],
           [$1], [$2])])
 m4_pushdef([AT_GLR_OR_PARAM_IF],
 [m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])])
@@ -69,12 +69,12 @@
            [yy])])
 # yyerror receives the location if %location & %pure & (%glr or %parse-param).
 m4_pushdef([AT_YYERROR_ARG_LOC_IF],
-[AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])],
+[AT_GLR_OR_PARAM_IF([AT_PURE_OR_PUSH_AND_LOC_IF([$1], [$2])],
                    [$2])])
 # yyerror always sees the locations (when activated), except if
 # yacc & pure & !param.
 m4_pushdef([AT_YYERROR_SEES_LOC_IF],
-[AT_LOCATION_IF([AT_YACC_IF([AT_PURE_IF([AT_PARAM_IF([$1], [$2])],
+[AT_LOCATION_IF([AT_YACC_IF([AT_PURE_OR_PUSH_IF([AT_PARAM_IF([$1], [$2])],
                                        [$1])],
                            [$1])],
                [$2])])
@@ -82,7 +82,7 @@
 # The interface is pure: either because %pure-parser, or because we
 # are using the C++ parsers.
 m4_pushdef([AT_PURE_LEX_IF],
-[AT_PURE_IF([$1],
+[AT_PURE_OR_PUSH_IF([$1],
            [AT_SKEL_CC_IF([$1], [$2])])])
 
 AT_PURE_LEX_IF(
@@ -125,7 +125,7 @@
 m4_popdef([AT_YYERROR_ARG_LOC_IF])
 m4_popdef([AT_NAME_PREFIX])
 m4_popdef([AT_GLR_OR_PARAM_IF])
-m4_popdef([AT_PURE_AND_LOC_IF])
+m4_popdef([AT_PURE_OR_PUSH_AND_LOC_IF])
 m4_popdef([AT_LOCATION_IF])
 m4_popdef([AT_PARAM_IF])
 m4_popdef([AT_YACC_IF])

Reply via email to