[antlr-interest] Custom AST Types
Terence Parr
parrt at jguru.com
Thu Jun 12 09:41:07 PDT 2003
Hi Robert. Can u summarize the basic problem in the code for me?
Thanks,
Ter
On Thursday, June 12, 2003, at 08:05 AM, Robert Colquhoun wrote:
> Hello,
>
> Following up my own post, i have a patch of antlr-2.7.2 which fixes the
> problem:
> http://www.trump.net.au/~rjc/antlr/
> It(customast.diff) was a one line patch to JavaCodeGenerator.java, the
> 2nd
> solution outlined below was used, possibly the same problem is in the
> C++
> and C# generators, but it is late and i couldn't be bothered checking
> ;-)
>
> Also at the bottom of the page is a compiled antlr.jar which has the 3
> listed patches on the page.
>
> - Robert
>
> At 12:25 PM 12/06/2003 +1000, Robert Colquhoun wrote:
>> Hi Everyone,
>>
>> Is anyone else having problems in tree walkers using custom AST types
>> in
>> conjunction with protected rules?
>>
>> I get ClassCastExceptions whenever the rule tries to match nothing ie
>> ASTNULL
>>
>> ie
>>
>> options{
>> ASTLabelType=MyAST;
>> }
>> ....
>> protected elsest: (#(ELSE statementblock))?
>>
>> The code generated has something like:
>>
>> protected final void elsest(antlr.collections.AST _t) throws
>> antlr.RecognitionException {
>>
>> MyAST elsest_AST_in = (MyAST)_t; //<---ClassCastException here!
>> .....
>>
>> What appears to happen is that the elsest() rule is called passing
>> ASTNULL
>> when there is no else clause as part of a if/then/else statement and
>> it
>> trys to cast ASTNULL to MyAST type which breaks things.
>>
>> To fix
>> - either somehow change ASTNULL to be of MyAST type.
>> - as in other parts of generated code use something like:
>> MyAST elsest_AST_in = (_t == ASTNULL) ? null :
>> (MyAST)_t;
>>
>> Both require changes to antlr to solve though, otherwise i can hack my
>> grammar to work around this i think.....just want to know if it is
>> affecting other people at all, and thus whether i should fix antlr?
>>
>> - Robert
>>
>>
>>
>>
>> Your use of Yahoo! Groups is subject to
>> http://docs.yahoo.com/info/terms/
>
>
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Co-founder, http://www.peerscope.com link sharing, pure-n-simple
Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list