[antlr-interest] Problem when parsing numerics
Jim Idle
jimi at temporal-wave.com
Wed Feb 18 08:16:13 PST 2009
Thomas Woelfle wrote:
> Hi Jim,
>
> thanks for the tip. This lexer grammar for floating points is quite
> impressive and answers some interesting questions to me. But it did
> not solve my problem. Using the toekn rule 'FLOATING_POINT_LITERAL' in
> my grammar results in the same MismatchedTokenException. My adjusted
> grammar is:
>
> foo : FLOATING_POINT_LITERAL '.';
>
> where "FLOATING_POINT_LITERAL" is the rule from your example.
>
> Parsing the input string "1.5." results in a MismatchedTokenException.
> Any idea what is going wrong?
You will need more than just the FLOATING_POINT_LITERAL rule I think.
You will need to allow the lexer to return the DOT token, but just
delete the RANGE token, then your parser rule would be foo :
FLOATING_POINT_LITERAL DOT ; When you add the '.' to your parser it
auto-creates a lexer rule that will not fit well with the other lexer rules.
Jim
>
> Regards,
> Thomas
>> Thomas Woelfle wrote:
>>
>>> Hi,
>>>
>>> I've been running into a strange problem using ANTLR 3.1.1. I don't
>>> know wether it is a bug in my grammar or a bug in ANTLR.
>>> In the language that has to be parsed following lines are legal
>>> strings:
>>>
>>> 1.
>>> 1.5.
>>>
>>> There is a rule where a numeric is followed by a dot.
>>>
>> Please look in the FAQ/examples:
>>
>> http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+point%2C+dot%2C+range%2C+time+specs
>>
>>
>> You should be able to simplify the grammar here to just what you need.
>>
>> Jim
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>
More information about the antlr-interest
mailing list