[antlr-interest] how to put lexer rules syntactic check
Jim Idle
jimi at temporal-wave.com
Fri Jul 24 10:10:57 PDT 2009
This is an FAQ answered again only yesterday or the day before. Look
on the wiki for the article on how to lex for integer, floating point
and range.
Jim
On Jul 24, 2009, at 4:21 AM, Ivo Kondapaneni
<ivo.kondapaneni at rcware.eu> wrote:
> Hi everyone,
>
> during creation of lexer for our language I have run across one
> trouble. My lexer rules looks as follows:
>
> Special_PERIOD : '.';
> Special_DOUBLE_PERIOD : '..';
>
> //
> fragment DIGIT
> : '0'..'9';
> //
> fragment FIXEDPOINTNUMBER
> : INTEGERNUMBER Special_PERIOD INTEGERNUMBER;
>
> fragment INTEGERNUMBER
> : DIGIT ('_'? DIGIT)*;
> //
> Literal_INTEGER
> : INTEGERNUMBER;
>
> Literal_REAL
> : FIXEDPOINTNUMBER ( 'e' ('+'|'-')? INTEGERNUMBER )?;
>
> and lexer generated from these throws MismatchedRange exception
> during parsing of input like:
>
> "1234.." or "1234. something",
>
> because it automatically choose to start with Literal_REAL instead
> of Literal_INTEGER and it fails when it comes to the second period
> (or anything which differs from a digit). I have tried to put there
> an syntactic predicate to real and integer rules, but that obviously
> didn't worked, because there is always only one possibility how to
> expand.
>
> To summarize, I would like to parse string "1234.." to
> "Literal_INTEGER Special_DOUBLE_PERIOD" tokens
>
> So, have anyone an idea, how to solve it in lexer definition?
>
> Thanks in advance.
>
> --
> Ivo Kondapaneni
> programátor
> Energocentrum Plus, s.r.o.
>
> Mobile: +420 739 074 964
>
> http://energocentrum.cz, http://rcware.eu
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090724/f8642f63/attachment.html
More information about the antlr-interest
mailing list