help-bison
[Top][All Lists]
Advanced

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

Re: Token redefinition


From: Bob Smith
Subject: Re: Token redefinition
Date: Fri, 17 Nov 2006 09:20:08 -0500
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)

On 11/17/2006 5:52 AM, Hans Aberg wrote:
On 17 Nov 2006, at 10:05, Tim Van Holder wrote:

I need to write a simple compiler for a pascal-like linguage, using
flex and bison.
The language uses token as "INT" "BOOL" or "FALSE"; when I compile the
project using
Visual Studio 6.0 the following message is displayed:

"'BOOL' : redefinition; typedef cannot be overloaded with any other
symbol"

This is because in windef.h they are other defines of tokens "INT"
"BOOL" or "FALSE".
How can I resolve the question WITHOUT change the names of the tokens ??

You can switch to a different platform.

Or, as a more constructive suggestion, you could use a prefix for the
token names in the grammar (T_BOOL, tBool, tokBOOL, etc. are all viable
alternatives).  And you can always give them string names you use in the
grammar:

grammar:   %token t_BOOL "BOOL"
lexer:     "BOOL" { return t_BOOL; }
grammar:   some_rule: some_other_rule "BOOL";

which ensures that bison syntax errors say they expect a BOOL rather
than a t_BOOL (only the lexer has to use the t_* names). This is
especially nice when the name for the token consists of multiple words:

%token t_DECIMAL_LITERAL "decimal literal"

You probably did not read the OP, who wants the macro names unchanged! The question seems to be how to avoid name clashes without changing their names. :-)

How about #undef BOOL, etc.?

--
_______________________________________________________________
Bob Smith - address@hidden - http://www.sudleyplace.com

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


reply via email to

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