[antlr-interest] Lexing problem I cannot resolve
carter_cheng at yahoo.com
Sun Aug 3 04:01:37 PDT 2008
Thanks for the reply. I think that will only disambiguate between the .2 and .. cases and not the example I am describing in this case.
The problem is the entry point into the FSA would be the leading digit and therefore the range rule will not be considered at all. The only thing I can think of but I am not sure how to state it in ANTLR is to use the syntax predicates and do something as follows.
digit+ '...'=> (return an int) /* int followed by ellipsis */
digit+ '..' => (return an int) /* int followed by range */
digit+ '.' => (possible float value) /* float or error */
Or is this wrong?
--- On Sun, 8/3/08, Raphael Reitzig <r_reitzi at cs.uni-kl.de> wrote:
> From: Raphael Reitzig <r_reitzi at cs.uni-kl.de>
> Subject: Re: [antlr-interest] Lexing problem I cannot resolve
> To: antlr-interest at antlr.org
> Date: Sunday, August 3, 2008, 3:41 AM
> Hi Carter!
> Moving range rule above float rule should do the job. ANTLR
> the first matching rule it discovers, testing bottom down.
> "Carter Cheng" <carter_cheng at yahoo.com>
> wrote (Sun Aug 3 12:16:38 2008):
> > Hi,
> > Yet another beginner's question. I have been
> having difficulties
> > with a lexing ambiguity and I am curious how one would
> go about
> > resolving it with ANTLR. The problem I am having is
> follows. I have
> > a grammar with a standard C like INT FLOAT lexing
> rules but I also
> > have the ellipsis ... and range .. tokens in the
> grammar. The
> > difficulty I am having is with this instance string:
> > 1..2
> > Which the lexer seems to like to lex as two FLOATS as
> oppose to as
> > INT RANGE INT. In the language in question FLOAT FLOAT
> is illegal
> > but obviously the lexer cannot know that. Is there a
> way to resolve
> > this in ANTLR cleanly?
> > Thanks in advance,
> > Carter.
> This message was sent using IMP, the Internet Messaging
More information about the antlr-interest