[antlr-interest] Using range operator (INT .. INT)

Fabien Hermenier hermenierfabien at gmail.com
Sun Nov 13 15:40:46 PST 2011


Hi

This situation occurred to me recently. Bart, correct me if I am wrong.
It seems like, similar to me, you do not see parsing and lexing as two 
different steps.
Your parser does not allow floats in a range. But prior to the parsing, 
your lexer has to detect if the
the current token it is trying to recognize is a float or a part of an 
integer followed by the range token.
This is why you have to help the lexer recognizing the good tokens using 
a solution
similar to the one explained in the wiki.


Fabien.

Le 13/11/11 16:30, Jiwon Seo a écrit :
> Hmm I see.
>
> Then do I have to extend the lexer like following?
>
> http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+point,+dot,+range,+time+specs
>
> Cause it seems like very complicated for what I want to achieve...
> In my language FLOAT does not have a conflict with the range because I
> do not allow a float number such as .123
> (dot has to be preceded by number like 0.123)
>
> Is there easier way which uses the fact that I'm now allowing .123
> style floating point number?
>
> Thanks.
>
> On Sun, Nov 13, 2011 at 10:14 AM, Bart Kiers<bkiers at gmail.com>  wrote:
>> On Sun, Nov 13, 2011 at 6:59 PM, Jiwon Seo<seojiwon at gmail.com>  wrote:
>>
>>> Thanks for the reply!
>>>
>>> I'm trying to do it without extending lexer since I think my
>>> definition of FLOAT should not be a problem with the range operator.
>>
>> But it _is_  a problem if the `..` is preceded by an INT: the ('0'..'9')+
>> '.' is consumed by FLOAT and can then not match ('0'..'9')+ EXPONENT?,
>> resulting in the MismatchedTokenException.
>>
>> Regards,
>>
>> Bart.
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
> 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