[antlr-interest] Question regarding "Assignment"

Sam Barnett-Cormack s.barnett-cormack at lancaster.ac.uk
Tue Mar 24 04:57:31 PDT 2009


Lucien Antlr wrote:
> Hi folks,
>  
> Still wrestling with the ins and outs of the tool, I came up with
> something I expected to work but that didn't.
> 
> I expected lab=(EQ expr) to assign the AST to "lab", but rather it
> always returns a null.
>  
> The equivalent  working statement would be either
> 1)    (labA=EQ labB=expr) -> ^($labA $labB)
> or
> 2)  newRule:   EQ expr;
>    (lab=newRule) -> ^($lab)
>  
> Is it a bug that grouping through ( ) doesn't work when assigning to a
> label?

I have reliably been informed - yes. Usual recommendation I've seen is
to do (2), although I don't think that'll quite work as you expect... I
think you want

newRule: EQ expr -> ^(EQ expr);

and do

lab=newRule -> $lab ---or--- newRule -> newRule, of course. Which is
equivalent to just newRule.

That would be equivalent to what you have in (1) - I'm not sure if what
you have in (2) is actually valid or not, as you appear to be saying
that the list "EQ expr" is to be the root of the new tree.

Sam


More information about the antlr-interest mailing list