[antlr-interest] Reuse rule-return "shortcuts"

Jim Idle jimi at temporal-wave.com
Wed Apr 2 11:11:47 PDT 2008


Felix,

the label is just that, a label named as per your choice, hence it is generated as a label in the target language, typed according to the rule name. Just as in say Java you cannot have both an int and a String called 'felix', you cannot use the same name on different rules as they have different return types and hence the variable types need to be different. If you want suffixes you must add them yourself. Just think of the labels as variable names and it should make sense to you.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Felix Dorner
> Sent: Wednesday, April 02, 2008 8:10 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Reuse rule-return "shortcuts"
> 
> Hey,
> 
> I try to reuse abbreviations for return values in rules like this:
> 
> expression: op=unaryOp e1=expression | op=binaryOp e1=expression
> e2=expression;
> 
> It seems like Antlr(3.0.1) can't handle this correctly, as it does not
> suffix the "op" with a unique id. So "op" gets only declared once. In
> generated code for the the second alternative, the assignment is
> completely missing.
> 
> Strangely a few minutes ago I got a warning "redefiniton of rule
> attribute with incompatible type" (or so). That warning now doesn't
> appear anymore, instead this silent bogus.
> 
> I'd like to be able to reuse these names (how are they called
> actually?)
> in different  alternatives even  if their types are different.  Antlr
> would have to append unique id in the generated code then.
> 
> Thanks for comments.
> Felix






More information about the antlr-interest mailing list