[antlr-interest] Printing AST tree

Johannes Luber jaluber at gmx.de
Mon Jul 21 16:12:14 PDT 2008


rkevinburton at charter.net schrieb:
> 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
> 
Try "tree". ANTLR grammars follow Java and not C# conventions, and 
changing targets doesn't influence that.

Johannes


More information about the antlr-interest mailing list