[antlr-interest] Emit two Tokens in one Lexer Rule
    Gavin Lambert 
    antlr at mirality.co.nz
       
    Tue Feb 12 11:25:30 PST 2008
    
    
  
At 02:16 13/02/2008, Alexander Gängel wrote:
 >
 >My problem it that I have to decide if I have 
an Float like  1.1 or
 >an Int DOT Identifiert lik 5.max
 >My workaround would be to emit just the first an restart lexing
 >from the last correct charterer. So I would Just emit 5 as Int
 >and reparse from the Dot.
Which is easy enough with a syntactic predicate:
fragment FLOAT: NUMBER DOT NUMBER;
INT
   : NUMBER
     ((DOT NUMBER) => DOT NUMBER { $type = FLOAT; })?
   ;
fragment NUMBER: DIGIT+;
fragment DIGIT: '0'..'9';
    
    
More information about the antlr-interest
mailing list