[antlr-interest] add new support methods in BaseTree?

Gerald Rosenberg gerald at certiv.net
Wed Oct 22 14:10:51 PDT 2008


At 02:01 PM 10/22/2008, Terence Parr wrote:
>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?

Yes, this would be quite helpful.  What other functions are you considering?

Gerald 



More information about the antlr-interest mailing list