public static void doTreeAction(string f, AST t, string[] tokenNames) { if (t == null) { return; } if (showTree) { BaseAST.setVerboseStringConversion(true, tokenNames); ASTFactory factory = new ASTFactory(); AST r = factory.create(0, "AST ROOT"); r.setFirstChild(t); ASTFrame frame = new ASTFrame("Java AST", r); frame.ShowDialog(); //frame.Visible = true; // System.out.println(t.toStringList()); } JavaTreeParser tparse = new JavaTreeParser(); JavaRecognizer.initializeASTFactory(tparse.getASTFactory()); try { tparse.compilationUnit(t); // System.out.println("successful walk of result AST for "+f); } catch (RecognitionException e) { Console.Error.WriteLine(e.Message); Console.Error.WriteLine(e.StackTrace); } }
/// <summary> /// Get number of children of this node; if leaf, returns 0 /// </summary> /// <returns>Number of children</returns> public int getNumberOfChildren() { BaseAST t = this.down; int n = 0; if (t != null) { n = 1; while (t.right != null) { t = t.right; n++; } } return(n); }
/*Add a node to the end of the child list for this node */ public virtual void addChild(AST node) { if (node == null) return ; BaseAST t = this.down; if (t != null) { while (t.right != null) { t = t.right; } t.right = (BaseAST) node; } else { this.down = (BaseAST) node; } }
/*Add a node to the end of the child list for this node */ public virtual void addChild(AST node) { if (node == null) { return; } BaseAST t = this.down; if (t != null) { while (t.right != null) { t = t.right; } t.right = (BaseAST)node; } else { this.down = (BaseAST)node; } }
public virtual void setNextSibling(AST n) { right = (BaseAST)n; }
public virtual void setFirstChild(AST c) { down = (BaseAST)c; }
/*Remove all children */ public virtual void removeChildren() { down = null; }
public virtual void setNextSibling(AST n) { right = (BaseAST) n; }
public virtual void setFirstChild(AST c) { down = (BaseAST) c; }