[antlr-interest] Problem with AST rewrite and variable

Bart Kiers bkiers at gmail.com
Fri Aug 26 04:48:53 PDT 2011


On Fri, Aug 26, 2011 at 1:40 PM, Adam Adamski <thebigsmalln at gmail.com>wrote:

> Dear all ANTLR users,
>

Hi Adam,


Is it a mistake to use variable like I used? I mean:
>
> rule:
>        IDN typ=(type1|type2|typ3)
>        ;
>

Yes, you can't do that. Try this instead:

rule
  :  (ARRAY_OF)* intermediate -> ^(TYPE ^(ARRAY_OFLIST
ARRAY_OF*) intermediate)
  ;

intermediate
  :  simpleType
  |  systemType
  |  objectType
  ;


> My final question: is it wrong to use same var name for many rules ? I
> used variable 'typ' in 4 rules. (I don't think It cause the problem, but
> I'm not sure)


No, there's nothing wrong with that.

Regards,

Bart.


More information about the antlr-interest mailing list