[antlr-interest] Identifiers are not local to alternati ves?

Gavin Lambert antlr at mirality.co.nz
Sun Jun 29 14:30:02 PDT 2008


At 09:12 30/06/2008, Raphael Reitzig wrote:
 >*** error(116): Test.g:4:8: unknown attribute for rule b: s
 >
 >4.8 does not point to any sensible location, at least not if you 
do
 >not know what to look for. Or am I counting in the wrong way? ?(

Line 4 column 8 is just after the opening { in the "v=a" line, so 
it's certainly *close* to the error.

 >* move declaration of those variable inside the "case"-Blocks,
 >rendering them kind of alternative-local.

There is a reason why this is done that way.  You might want to 
have code like this:

test
   :  (v=a | v=b) { DoSomething($v.x); }
   ;

(Where both 'a' and 'b' return the same type.)

Having said that, the way the internal code generation works tends 
to make the types incompatible anyway (the actual return from 'a' 
will be an 'a_return_struct' and the return from 'b' will be a 
'b_return_struct', which aren't compatible), so the above isn't 
always feasible either.  Another example (which does work 
currently):

test
   :  (v=a b c | d v=a c) { DoSomething($v.x); }
   ;



More information about the antlr-interest mailing list