[antlr-interest] about range float and stuff

Fabien Hermenier hermenierfabien at gmail.com
Thu Nov 3 23:28:40 PDT 2011


Hi

In an earlier version of my language, I had to parse range of integers 
in various base. Now I want to include float. I have read
http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+point,+dot,+range,+time+specs
but I've still got some questions.

All the work seems to be done at the lexer level so the type of the 
following tokens will be as example:
5 : DECIMAL_LITTERAL
07 : OCTAL_LITTERAL
7.5: FLOATING_POINT_LITTERAL
5..7 : DOTDOT

In the last example, the result is not very convenient because I will 
still have to extract the bounds
and compute their type by myself which seems quite redundant with the 
job performed by the lexer.
May be I am missing something ?

I would rather be able to express the range at the parser level which 
seems much more convenient to me:
range: FLOATING_POINT_LITTERAL DOTDOT FLOATING_POINT_LITTERAL.
In this way, I will also be able to manage the possible spaces between 
the bounds and the DOTDOT.

So, am I right to try to parse range at the parser level ? Or is there a 
solution to extract easily the bounds with their type if I am doing the 
job at the lexer level ?

Thanks in advance,
Fabien.





More information about the antlr-interest mailing list