[antlr-interest] missing MATCHRANGE macro

Douglas Godfrey douglasgodfrey at gmail.com
Tue Nov 15 08:49:45 PST 2011


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" <jbb at acm.org> 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: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>>> bounces at antlr.org] On Behalf Of yushang
>>> Sent: Monday, November 07, 2011 2:17 AM
>>> To: antlr-interest at antlr.org
>>> 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 <yusunn at gmail.com>
>>>
>>>> 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




More information about the antlr-interest mailing list