[antlr-interest] Question about rule scopes

Johannes Luber jaluber at gmx.de
Sun Feb 24 05:20:34 PST 2008


Olivier Lefevre schrieb:
> If a rule, say bar, can be invoked by more than one other rule and only 
> one these invoking rules, say foo, defines a scoped variable x that we 
> wish to access, then bar needs to know that it was invoked (perhaps 
> through several intermediates) by foo, otherwise $foo::x within bar 
> would either fail or do the wrong thing. Is that information available 
> somehow?
> 
> I can think of other solutions to my problem but they are more verbose 
> than using a scope.
> 
> -- O.L.
> 
> 

You could create a global scope which is initialized to a default value 
or has a boolean set to false at the first parser rule called ever. Only 
foo sets the scope to another value. You have then only check for the 
discriminatory value.

Johannes


More information about the antlr-interest mailing list