[antlr-interest] How does AST construction work?
Martin Probst
mail at martin-probst.com
Tue May 17 16:14:07 PDT 2005
Hi,
> I tried this, and the returned tree just contains '2':
maybe your just running into ANTLRs sibling pointered trees?
Try this code to print your tree:
void printTree(AST ast) {
System.out.println(ast);
if (ast.getFirstChild() != null)
printTree(ast.getFirstChild());
if (ast.getNextSibling() != null)
printTree(ast.getNextSibling());
}
The AST tree is sibling pointered, e.g. if you have a simpe list like
( 1 2 3 4 )
you have to follow the getNextSibling() link from the node that contains
"1".
Sorry if this was too obvious, but that would at least make an
explanation...
Regards,
Martin
More information about the antlr-interest
mailing list