help-bison
[Top][All Lists]
Advanced

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

Re: yyparse() & yyval


From: Hans Aberg
Subject: Re: yyparse() & yyval
Date: Fri, 3 Nov 2000 20:18:38 +0100

At 11.20 -0600 0-11-03, Davy Durham wrote:
>I concur.... I always have to declare a global variable (could cast the int
>returned as a pointer to my parser tree, but that's goofy) and set it in the
>start rule...It's kind of pointless to let you have a pure-parser (for
>thread-safeness or other reasons) but still have to have a global var..

Right. If one wants a pure parser, then one should be able to avoid global
variables altogether; important, especially when the output is to be used
with C++.

>    It seems that $$ of the start rule could go to that extra parameter in
>yyparse he wants...

One variation is that YYACCEPT sets the latest $$ value to the argument of
parse in the use
  YYSTYPE value;
  parse(&value);
The other macros, YYABORT, YYERROR, ... should not set value = $$ (except
possibly for debugging purposes or on special request). Thus if an error of
some sort occurs, "value" is left unchanged.

Perhaps this suffices to many. But the other variation
  YYPARSETYPE pvalue;
  parse(&pvalue);
with an internal (say) $! variable is different, because this is a variable
that can also be used to pass a value _into_ the parser, apart from that
one can use it to only delivering a part of the YYSTYPE value. It is also a
value that is global to all the $-variables; so the $! value can be used if
one builds say a large object which should not be copied and one knows the
order of parsing does not make any difference (even though parser
back-tracking probably will screw this up), or to pass values between the
$-variables.

  Hans Aberg





reply via email to

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