3 using AST
= antlr
.collections
.AST
;
7 /* ANTLR Translator Generator
8 * Project led by Terence Parr at http://www.jGuru.com
9 * Software rights: http://www.antlr.org/license.html
15 // ANTLR C# Code Generator by Micheal Jordan
16 // Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
17 // Anthony Oguntimehin
19 // With many thanks to Eric V. Smith from the ANTLR list.
23 /// Summary description for DumpASTVisitor.
25 /** Simple class to dump the contents of an AST to the output */
26 public class DumpASTVisitor
: ASTVisitor
28 protected int level
= 0;
33 for (int i
= 0; i
< level
; i
++)
35 Console
.Out
.Write(" ");
39 public void visit(AST node
)
41 // Flatten this level of the tree if it has no children
42 bool flatten
= /*true*/ false;
44 for (node2
= node
; node2
!= null; node2
= node2
.getNextSibling())
46 if (node2
.getFirstChild() != null)
53 for (node2
= node
; node2
!= null; node2
= node2
.getNextSibling())
55 if (!flatten
|| node2
== node
)
59 if (node2
.getText() == null)
61 Console
.Out
.Write("nil");
65 Console
.Out
.Write(node2
.getText());
68 Console
.Out
.Write(" [" + node2
.Type
+ "] ");
72 Console
.Out
.Write(" ");
76 Console
.Out
.WriteLine("");
79 if (node2
.getFirstChild() != null)
82 visit(node2
.getFirstChild());
89 Console
.Out
.WriteLine("");