[antlr-interest] Relaxed number format lexer problem
    Sam Harwell 
    sharwell at pixelminegames.com
       
    Wed Apr 22 09:40:46 PDT 2009
    
    
  
I'm using a heavily relaxed NUMBER token in my lexer so I can provide
better error messages. The problem I'm having occurs when input such as
1..2 is reached. The '..' should be an OP_RANGE token, not part of the
number.
 
NUMBER
@after
{
ClassifyNumber($text);
}
        :       '.'? '0'..'9'
                (       // <-- It throws a NoViableAltException at this
decision when next the input is '..'
                        (       '0'..'9'
                        |       'a'..'d'
                        |       'f'..'z'
                        |       'A'..'D'
                        |       'F'..'Z'
                        |       ('.' ~'.') => '.'
                        )
                |       ('e' | 'E')
                        (       ('+'|'-') => ('+' | '-')?
                                '0'..'9'
                        )?
                )*
        ;
 
I found that I had to rearrange the rule in a strange way to get rid of
the error:
 
NUMBER
@after
{
ClassifyNumber($text);
}
        :       '.'? '0'..'9'
                (       (       (       '0'..'9'
                                |       'a'..'d'
                                |       'f'..'z'
                                |       'A'..'D'
                                |       'F'..'Z'
                                )
                        |       '.' ('0'..'9' | 'a'..'d' | 'f'..'z' |
'A'..'D' | 'F'..'Z')
                        |       '.'? ('e' | 'E')
                                (       ('+'|'-') => ('+' | '-')?
                                        '0'..'9'
                                )?
                        )
                )*
                (       ('.' ~'.') => '.'
                )?
        ;
 
Thank you,
Sam Harwell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090422/acaf16fe/attachment.html 
    
    
More information about the antlr-interest
mailing list