Thanks Jim, the link looks very useful, albeit a bit daunting. I tried
amending my FLOAT to:

FLOAT
    :   ('0'..'9')+ ({input.LA(2) >= '0' && input.LA(2) <= '9'}?=>'.')
('0'..'9')+ EXPONENT?
    |   '.' ('0'..'9')+ EXPONENT?
    |   ('0'..'9')+ EXPONENT
    ;

Unfortunately I get a "rule FLOAT failed predicate" error.

On Fri, Jan 29, 2010 at 6:02 PM, Jim Idle <[email protected]> wrote:

> Please see the FAQ and complete grammar at:
>
>
> http://antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+point%2C+dot%2C+range%2C+time+specs
>
>
> All you need do is add to the predicate here:
>
>                |   // We can of course have 0.nnnnn
>                    //
>                    { input.LA(2) != '.'}?=> '.'
>
> To check :
>
> { input.LA(2) != '.' && input.LA(2) >= '0' && input.LA(2) <= '0' }?=> '.'
>
> Then remove the empty alt there that allows number forms like 8.
>
> Jim
>
> > -----Original Message-----
> > From: [email protected] [mailto:antlr-interest-
> > [email protected]] On Behalf Of Scott Oakes
> > Sent: Friday, January 29, 2010 9:43 AM
> > To: [email protected]
> > Subject: [antlr-interest] Lexer for floating point numbers + field
> > access syntax with '.'
> >
> > Hi, hoping for some help trying to write a lexer that allows you to
> > recognise floating point literals (2.3) as well as field accesses of
> > the
> > form x.y; see grammar below. The trouble is that an input like
> >
> >   3.fieldAccess
> >
> > Produces two tokens, FLOAT and ID, rather than the desired three, INT,
> > DOT
> > and ID.
> >
> > Pointers would be much appreciated!
> >
> > -------------------
> >
> > grammar test;
> >
> > top: expr EOF;
> >
> > expr: (INT | FLOAT | ID | '(' expr ')') (DOT ID)*;
> >
> > ID  :    ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
> >     ;
> >
> > INT :    '0'..'9'+
> >     ;
> >
> > DOT: '.';
> >
> > FLOAT
> >     :   ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
> >     |   '.' ('0'..'9')+ EXPONENT?
> >     |   ('0'..'9')+ EXPONENT
> >     ;
> >
> > WS  :   ( ' '
> >         | '\t'
> >         | '\r'
> >         | '\n'
> >         ) {$channel=HIDDEN;}
> >     ;
> >
> > fragment
> > EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
>

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to