[antlr-interest] lexer problem...
Lloyd Dupont
ld at galador.net
Fri Jul 20 20:56:03 PDT 2007
Yeah man, that did it!!! :D
Big Thanks!
----- Original Message -----
From: Jim Idle
To: antlr-interest at antlr.org
Sent: Friday, July 20, 2007 2:30 AM
Subject: Re: [antlr-interest] lexer problem...
I think that this question points out that many of us expect ATNLR to "just work it out" for us. All these problems are best solved with a mind experiment first "How would you scan it with the eye?", then break the rule at the different alternatives yourself and stick in the lookahead you perform with your mind. It will result in better generated code anyway:
grammar fred;
stat
: test+
;
test
: (INT DOT ID)
| FLOAT
;
fragment
DIGIT : '0'..'9'
;
FLOAT : INT
(
('.' INT)=> '.' INT
| {$type = INT; }
)
;
DOT : '.' ;
Fragment // Also ensures a token type INT is present
INT : DIGIT+;
ID : ('A'..'Z' | 'a'..'z')+
;
Jim
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Lloyd Dupont
Sent: Thursday, July 19, 2007 6:13 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] lexer problem...
I have the following lexer rule:
==============
FLOAT : ('0'..'9')+ '.' ('0'..'9')+ (EXPONENT_PART)? (FLOAT_TYPE_SUFFIX)?
;
==============
as you can see: it require 1 or more number on both side of the DOT
my problem is that with the follwoing input:
====
1.ToString()
====
instead of returning INT DOT ID
it apparently try to return a FLOAT and I have the following error message when trying on the command line:
====
line 1:2 required (...)+ loop did not match anything at character 'T'
====
Any idea how to solve this lexer problem??
Thanks! :D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070721/e613342c/attachment-0001.html
More information about the antlr-interest
mailing list