help-bison
[Top][All Lists]
Advanced

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

Re: Name clash with token type BEGIN


From: Luca
Subject: Re: Name clash with token type BEGIN
Date: Thu, 31 Dec 2009 12:41:41 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0

Il 29/12/2009 21.28, Joel E. Denny ha scritto:
On Tue, 29 Dec 2009, August Karlstrom wrote:


Joel E. Denny wrote:

I'm guessing your parser.h is included in a scanner generated by Flex, which
defines the macro BEGIN.

Yes, that's the case. Do you know if there is there a way around this or do I
have to add a prefix to the token (or all tokens for sake of consistency)?

I think you'll have to change the name somehow.

Bison 2.6 should provide api.tokens.prefix to do this automatically, but
it's going to be a while before 2.6 is released.


Obviously, the recommendation in the Bison manual of using the same name for a
reserved words and its corresponding tokens cannot be followed in the general
case when using Flex and Bison in tandem.

I guess Flex is to blame here -
BEGIN should have been named something like YY_BEGIN.

See PREFIX option:
http://flex.sourceforge.net/manual/Code_002dLevel-And-API-Options.html#Code_002dLevel-And-API-Options
but unfortunately I think BEGIN macro isn't affected.

Please remember a TOKEN is only a define, so if you put inside .y file:
%token MY_BEGIN "BEGIN"
error reporting done by yyerror will always print "BEGIN" and not "MY_BEGIN", and you can avoid the conflict.


Maybe there is another workaround (with bison 2.3 or later), you have to try:
you can use the enum yytokentype in your code and manually remove the define
 #define BEGIN someint
from your y.tab.h
or you can undefine BEGIN macro in the definition section of lex (before the first %%) after including y.tab.h:
http://flex.sourceforge.net/manual/Definitions-Section.html#Definitions-Section

for example
#include y.tab.h
#undef BEGIN
%%
"BEGIN" {return 268; //you cannot place BEGIN here cos the preprocessor use the FLEX macro; keep the number updated!}


Luca

I agree.  Of course, we're probably a few decades too late to change the
default Flex behavior, which is inherited from Lex and specified by POSIX.
However, it would be nice if Flex provided an option to avoid namespace
pollution.  (If there's something already, I missed it in the manual.)


_______________________________________________
address@hidden http://lists.gnu.org/mailman/listinfo/help-bison







reply via email to

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