[antlr-interest] An issue with label method references in actions

Terence Parr parrt at cs.usfca.edu
Fri Jan 16 17:01:50 PST 2009


On Jan 16, 2009, at 4:47 PM, Gerald Rosenberg wrote:

> At 03:40 PM 1/16/2009, Jim Idle wrote:
>> Gerald Rosenberg wrote:
>>> At 01:20 PM 1/16/2009, Jim Idle wrote:
>>
>> Hence, because the reference parser is simple, and does not know  
>> anything about the object it will generate code to reference, there  
>> is no way to protect you from the NPE, hence there is nothing to  
>> fix per se.
>
> Hmmm, if the code gen is smart enough to break up
>
> gDecl .setName($k. start .getStartIndex());
>
> to produce this
>
> gDecl .setName((k != null ? ((CommonToken) k.start ) :  
> null ).getStartIndex());

it only sees $k.start...nothing beyond.

> then it should be able to produce this instead
>
> gDecl .setName((k != null ? ((CommonToken)  
> k.start .getStartIndex()) : null ));

unfortunately, can't see past start in $x.y action translator.

> I did see Ter's note that the current code gen analysis is not  
> looking far enough ahead to handle this.  But, that is just one of  
> those minor, no-doubt short-lived practical inconveniences. ;-)

actually, it's 'cause I don't know what language people are using; or  
how to eval what's around the $x.y

>> It's one of those things that you have to garner some extra  
>> knowledge from by looking at the code, which you have done :-)
>
> I have to say that I am doing this less and less and, always now,  
> the issues are these kind of odd code generation issues.  The  
> evolution of Antlr as a language has been amazing to watch.  Still,  
> I look forward to when lifting the cover will not be required except  
> in the most exceptional of circumstances.

me too!

Ter


More information about the antlr-interest mailing list