/** Get the ith child from 0 */ public GrammarAST getChild(int i) { int n = 0; AST t = getFirstChild(); while ( t!=null ) { if ( n==i ) { return (GrammarAST)t; } n++; t = (GrammarAST)t.getNextSibling(); } return null; }
/** Get the ith child from 0 */ public GrammarAST getChild(int i) { int n = 0; AST t = getFirstChild(); while ( t!=null ) { if ( n==i ) { return (GrammarAST)t; } n++; t = (GrammarAST)t.getNextSibling(); } return null; }
public GrammarAST getLastChild() { return ((GrammarAST)getFirstChild()).getLastSibling(); }
public GrammarAST getLastChild() { return ((GrammarAST)getFirstChild()).getLastSibling(); }
public GrammarAST getFirstChildWithType(int ttype) { AST t = getFirstChild(); while ( t!=null ) { if ( t.getType()==ttype ) { return (GrammarAST)t; } t = (GrammarAST)t.getNextSibling(); } return null; }
public GrammarAST[] getChildrenAsArray() { AST t = getFirstChild(); GrammarAST[] array = new GrammarAST[getNumberOfChildren()]; int i = 0; while ( t!=null ) { array[i] = (GrammarAST)t; t = t.getNextSibling(); i++; } return array; }
public GrammarAST getFirstChildWithType(int ttype) { AST t = getFirstChild(); while ( t!=null ) { if ( t.getType()==ttype ) { return (GrammarAST)t; } t = (GrammarAST)t.getNextSibling(); } return null; }
public GrammarAST[] getChildrenAsArray() { AST t = getFirstChild(); GrammarAST[] array = new GrammarAST[getNumberOfChildren()]; int i = 0; while ( t!=null ) { array[i] = (GrammarAST)t; t = t.getNextSibling(); i++; } return array; }
public int getNumberOfChildrenWithType(int ttype) { AST p = this.getFirstChild(); int n = 0; while ( p!=null ) { if ( p.getType()==ttype ) n++; p = p.getNextSibling(); } return n; }
public int getNumberOfChildrenWithType(int ttype) { AST p = this.getFirstChild(); int n = 0; while ( p!=null ) { if ( p.getType()==ttype ) n++; p = p.getNextSibling(); } return n; }
public int getLine() { int line=0; if ( token!=null ) { line = token.getLine(); } if ( line==0 ) { AST child = getFirstChild(); if ( child!=null ) { line = child.getLine(); } } return line; }
public int getColumn() { int col=0; if ( token!=null ) { col = token.getColumn(); } if ( col==0 ) { AST child = getFirstChild(); if ( child!=null ) { col = child.getColumn(); } } return col; }
public int getLine() { int line=0; if ( token!=null ) { line = token.getLine(); } if ( line==0 ) { AST child = getFirstChild(); if ( child!=null ) { line = child.getLine(); } } return line; }
public int getColumn() { int col=0; if ( token!=null ) { col = token.getColumn(); } if ( col==0 ) { AST child = getFirstChild(); if ( child!=null ) { col = child.getColumn(); } } return col; }
/** See if tree has exact token types and structure; no text */ public boolean hasSameTreeStructure(AST t) { // check roots first. if (this.getType() != t.getType()) return false; // if roots match, do full list match test on children. if (this.getFirstChild() != null) { if (!(((GrammarAST)this.getFirstChild()).hasSameListStructure(t.getFirstChild()))) return false; } // sibling has no kids, make sure t doesn't either else if (t.getFirstChild() != null) { return false; } return true; }
/** See if tree has exact token types and structure; no text */ public boolean hasSameTreeStructure(AST t) { // check roots first. if (this.getType() != t.getType()) return false; // if roots match, do full list match test on children. if (this.getFirstChild() != null) { if (!(((GrammarAST)this.getFirstChild()).hasSameListStructure(t.getFirstChild()))) return false; } // sibling has no kids, make sure t doesn't either else if (t.getFirstChild() != null) { return false; } return true; }
/** Return a reference to the first node (depth-first) that has * token type ttype. Assume 'this' is a root node; don't visit siblings * of root. Return null if no node found with ttype. */ public GrammarAST findFirstType(int ttype) { // check this node (the root) first if ( this.getType()==ttype ) { return this; } // else check children GrammarAST child = (GrammarAST)this.getFirstChild(); while ( child!=null ) { GrammarAST result = child.findFirstType(ttype); if ( result!=null ) { return result; } child = (GrammarAST)child.getNextSibling(); } return null; }
/** Track which rules have rewrite rules. Pass in the ALT node * for the alt so we can check for problems when output=template, * rewrite=true, and grammar type is tree parser. */ public void trackAltsWithRewrites(GrammarAST altAST, int outerAltNum) { if ( grammar.type==Grammar.TREE_PARSER && grammar.buildTemplate() && grammar.getOption("rewrite")!=null && grammar.getOption("rewrite").equals("true") ) { GrammarAST firstElementAST = (GrammarAST)altAST.getFirstChild(); grammar.sanity.ensureAltIsSimpleNodeOrTree(altAST, firstElementAST, outerAltNum); } altsWithRewrites[outerAltNum] = true; }
/** Track which rules have rewrite rules. Pass in the ALT node * for the alt so we can check for problems when output=template, * rewrite=true, and grammar type is tree parser. */ public void trackAltsWithRewrites(GrammarAST altAST, int outerAltNum) { if ( grammar.type==Grammar.TREE_PARSER && grammar.buildTemplate() && grammar.getOption("rewrite")!=null && grammar.getOption("rewrite").equals("true") ) { GrammarAST firstElementAST = (GrammarAST)altAST.getFirstChild(); grammar.sanity.ensureAltIsSimpleNodeOrTree(altAST, firstElementAST, outerAltNum); } altsWithRewrites[outerAltNum] = true; }
/** Return a reference to the first node (depth-first) that has * token type ttype. Assume 'this' is a root node; don't visit siblings * of root. Return null if no node found with ttype. */ public GrammarAST findFirstType(int ttype) { // check this node (the root) first if ( this.getType()==ttype ) { return this; } // else check children GrammarAST child = (GrammarAST)this.getFirstChild(); while ( child!=null ) { GrammarAST result = child.findFirstType(ttype); if ( result!=null ) { return result; } child = (GrammarAST)child.getNextSibling(); } return null; }