[antlr-interest] Lexing problem I cannot resolve

Carter Cheng carter_cheng at yahoo.com
Wed Aug 6 08:37:54 PDT 2008


Thanks for the reply. You are quite correct I added the ? to the lexer rule. Unfortunately it still complains of a no viable alt exception on the '.'. I reduced the grammar to this to try to locate the problem. I ran it through AntlrWorks and still seems to return a FLOAT token for "1..". Hopefully I am still in error here somehow :-).

Thanks again,

Carter.



--- On Wed, 8/6/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: Wednesday, August 6, 2008, 4:23 AM
> At 15:06 6/08/2008, Carter Cheng wrote:
>  >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-
> [...]
>  >INTEGER_V	
>  >	: Digit+ ( ('..') => | '.' Digit*
> { $type = FLOAT_V; } )
>  >	;
> 
> You're missing a ?.  Right at the end of the rule you
> need a ? 
> after the closing parenthesis, since Digits are not
> necessarily 
> followed by any kind of dot.
> 
> INTEGER_V	
>    : Digit+ ( ('..') => | '.' Digit* {
> $type = FLOAT_V; } )?
>    ;
> 
> Follow through each part of that and you should see how it
> works:
>    - first match a sequence of one or more Digits
>    - optionally followed by one of:
>      - if you see two dots in lookahead: nothing
>      - otherwise, match a dot and zero or more Digits and
> call it 
> a FLOAT_V
> 
> Without the ?, ANTLR will complain if it can't see a
> dot following 
> the initial Digits, since it doesn't have anywhere else
> to go.


      
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.g
Type: application/octet-stream
Size: 278 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080806/83b17f53/attachment.obj 


More information about the antlr-interest mailing list