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

Terence Parr parrt at cs.usfca.edu
Fri Jan 16 15:44:29 PST 2009


On Jan 16, 2009, at 3:21 PM, Gerald Rosenberg wrote:

> At 01:20 PM 1/16/2009, Jim Idle wrote:
>> Gerald Rosenberg wrote:
>>> Bug in the Java target code generation? -- possibly related to  
>>> ANTLR-357
>> Basically, the references are not really intended to be used like  
>> that, but you get away with it quite a lot of the time. You should  
>> really do this:
>>
>> CommonToken ct = $k.start;
>> // Check for null and so on here
>> gDecl.setName(ct.getStartIndex());
>
> Thanks, Jim.  I realize the work around is obvious.
>
> What is not so obvious is intent.  To all appearances, the code gen  
> is intending to do the right thing -- it produces valid code, but  
> vulnerable to the run-time NPE.  I just wanted to raise the issue so  
> that it might be noted by someone with Jira rights and hopefully  
> addressed as Antlr continues to evolve.

hi. yeah, the problem is that $k.start must be NPE protected.   
Anything that uses that expression could get an NPE though :(  I don't  
see past $k.start so I can't know what you're doing with it.
Ter


More information about the antlr-interest mailing list