[antlr-interest] how to put lexer rules syntactic check
Ivo Kondapaneni
ivo.kondapaneni at rcware.eu
Fri Jul 24 07:21:19 PDT 2009
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090724/1cf71711/attachment.html
More information about the antlr-interest
mailing list