[antlr-interest] specialStateTransition() in Java-generated lexer

Kevin J. Cummings cummings at kjchome.homeip.net
Thu Jul 23 16:09:50 PDT 2009


On 07/23/2009 05:39 PM, Gavin Lambert wrote:
> At 09:22 24/07/2009, Kevin J. Cummings wrote:
>  > The only usage of "s" after the "_s = s" assignment, are
>  >assignments to "s" itself, which reflect a value depending
>  >on the if statements inside the switch. If you assigned a
>  >positive value to s, return it.
>  >Otherwise (I assume s is still -1) you break out of the switch
>  >statement. In which case (pun intended), since you are about to
>  >throw an exception, it contains the saved input value _s. So,
>  >the code looks good to me.....
>
> Although it would have made more sense to alter the local variable and
> leave the parameter alone. So, correct, yes, but "good" might be a bit
> of a stretch... :)

Maybe, but leaving the parameter in a register ties up that register 
(and it might still be spilled anyways), depends on the complexity of 
the code and the intelligence of the optimizers and code generators. 
B^)  From the viewpoint of readability, Gavin is probably right.

-- 
Kevin J. Cummings
kjchome at rcn.com
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list