[antlr-interest] ASTs and node types: Java

mzukowski at yci.com mzukowski at yci.com
Mon May 12 07:45:15 PDT 2003


Try generating your code with -traceTreeParser and then figure out what it
is doing.  This doesn't appear to be a type casting problem, rather it looks
like a mis-built tree, from what little information is there about it.

Monty

-----Original Message-----
From: biz_morland [mailto:biz_morland at yahoo.com]
Sent: Saturday, May 10, 2003 3:18 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] ASTs and node types: Java


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/ 


 

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




More information about the antlr-interest mailing list