Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Parser / antlr / DumpASTVisitor.cs
blob83adf02f1180eb477786fecbe24cdf39b2e37cc9
1 using System;
3 using AST = antlr.collections.AST;
5 namespace antlr
7 /* ANTLR Translator Generator
8 * Project led by Terence Parr at http://www.jGuru.com
9 * Software rights: http://www.antlr.org/license.html
11 * $Id:$
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.
22 /// <summary>
23 /// Summary description for DumpASTVisitor.
24 /// </summary>
25 /** Simple class to dump the contents of an AST to the output */
26 public class DumpASTVisitor : ASTVisitor
28 protected int level = 0;
31 private void tabs()
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;
43 AST node2;
44 for (node2 = node; node2 != null; node2 = node2.getNextSibling())
46 if (node2.getFirstChild() != null)
48 flatten = false;
49 break;
53 for (node2 = node; node2 != null; node2 = node2.getNextSibling())
55 if (!flatten || node2 == node)
57 tabs();
59 if (node2.getText() == null)
61 Console.Out.Write("nil");
63 else
65 Console.Out.Write(node2.getText());
68 Console.Out.Write(" [" + node2.Type + "] ");
70 if (flatten)
72 Console.Out.Write(" ");
74 else
76 Console.Out.WriteLine("");
79 if (node2.getFirstChild() != null)
81 level++;
82 visit(node2.getFirstChild());
83 level--;
87 if (flatten)
89 Console.Out.WriteLine("");