[antlr-interest] AST rewrites for recursive rules

John B. Brodie jbb at acm.org
Sat Sep 2 07:51:45 PDT 2006


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


More information about the antlr-interest mailing list