[antlr-interest] add new support methods in BaseTree?
Terence Parr
parrt at cs.usfca.edu
Wed Oct 22 14:01:10 PDT 2008
Hi, i'm thinking of adding this to BaseTree:
/** Walk upwards looking for ancestor of this token type */
public boolean hasAncestor(int ttype) {
CommonTree t = this;
t = t.parent;
while ( t!=null ) {
if ( t.getType()==ttype ) return true;
t = t.parent;
}
return false;
}
and perhaps a few more context computations. In a tree grammar, you
might want to do this:
{((VecMathNode)input.LT(1)).hasAncestor(PRINT)}? ID // match only IDs
in expr of print statements
Any objections or votes in support?
Ter
More information about the antlr-interest
mailing list