[antlr-interest] matching an AST segment with Java 5
John Green
greenj at ix.netcom.com
Tue Jul 25 17:08:42 PDT 2006
With Java 5 and autoboxing, I could use nested Object arrays as a quick and dirty description for a segment of an AST. Has anybody done this sort of thing before? Specifically, I wonder if match(AST, Object[]) as per my "usage example" below has been written and exists in any of the Antlr or other libraries.
It'll be easy to write, I'd just rather use existing libraries. :)
int PLUS = 20;
int NUMBER = 30;
void m(AST currentNode) {
// Looking for: #(PLUS #(PLUS NUMBER NUMBER) NUMBER)
// and if found, print the text of the first NUMBER node.
Object [] match = match(currentNode,
new Object[]{PLUS, new Object[]{PLUS, NUMBER, NUMBER}, NUMBER}
);
if (match!=null) {
out.println(((AST)((Object[])match[1])[1]).getText());
}
}
Cheers,
John
www.joanju.com
More information about the antlr-interest
mailing list