[antlr-interest] Re: [antlr-dev] something like @lexer::init

Terence Parr parrt at cs.usfca.edu
Sun Jun 11 08:17:24 PDT 2006


On Jun 11, 2006, at 4:59 AM, Kay Roepke wrote:
> Do we already have support for something like
>
> lexer grammar foo;
>
> @lexer::members {
> 	NSMutableDictionary *packetDict;	// this goes into header file
> }	
>
> @lexer::init { // (naming?)
> 	// do this stuff in the constructor/initializer
> 	// maybe setup the packetDict instance var...
> 	packetDict = [[NSMutableDictionary alloc] init];
> }
>
> or do I have to subclass the generated lexer? (I'd rather not...)
>
> For extra credit I'd like to have a action scope for the dealloc/ 
> destructor phase, too. Maybe @lexer::finally?

Here's the beauty of v3's use of ST.  You can define whatever actions  
you want for your target.  ANTLR just passes them through and your  
target templates just need to reference them.

I added @synpredgate {...} last night for all targets and it just  
appears as <actions.parser.synpredgate> in the parser templates. :)

So, if your target needs them (doesn't ObjC have a ctor?) then define  
them! :)

Ter


More information about the antlr-interest mailing list