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

Raphael Reitzig r_reitzi at cs.uni-kl.de
Sat Jul 12 04:25:35 PDT 2008


Hi!

I did not have such examples in mind. Given something like that is and
should be possible, perhaps enhanced static analysis of the input grammar
would be a good solution to avoid confusion. 
It would be a matter of style wether you would like to use more powerful
analysis to create the most fitting piece of code or to print the most
accurate error message (if you want to be restrictive with the use of
variables in grammars).

(Naturally, if you know the tool well, you will not be confused. But
hopefully, there will always be people getting to know ANTLR just then,
like me today, and getting confused.)

Regards

Raphael

On Mon, 30 Jun 2008 09:30:02 +1200, Gavin Lambert <antlr at mirality.co.nz>
wrote:
> 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