[antlr-interest] Lexing problem I cannot resolve

Gavin Lambert antlr at mirality.co.nz
Wed Aug 6 04:23:44 PDT 2008


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.



More information about the antlr-interest mailing list