[antlr-interest] rule names collision with reserved words in target language

Jim Idle jimi at temporal-wave.com
Sat Oct 11 18:30:41 PDT 2008


On Sat, 2008-10-11 at 23:54 +0200, Johannes Luber wrote:

> Magnus Danielson schrieb:
> > Hi!
> > 
> > As I was working on a project I had a bug that took some time to figure 
> > out. It crashed and burned as I compiled it. The trouble was that I hade 
> > a rule named const in my grammar, and producting a routine called const 
> > in the produced C code. Now, const is a reserved word so GCC spewed 
> > severly upon it.
> > 
> > If I had used prefixing it would have solved itself. Renaming it solved 
> > it, but you would rather want either a warning/error occur up in the 
> > ANTLR front or a backend renaming to occur to avoid it, if needed (i.e. 
> > if reserved for the target language and no prefixing is used).
> > 
> > I think this problem can occur with other languages than C, so it could 
> > be worth considering. Oh, I was using 3.0.1 if you where asking.
> 
> This problem is known, but until name mangling is implemented not much
> can be done. ANTLR is largely language agnostic and doesn't know if a
> rule has the same name as a reserved word. Maybe putting a warning on
> the wiki to that effect.


Because one of the goals is to generate somewhat readable/decipherable
code, this name mangling won't be done. Once the generated code is in an
IDE you want to be able to navigate to the tokens and rules and so on.
It is a minor restriction that you cannot use the names of built-ins and
keywords and so on.

Jim


> 
> Johannes
> > 
> > Cheers,
> > Magnus
> > 
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> > 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081011/3367731d/attachment.html 


More information about the antlr-interest mailing list