[antlr-interest] Treeview
Barry Kelly
barry.j.kelly at gmail.com
Thu Oct 28 06:28:04 PDT 2004
On Thu, 28 Oct 2004 14:38:18 +0200, Maassen, H.A.M.
<h.a.m.maassen at student.tue.nl> wrote:
> So if anyone could give me a quick-and-dirty rundown of how to get my Main() to show
> me a little ascii tree I'd be really grateful :) otherwise I guess it's back to browsing the
> examples and documentation.
You could use AST.ToString* and friends, but here's a manual recursive method:
using System.IO;
using AST = antlr.collections.AST;
// etc...
public static void Main(string[] args)
{
// Create compiler, compile.
YourLexer lex = new YourLexer(new StringReader(text));
YourParser parser = new YourParser(lex);
parser.yourTopRule();
AST root = parser.getAST();
if (root != null)
RecurseIntoMyAST(string.Empty, root);
}
public static void RecurseIntoMyAST(string indent, AST root)
{
// Assumes that root is not null.
// Print this node
Console.WriteLine("{0}{1}", indent, root.getText());
// Print all children
for (AST child = root.getFirstChild(); child != null;
child = child.getNextSibling())
RecurseIntoMyAST(indent + " ", child);
}
// ...
-- Barry
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list