[antlr-interest] Why doesn't this work?
Indhu Bharathi
indhu.b at s7software.com
Wed Apr 8 20:51:02 PDT 2009
Hi Gavin,
Thanks for the reply. I had previously fixed it with gated symantic
predicates with using LA(...). Instead using syntactic predicates as you
have suggested looks like a more elegant option. Will try that. Thanks
again.
Though the problem is solved now, I'm interested to know why the
original example didn't work. That will produce a more readable grammar
file, ofcourse will a little sacrifice on performance. One difference in
the generated code I see is, INT_FLOAT_PATTERN() function is not using
synpred*** at all. It is just guessing the alts using a dfa. However the
dfa has something called special state transition which checks just one
of the three syntactic predicates. Shouldn't INT_FLOAT_PATTERN() use all
three synpred*** directly? I feel there is something going wrong in the
code generation part.
Thanks, Indhu
Gavin Lambert wrote:
> At 03:12 9/04/2009, Indhu Bharathi wrote:
>> INT_FLOAT_PATTERN
>> : (NUMBER DOT NUMBER LETTER ) => NUMBER DOT NUMBER LETTER
>> { $type=PATTERN; }
>>
>> | ( NUMBER DOT NUMBER ) => NUMBER DOT NUMBER
>> { $type=FLOAT_LIT; }
>>
>> | (NUMBER) => NUMBER
>> { $type=INT_LIT; }
>>
>> ;
>
> I'm not sure why that isn't working, but you might want to left-factor
> it a bit more than you have:
>
> INT_FLOAT_PATTERN /* or you could just make this INT_LIT */
> : NUMBER { $type = INT_LIT; }
> ( (DOT NUMBER) => DOT NUMBER { $type = FLOAT_LIT; }
> (LETTER { $type = PATTERN; })?
> )?
> ;
>
> This should be more efficient (because it will only do the
> lookahead-backtracking once), and hopefully it'll actually work
> (though I haven't tested it).
>
>
More information about the antlr-interest
mailing list