try using the Number lexer rule from the Sun Java lexer posted on the Antlr site.
The Number rule handles Float and Int as well as hex and octal values. The resulting tokens are Float or Int. On 11/7/11 4:47 PM, "John B. Brodie" <[email protected]> wrote: >On 11/07/2011 12:32 PM, Jim Idle wrote: >> Better to do this: >> >> fragment FLOAT; >> INT : '0'..'9'+ ( '.' '0'..'9'+ { $type = FLOAT; } | ) ; > >and of course the above REQUIRES at least one digit to the left of the >decimal place on FLOAT. which is not what the OP had. but is easily >fixed, i believe, as: > >FLOAT : '.' '0'..'9'+ ; >INT : '0'..'9'+ ( '.' '0'..'9'+ { $type = FLOAT; } )? ; > >(note that i also replaced the empty alternative with use of the `?` >meta-operator. i think the meta-operator is stylistically clearer, but >maybe there is some other reason not to use it?) > >> >> Cheers, >> >> Jim >> >>> -----Original Message----- >>> From: [email protected] [mailto:antlr-interest- >>> [email protected]] On Behalf Of yushang >>> Sent: Monday, November 07, 2011 2:17 AM >>> To: [email protected] >>> Subject: Re: [antlr-interest] missing MATCHRANGE macro >>> >>> Hi, >>> I think I've found the reason . I've written a rule as follow >>> numeric_literal >>> : '0'..'9' ('0'..'9')* >>> | ('0'..'9')* '.' '0'..'9' ('0'..'9')* >>> ; >>> which will be translated to MATCHRANGE in Parser , if I change it to >>> this : >>> numeric_literal >>> : INT >>> | FLOAT >>> ; >>> INT >>> : '0'..'9' ('0'..'9')* >>> ; >>> FLOAT >>> : ('0'..'9')* '.' '0'..'9' ('0'..'9')* >>> ; >>> will OK. Many thanks. >>> >>> 2011/11/5 yushang <[email protected]> >>> >>>> Hi , I'm using ANTLR v3 C runtime and found this macro is missing >>> from >>>> the generated *Parser.c and *Parser.h . This macro can be found in >>>> *Lexer.c file . Is this a bug ? >>>> thanks in advance . >>>> >>> >>> List: http://www.antlr.org/mailman/listinfo/antlr-interest >>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- >>> email-address >> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest >> Unsubscribe: >>http://www.antlr.org/mailman/options/antlr-interest/your-email-address > > >List: http://www.antlr.org/mailman/listinfo/antlr-interest >Unsubscribe: >http://www.antlr.org/mailman/options/antlr-interest/your-email-address 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.
