[antlr-interest] ClassCastException with custom node type

Ale Strooisma alestrooisma at gmx.net
Wed Jul 4 11:52:14 PDT 2012


Hello,

I get this error:
java.lang.ClassCastException: org.antlr.runtime.tree.CommonTree cannot 
be cast to wc.util.ASTNode
     at wc.compiler.WcChecker.expr(WcChecker.java:1290)
     at wc.compiler.WcChecker.statement(WcChecker.java:928)
     at 
wc.compiler.WcChecker.nonOpeningCompoundStatement(WcChecker.java:814)
     at wc.compiler.WcChecker.function(WcChecker.java:755)
     at wc.compiler.WcChecker.program(WcChecker.java:289)
     at wc.Driver.compile(Driver.java:95)
     at wc.Driver.main(Driver.java:67)
on the line: t=(ASTNode)match(input,BECOMES,FOLLOW_BECOMES_in_expr445);

I created a node and errornode class and an factory for it. The weird 
thing is that when I replace the line with:

Object ct = match(input,BECOMES,FOLLOW_BECOMES_in_expr445);
System.out.println(ct.getClass());
t=(ASTNode)ct;

then, with a certain test-file first two times the type 
"wc.util.ASTNode" is outputted, and after that 
"org.antlr.runtime.tree.CommonTree".

Please help,
Ale


More information about the antlr-interest mailing list