[antlr-interest] dynamically scoped attribute syntax
Terence Parr
parrt at cs.usfca.edu
Wed Nov 23 13:12:57 PST 2005
On Nov 23, 2005, at 1:02 PM, Jim Idle wrote:
>> 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.
I decided that any ref to a dynamically scoped attribute (even inside
rule that defines the attribute) should use $x::y. Just made the
implementation cleaner :) Also, Jean in ANTLRWorks will be able to
highlight all refs with potentially nonlocal effects :)
>> 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? ;-)
Turns out putting the init inside is very hard. The whole thing is
language independent and I just get ACTION from the ANTLR lexer. I
am thinking that we need something like:
scope Foo {...}
@Foo::init {...} // to be consistent with scope access?
then we'd also allow
@header {...}
@lexer::header {...}
etc...
Working on the x::y thing now...60 unit tests to change and all the
examples! ;)
Ter
More information about the antlr-interest
mailing list