[antlr-interest] Please advice about float
Mark Kattenbelt
mark.kattenbelt at gmail.com
Mon Sep 19 12:42:35 PDT 2005
I understand your point and agree that perhaps the implication is not
ideal. However in my parser I want to sometimes parse INT's and other
times REAL's and not NUMBER's that can be either.
So how do I avoid using => but still having the benefit of having the
actual INT and REAL token. Is that possible in Geviks original lexer?
I'm a bit unsure. I do remember being stuck on this before.
Surely this is a common problem, unless of course I'm being stupid and
see a problem where there isn't one.
Mark
>Yes, and that works too; because I write in C++, I avoid "=>"
>predicates because they incur a thrown exception - very expensive in
>C++ - and in this case you don't really need it.
>
>For java, I understand exceptions are not expensive, so this would
>perhaps work as well.
>
>On 9/19/05, Mark Kattenbelt <mark.kattenbelt at gmail.com> wrote:
>
>
>>My solution:
>>
>>REAL_OR_INT
>> : ( INT '.' ) => REAL { $setType(REAL); }
>> | ('-' INT '.' ) => REAL { $setType(REAL); }
>> | INT { $setType(INT); }
>> ;
>>
>>protected INT options { paraphrase = "a constant integer"; }
>> : ('0' .. '9')+
>> ;
>>
>>protected REAL options { paraphrase = "a floating point value"; }
>> : ('-')? INT '.' INT
>> ;
>>
>>Hope it helps,
>>
>>Mark Kattenbelt
>>
>>
>
>
>
More information about the antlr-interest
mailing list