[antlr-interest] AST rewrites for recursive rules
Phil Goodwin
phil.goodwin at gmail.com
Sat Sep 2 22:03:40 PDT 2006
Hi John,
Yes, that is very helpful! So, instead of accessing the generated tree and
rearranging it, we pass the parts that we already have to the referenced
rule and let it do the work once it gathers the rest of the information.
Works perfectly and gives me a different way to think about tree generation.
Thanks a lot,
Phil
On 9/2/06, John B. Brodie <jbb at acm.org> wrote:
>
> Greetings!
>
> >....snipped...
> >I've pasted the code below. Here's my question: is there a better way to
> >access and manipulate the tree generated by a referenced rule? The AST
> >generation code below mirrors the elegance of the original recognizer but
> >that is lost amid the brutality done to the returned trees.
> >....snipped...
>
> How about passing the formal type as a parameter?
>
> formalParameters
> : t=TYPE formalParameterDeclsRest[$t] -> formalParameterDeclsRest
> ;
> formalParameterDeclsRest[ Token t ]
> : i=IDENTIFIER
> ( ( ',' formalParameters -> ^({$t} $i) formalParameters )
> | ( /*empty*/ -> ^({$t} $i) )
> )
> ;
>
> Hope this helps...
> -jbb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060902/d1351711/attachment.html
More information about the antlr-interest
mailing list