[antlr-interest] Lexing problem I cannot resolve

Carter Cheng carter_cheng at yahoo.com
Tue Aug 5 20:06:28 PDT 2008


I apologize for the delayed reply here but I have been trying various things to try to get this to work without much luck. I have a simpler case which is a part of my grammar which is-

[1..]

now: 

[1 .. ]  

parses properly but the previous rule gives a no valid alts error on the '.' which makes me believe it's still parsing it as a float. The rule I am currently using is this-

INTEGER_V	

	: Digit+ ( ('..') => | '.' Digit* { $type = FLOAT_V; } )  

//	| ( '0' ('x'|'X') ) => '0' ('x'|'X') (Digit|'a'..'f'|'A'..'F')+
//        | ('.' Digit+) => '.' Digit+ { $type = FLOAT_V; }
	;

I am not sure how merging in the '..' would help here. Since I expect that would only possibly be of use disambiguating '..' from '.' Digit+.

Thanks again,

Carter.


--- On Sun, 8/3/08, Gavin Lambert <antlr at mirality.co.nz> wrote:

> From: Gavin Lambert <antlr at mirality.co.nz>
> Subject: Re: [antlr-interest] Lexing problem I cannot resolve
> To: carter_cheng at yahoo.com, antlr-interest at antlr.org
> Date: Sunday, August 3, 2008, 1:39 PM
> At 08:11 4/08/2008, Carter Cheng wrote:
>  >Thanks for the replies both. I have been trying this
> and it 
> still
>  >does not seem to lex properly. Am I still doing
> something wrong? 
> 
>  >This is with ANTLR 3.0.1
> [...]
>  >INT	
>  >	: Digit+ ( ('..') =>
>  >        | '.' Digit* { $type = FLOAT; } )?
>  >
>  >	| ( '0' ('x'|'X') ) =>
> '0' ('x'|'X')
> (Digit|'a'..'f'|'A'..'F')+
>  >        | ('.' Digit+) => '.'
> Digit+ { $type = FLOAT; }
>  >	;
> 
> Hmm.  First of all, make sure that the FLOAT rule is a
> fragment 
> rule -- doesn't matter what's in it (since
> it'll never be called), 
> but it must not be a top-level candidate:
>    fragment FLOAT: Digit;
> 
> If that doesn't help, then you might need to merge the
> DOTDOT and 
> INT rules, as I said before.  But where and how is it
> failing?
> 
> (A useful thing to do here is to try running the lexer in 
> isolation and dump the generated tokens to screen/file, so
> you can 
> see what tokens are being generated and what each token
> contains.)


      


More information about the antlr-interest mailing list