[antlr-interest] [v3] Rule references in rewrite rules?

Stuart Dootson stuart.dootson at gmail.com
Mon Aug 21 11:10:13 PDT 2006


On 8/21/06, David Holroyd <dave at badgers-in-foil.co.uk> wrote:
> Hello,
>
>
> Should the following do what I think it should..?
>
>   compilationUnit:
>           'package' packageBlock -> ^(COMPILATION_UNIT $compilationUnit)
>       ;
>
> I was expecting this to give me a result tree which lookes like,
>
>   #( COMPILATION_UNIT 'package' ..etc.. )
>
> but instead I just get,
>
>   #( COMPILATION_UNIT )
>
>
> Is my syntax wrong, or is $compilationUnit not actually a reference to
> the entire pre-rewrite tree for the compilationUnit rule?  (I can't
> remember where I read that it should be, any more.)
>
>
> Thanks for any suggestions!
> dave

I would imagine you can only reference things on the right hand side
in the rewrite rule - after all, $compilationUnit doesn't really exist
at that point (if you see the rule as a declaration of sorts)? And
what if you had a recursive rule?

Stuart Dootson

PS Izzat Ada you're parsing?


More information about the antlr-interest mailing list