[antlr-interest] Using range operator (INT .. INT)

Jiwon Seo jiwon at stanford.edu
Sun Nov 13 09:58:01 PST 2011


I attached a simplified grammar file with the problem.
If you run the interpreter in antlrworks 1.4.3 the following will give an error

int n:0..10

But the following won't give an error:

int n:0 .. 10    // white space before and after ..


Note that my definition of FLOAT does not conflict with the range operator:

FLOAT
    :   ('0'..'9')+ '.' ('0'..'9')+ EXPONENT?
    |   ('0'..'9')+ EXPONENT
    ;


Thanks.

On Sun, Nov 13, 2011 at 3:09 AM, Christian <chwchw at gmx.de> wrote:
> Hello Jiwon,
>
> first, try to write a simple minimal grammar that represents your
> usecase because I do not see anything that explains the behavior you
> described. Maybe there are some other rules that influence the parsing.
>
> Tell us afterwards.
>
> Regards,
> Christian
>
> Am 13.11.2011 10:31, schrieb Jiwon Seo:
>> I'm trying to add range operator in my language, and I'm having a
>> problem with it.
>>
>> The range operator is defined as following:
>>
>> range: INT '..' INT ;
>>
>> where INT is '0'..'9'+
>>
>> I do have FLOAT, but it is defined such that it does not have conflict
>> with the range operator:
>>
>> FLOAT: ('0'..'9')+'.'('0'..'9')+ EXPONENT?
>>             | ('0'..'9')+ EXPONENT
>>           ;
>>
>> The thing is, if I use the range operator with white spaces before &
>> after the dots(such as 10 .. 100), it parses fine
>> But without the white spaces(such as 10..100), it says
>> 'MismatchedTokenException' .
>>
>> Can anyone see why it's acting like that? I do not use dot ('.') in
>> any other places.
>>
>> I'm using antlrworks 1.4.3 for writing grammar and testing it
>> (interpreter & debugger)
>>
>> Thanks.
>>
>> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple.g
Type: application/octet-stream
Size: 1342 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20111113/ad587ed4/attachment.obj 


More information about the antlr-interest mailing list