[antlr-interest] CommonTree -> AST conversion ?

Sébastien Kirche sebastien.kirche at gmail.com
Wed Apr 14 10:10:21 PDT 2010


Le 13 avril 2010 21:24, Gerald Rosenberg <gerald at certiv.net> a écrit :

>  ------ 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
>
>  [...]

>  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.
>
>
Yes, decoupling the application-specific code from the parser code with a
helper class sound a reasonable solution. I will try that.
And thanks for your documentation pointers.
-- 
Sébastien Kirche


More information about the antlr-interest mailing list