[antlr-interest] Lexing problem I cannot resolve
John B. Brodie
jbb at acm.org
Wed Aug 6 12:39:04 PDT 2008
Carter Cheng continued a long thread by saying:
>I tried this variant too but it does not seem to parse correctly(see
>attached). It still thinks that the 1. is a FLOAT token. Perhaps I
>have run afoul of some bug in 3.0.1?
>
>Regards,
>
>Carter.
>
>--- On Wed, 8/6/08, Loring Craymer <lgcraymer at yahoo.com> wrote:
>
>> From: Loring Craymer <lgcraymer at yahoo.com>
>> Subject: Re: [antlr-interest] Lexing problem I cannot resolve
>> To: "Carter Cheng" <carter_cheng at yahoo.com>, antlr-interest at antlr.org
>> Date: Wednesday, August 6, 2008, 10:18 AM
>> Try
>> fragment DIGIT: '0'..'9';
>> fragment DOTDOT : '..' ;
>> RANGE: DOTDOT ;
>> INT
>> : DIGIT+
>> ( (DOTDOT) => |
>> ( '.' DIGIT* { $type = FLOAT; } )? )
>> ;
>>
>> fragment FLOAT : DIGIT;
>>
....remainder snipped....
well Loring's rule, and all of the vesions of it posted in the message
Loring replied to, permit 0 or more DIGITs after the single decimal
point.
Notice the `*` on the DIGIT after the `.`.
so if you do not want `1.` to be a FLOAT then change the `*` to a `+`.
Hope this helps
-jbb
More information about the antlr-interest
mailing list