[Top][All Lists]

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

Re: Propagation of prefix change in "yylval" name

From: François PELLEGRINI
Subject: Re: Propagation of prefix change in "yylval" name
Date: Mon, 07 Jun 2010 16:40:43 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100422 Mandriva/3.0.4-0.4mdv2010.0 (2010.0) Thunderbird/3.0.4

Dear M. Denny,

On 04/30/2010 05:01 PM, Joel E. Denny wrote:
On Wed, 28 Apr 2010, François PELLEGRINI wrote:

In order to protect the parser I generate
from collisions with third-party parsers,
I use the "-p" and "-P" options, respectively :

$ bison -pscotchyy -d -v parser_yy.y
$ flex -Pscotchyy parser_ll.l

However, as far as I have seen, I have to
hard-code the changes in the parser code
itself, which in my opinion should not be
the case.

Are you saying you want to be able to change the value of the -p and -P
flags without having to update any code in your .l and .y files?


It seems inconsistent to have bison change the
"yylval" variable to the given prefix (by means
of the "-p" option), while flex does not do it
(when using its "-P" option).

Since both are designed so as to be used together,
setting the same prefix in both should yield the
same results for the symbols they share, e.g. "yylval".

However, in file "parser_ll.l", where
I wrote things such as :

<lstrat>[0-9A-Za-z]         {
                               strncpy (yylval.STRING, yytext, PARSERSTRINGLEN);
                               yylval.STRING[PARSERSTRINGLEN - 1] = '\0';
                               return (METHODNAME);

I have no way to know that "yylval" is
no longer "yylval" but "scotchyylval" too.

Maybe you'd be happier with a pure parser so that scotchyylval is an
argument to yylex rather than a global variable and thus needs no prefix.
Search for "pure parser" in the Bison manual.

Of course, this can be a possibility, but
it is not what I want. I do not want to
re-engineer my software and lose compatibility
with respect to other parsers. I would like flex
and bison to benefit from the added value, in
terms of namespace isolation, of the "-p" and
"-P" options of flex and bison. This is why I
point that their implementation is not consistent :
one changes yylval, while the other does not.

The solution to this would be that, when a "-p"
option is present, flex adds a "#define" line to
the beginning of the "lex.yy.c" file it produces,
so that subsequent uses of the "yylval" variable
are properly renamed.



reply via email to

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