[antlr-interest] Printing AST tree

rkevinburton at charter.net rkevinburton at charter.net
Mon Jul 21 14:34:53 PDT 2008


I am using CSharp and am starting my tour through ANTLR using the ANTLR book and the first road block that I came up with is printing out the AST tree. In the book there is a statement:

prog: ( stat {System.out.println($stat.tree.toStringTree());} )+ ;

I am try the following action:

program
	: (sourceElement { Console.WriteLine((CommonTree)$sourceElement.Tree); })*
	;



But from ANTLRWorks I am unable to generate code because 'Tree' is undefined. What is the equivalent C# statement for converting an AST tree to a string for pinrtout.

Thank you.

Kevin


More information about the antlr-interest mailing list