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

David Holroyd dave at badgers-in-foil.co.uk
Tue Aug 22 02:29:06 PDT 2006


On Mon, Aug 21, 2006 at 07:10:13PM +0100, Stuart Dootson wrote:
> 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.)

> 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?

Well, the example I was copying from was the last one on the Tree
Construction wiki page:

  http://www.antlr.org/wiki/display/ANTLR3/Tree+construction


> PS Izzat Ada you're parsing?

Nope, ActionScript3 (kinda like ECMAScript4), which has constructs like,

  package foo.bar {  // grammar fragment above lacks the ident
    class Blat {
    }
  }


ta,
dave


More information about the antlr-interest mailing list