[antlr-interest] dynamically scoped attribute syntax

Jim Idle jimi at temporal-wave.com
Wed Nov 23 13:02:21 PST 2005



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Terence Parr
> Sent: Wednesday, November 23, 2005 10:16 AM
> To: ANTLR Interest
> Subject: [antlr-interest] dynamically scoped attribute syntax
> 
> I've changed my mind on this syntax too (yet more changes in my tests/
> examples).

> In the body rule, you must specifically
> reference the scope with the attribute as $function.name, but this
> still doesn't scream "the value is in another rule, dude!"
> 
> I am proposing to avoid use of a special '@' symbol or whatever in
> favor of the C++ style scope override "::".  

I totally agree with this as I have had issues with the $stuff not being
able to work out what I meant.

> THat said, I think the
> distinction should be sort of "local" vs "global" so that you can say
> $name inside the rule that defines the scope, but you must use
> $scope::name in an invoked rule like body:

Gets my vote.
 
> What about shared global scopes?  I propose that we always have to
> use the fully-qualified scope in this case.

I agree.

> Speaking of which, we need to be able to specify some init code in
> the global scope so we can avoid code duplication and do avoid
> forgetting.  I shied away from it originally because I didn't know
> what the syntax would look like and whether it would be useful.  This
> bit me hard yesterday when building an ANTLR+ST example.  How about
> just adding the init action into the scope?
> 
> scope Symbols {
> 	List names;
> 	init {
> 		$Symbols::names = new ArrayList();
> 	}
> }
> 
> Actually I'll be using probably @init {...} 

I am in favor of all of this. Very much so... so can you type it in now
so I get on with the C code generator? ;-)

Jim


More information about the antlr-interest mailing list