bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: push parser


From: Paul Eggert
Subject: Re: push parser
Date: Wed, 27 Sep 2006 11:42:36 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Bob Rossi <address@hidden> writes:

> Well, this is what is happening. Either the user is using there own 
> version of the yylval and yylloc, or they are using the global vars
> that are provided. Either way, when they call yypushparse, it copies
> that data into ctx. yypushparse then uses the data in ctx. The first
> thing the yypushparse function does is copy the ctx variables to the
> global and local variables in the function, so that yypushparse can
> operate on the local/global variables and not know anything about the 
> ctx.

"global and local variables in the function"?  I thought that
push parsers were always pure, so that there was no need for
global variables.

If yypushparse simply copies context to local vars, then perhaps
we should remove lval and lloc info from the context, and stick
with something like this interface:

 {
   struct yypvars *ctx = yypvarsinit ();
   int status;
   do {
     YYSTYPE my_lval;
     YYLTYPE my_lloc;
     status = yypushparse (ctx, my_lex (&my_lval, &my_lloc),
                           &my_lval, &my_lloc);
   } while (status == YYPUSH_MORE);
   free (ctx);
   return status;
 }

Or perhaps we want to simplify it a bit, as follows:

 {
   struct yypvars *ctx = yypvarsinit ();
   int status;
   do {
     YYTOKTYPE token_info;
     status = yypushparse (ctx, my_lex (&token_info), &token_info);
   } while (status == YYPUSH_MORE);
   free (ctx);
   return status;
 }

where YYTOKTYPE is defined to be a structure containing a YYSTYPE (and
an YYLTYPE, if locations are used).

Then, when yypushparse starts up, it can (if it likes) copy my_lexinfo
to its local vars.  But I don't see why it would bother; it can simply
use the address it's passed, and not make copies of the variable in
question.

> So, the question is, should we include these 2 particular variables in
> the ctx, or assume the user is responsible for storing and using this
> data, along with passing it into the yypushparse function?

I'd say the latter.

> Does the
> parser modify either of these variables?

No, just as it doesn't modify yylloc or yylval.

> Not to be totally annoying, but the variables 'int yychar;', and 
> 'int yynerrs' also fall under this same category. That is, they are
> both declared global and in the ctx.

They shouldn't be global, surely.  I thought this stuff was supposed
to be reentrant.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]