[antlr-interest] Custom AST Types
Robert Colquhoun
rjc at trump.net.au
Wed Jun 11 19:25:47 PDT 2003
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/
More information about the antlr-interest
mailing list