[antlr-interest] Minor suggestion re. Java output

Johannes Luber jaluber at gmx.de
Sun Feb 3 14:24:15 PST 2008


Guntis Ozols schrieb:
>> A tree is not guaranteed to be any particular type or interface as the
>> tree adaptor can produce anything it likes. Hence it must be an object.
>> This is explained in the code etc.
>>
>> Jim
> 
> Casting tree once is not that big of a deal, but tons of casting could be
> eliminated, plus there is no need for an option, if CommonTree.getChild()
> returned CommonTree.
> 
> Covariant return types are available since java 1.5 (Sept 2004).

The Java target remains for the foreseeable future 1.4. I haven't looked 
if C# allows this, too, but it would be possible to use templates and 
specify the template parameter so that it uses the ASTLabelType value.

> Also, how about using enum for tokens? It would free client code of prefixes in
> switch statements, plus toString() would be available and more.

Could do that only for C#, but for Java you are out of luck. As long 
people use 1.4 for projects, ANTLR can't easily move. I have that 
problem with the C# target, though I'm quite sure that no one uses C# 1 
in combination with ANTLR.

Johannes


More information about the antlr-interest mailing list