[antlr-interest] Lexing problem I cannot resolve
Thomas Brandon
tbrandonau at gmail.com
Wed Aug 6 12:51:34 PDT 2008
The grammar below parses the lines of the input (Note the final line
is required given the grammar):
1
1.0
1.
.1
1..0
as INT, FLOAT, FLOAT, FLOAT and INT RANGE INT respectively. You should
bea ble to get what you want out of that. Tested under ANTLR 3.0.1.
Grammar:
grammar test;
test
:( ( int1
| float1
| range
) NL
)+ EOF
;
int1 : INT;
float1
: FLOAT;
range
: INT RANGE INT;
fragment DIGIT: '0'..'9';
RANGE: '..' ;
INT
: DIGIT+ ( ('.' ~'.')=> '.' DIGIT* {$type=FLOAT;} )?
;
FLOAT: '.' DIGIT+;
NL : ('\n'|'\r')+;
Tom.
On Thu, Aug 7, 2008 at 5:07 AM, Carter Cheng <carter_cheng at yahoo.com> wrote:
> I tried this variant too but it does not seem to parse correctly(see attached). It still thinks that the 1. is a FLOAT token. Perhaps I have run afoul of some bug in 3.0.1?
>
> Regards,
>
> Carter.
>
More information about the antlr-interest
mailing list