public void visit(AST node) { // Flatten this level of the tree if it has no children bool flatten = /*true*/ false; AST node2; for (node2 = node; node2 != null; node2 = node2.getNextSibling()) { if (node2.getFirstChild() != null) { flatten = false; break; } } for (node2 = node; node2 != null; node2 = node2.getNextSibling()) { if (!flatten || node2 == node) { tabs(); } if (node2.getText() == null) { Console.Out.Write("nil"); } else { Console.Out.Write(node2.getText()); } Console.Out.Write(" [" + node2.Type + "] "); if (flatten) { Console.Out.Write(" "); } else { Console.Out.WriteLine(""); } if (node2.getFirstChild() != null) { level++; visit(node2.getFirstChild()); level--; } } if (flatten) { Console.Out.WriteLine(""); } }
/*Is node t equal to this in terms of token type and text? */ public virtual bool Equals(AST t) { if (t == null) { return(false); } return((Object.Equals(this.getText(), t.getText())) && (this.Type == t.Type)); }