[antlr-interest] Problems defining a simple Integer Match

Marwan Ajraoui marwan.alephn at gmail.com
Mon May 4 12:00:55 PDT 2009


MANY THX; The problem is solved thanks to the information you gave me.

Kind regards,

Marouane

2009/5/4 Jim Idle <jimi at temporal-wave.com>:
> Marwan Ajraoui wrote:
>> Hi There;
>>
>> I'm currently defining a grammar for a based tag language using ANTLR;
>> The problem I'm facing is that a single digit doesn't match my defined
>> rule INTEGER, here is the definition I put (as i saw in The Definitive
>> guide of ANTLR):
>>
>> DIGITO: '0'..'9' ;
>> INT : DIGITO + ;
>>
>> This rule should match any digit, but does match only numbers that are
>> composed of tow or more digits, like 45, 0567, etc. Numbers as 0, 7 or
>> 5 doesn't match.
>>
>> I will be gratefull, if you give me any issue about it;
>>
> You probably are best reading through the example grammars to get a full
> understanding, but here both of your lexer rules can match digits so the
> best ANTLR can do is realize that INT is selected when there are more
> than one DIGITs because DIGIT0 can only match 1 digit.
>
> You cannot have two rules that match the same thing basically. When you
> want to use a rule as sort of 'subroutine' that does not create any
> tokens itself, then you need to mark it as a fragment. Then it will
> generate code that can be called by other rules but will not try and
> create tokens itself.
>
> fragment DIGITO: '0'..'9' ;
> INT : DIGITO + ;
>
>
> Jim
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>



-- 
Marouane


More information about the antlr-interest mailing list