[antlr-interest] CommonTree -> AST conversion ?

Gerald Rosenberg gerald at certiv.net
Tue Apr 13 12:24:47 PDT 2010


------ Original Message (Tuesday, April 13, 2010 11:12:53 
AM) From: Sébastien Kirche ------
Subject: Re: [antlr-interest] CommonTree -> AST conversion ?
> Do you mean to generate the tree walker by writing a tree grammar on 
> top of my parser grammar, or am I missing an antlr feature ?
Yes, just write a simple tree pattern matcher and have Antlr generate 
the tree walker code.  Lots of examples and more explanation in Language 
Implementation Patterns 
<http://pragprog.com/titles/tpdsl/language-design-patterns>.  
http://www.antlr.org/wiki/display/ANTLR3/Tree+pattern+matching
>
> When I was talking about implementing a visitor, it was related to the 
> article « Manual Tree Walking Is Better Than Tree Grammars »[1]
There are valid points made in that article, but that is just not the 
best place to start.
> And it was also to see what is under the hood of the tree grammars, 
> like learning some assembly helps to understand the work of a C compiler.
Looking at the source of the C compiler would be far more sensible.
> And I also find quite ugly the mix of grammar code with java code : I 
> fear that when my grammar will grow the maintenance of the resulting 
> code will become hard.
Yes, best to minimize the mix.  You can either use the superclass option 
(http://www.antlr.org/wiki/display/ANTLR3/Grammar+options) or, better, 
set a helper class on the parser that can then be called from the actions.



More information about the antlr-interest mailing list