[antlr-interest] Lexing problem I cannot resolve

Carter Cheng carter_cheng at yahoo.com
Wed Aug 6 12:07:32 PDT 2008


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.

--- On Wed, 8/6/08, Loring Craymer <lgcraymer at yahoo.com> wrote:

> From: Loring Craymer <lgcraymer at yahoo.com>
> Subject: Re: [antlr-interest] Lexing problem I cannot resolve
> To: "Carter Cheng" <carter_cheng at yahoo.com>, antlr-interest at antlr.org
> Date: Wednesday, August 6, 2008, 10:18 AM
> Try
> fragment DIGIT: '0'..'9';
> fragment DOTDOT : '..' ;
> RANGE: DOTDOT ;
> INT
>    : DIGIT+ 
>     (     (DOTDOT) => |
>           ( '.' DIGIT* { $type = FLOAT; } )? )
>    ;
>    
> fragment FLOAT : DIGIT;     
> 
> and then editing to see how close you can get to the
> original.  The DOTDOT takes advantage of ANTLR 3's lack
> of FOLLOW sets (INT does not look for a '.' when
> evaluating the synpred).  Otherwise, your last version is
> technically correct.
> 
> --Loring
> 
> 
> 
> ----- Original Message ----
> > From: Carter Cheng <carter_cheng at yahoo.com>
> > To: antlr-interest at antlr.org
> > Sent: Wednesday, August 6, 2008 8:37:54 AM
> > Subject: Re: [antlr-interest] Lexing problem I cannot
> resolve
> > 
> > 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 wrote:
> > 
> > > From: Gavin Lambert 
> > > 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: 529 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080806/011140ba/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.s
Type: application/octet-stream
Size: 4 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080806/011140ba/attachment-0001.obj 


More information about the antlr-interest mailing list