[antlr-interest] ASTs and node types: Java

biz_morland biz_morland at yahoo.com
Sat May 10 15:18:11 PDT 2003


Hi,

I'm writing a java program that uses an Antlr grammar file to build 
and traverse an AST. Beforehand my Main.java and expression.g had 
worked well with an AST of nodes each of which consisted of a number 
of type double.

In Main.java I had used the following command to create an AST and 
traverse it, printing the result:

CommonAST parseTree = (CommonAST)parser.getAST();
System.out.println(parseTree.toStringList());
ExpressionTreeWalker walker = new ExpressionTreeWalker();
Double result = walker.expr(parseTree);
System.out.println("Value: "+result);

OK, now I need an AST whose nodes are of type java.lang.Object 
instead of double. However I keep getting the following error message 
from the walker.expr(parseTree) statement.

For an example tree: +( 1 1)
Error message:

<snip>
<AST>: unexpected AST node: 1
<AST>: unexpected AST node: 1
Exception: java.lang.NullPointerException
</snip>

The most obvious solution to me would be to somehow typecast the 
walker.expr() statement to java.lang.Object, but I've tried this in 
many different ways resulting in the same error msg above.

Is there anyone who has had similar error messages or problems with 
building ASTs, where the nodes have had to be changed or cast to 
different types?

Thanks,
Greg


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list