[antlr-interest] Handling number Integer and real

Tamas Kerecsen kerecsen at gmail.com
Thu Aug 17 22:16:00 PDT 2006


Grab the examples from http://www.antlr.org/download/examples-v3.tar.gz and
look at the C parser to see how it's done. If you want to understand the
"why", borrow a good lex/yacc or other parser-related book from your local
library, or at least work your way though a few tutorials on the web.

I am new to antlr. I stuck with defining rules for numbers, such as
> integer and real.
>
> I defined the following rules. however, it gives warnings when I compile
> them.
>
> Rules:
> ==============================================
> INTEGER         :       ('+'|'-')? ('0'..'9')+ ;
> HEX_INTEGER     :       '0' ('x'|'X') ('0'..'9'|'A'..'F'|'a'..'f')+ ;
> BINARY_INTEGER  :       '0' ('b'|'B') ('0'..'9')+ ;
> REAL            :       ('+'|'-')? ( ('0'..'9')+ (('e'|'E') ('-'|'+')?
> ('0'..'9')+) |
> (('0'..'9')+ '.' ('0'..'9')* (('e'|'E')('-'|'+')? ('0'..'9')+)?) ) |
> ( '.' ('0'..'9')+ (('e'|'E') ('-'|'+')? ('0'..'9')+)? );
>
>
> Warnings:
> =============================================
> lexical nondeterminism between alts 1 and 2 of block upon k==1:'0'..'9'
> k==2:'0'..'9' k==3:'0'..'9','E','e'
>
> lexical nondeterminism between rules INTEGER and REAL upon
> k==1:'+','-','0'..'9' k==2:'0'..'9' k==3:<end-of-token>,'0'..'9'
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060817/f437dc59/attachment.html


More information about the antlr-interest mailing list