[antlr-interest] [C target] #define clashes: would itbe possible to add ANTLR_ prefix to automatically generated macros?

Martin Hans mah at oticon.dk
Mon Aug 4 23:45:20 PDT 2008


Hi,

I think ANTLR could be more helpful than it is in this situation, simply
by issuing an clear error message if the grammar uses a reserved word.
It took me a while to figure out that "match" is reserved when using the
python target because the parser base class uses that method name for
something else. Without the error message we are left to debugging the
name clashes from obscure syntax errors or parsers that don't work as
expected.

 

As a newbie this was the largest hurdle in getting started with ANTLR.

 

Martin 

 

________________________________

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Saturday, August 02, 2008 2:07 AM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] [C target] #define clashes: would itbe
possible to add ANTLR_ prefix to automatically generated macros?

 

On Fri, 2008-08-01 at 16:05 -0700, Dinghao Wu wrote: 

 
It is similar for ANTLR generated code for grammar rules. Once I had
rules called "null" and "string". The generated C# code clashes. I think
the generated code should add some prefix so that it won't generate a
method called null() or string().


Basically you just don't use keywords in the target language. There is
no way to completely guarantee that things won't clash, even
ANTLR_TOKEN_ and so on. But when you prefix them then you lose the
readability of the source code when debugging. It's obvious what is
happening and easier to change your rule and token names IMO.

Jim 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080805/03baafc8/attachment.html 


More information about the antlr-interest mailing list