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

Jiwon Seo jiwon at stanford.edu
Sun Nov 13 23:06:18 PST 2011


I did the following change:

FLOAT
    : ('0'..'9')+
    (
        {input.LA(2) != '.'}? => '.' ('0'..'9')+ EXPONENT? {$type = FLOAT;}
        |  {$type = INT;}
    )
    |  ('0'..'9')+ EXPONENT
    ;

I tested it inside antlrworks, and very strangely, it works fine with
the debugger(generates the right parse tree),
but raises Mismatched token exception with the interpreter.

Is the above right way to do this?


On Sun, Nov 13, 2011 at 5:10 PM, Jim Idle <jimi at temporal-wave.com> wrote:
> Please read the wiki articles - your rules conflict and there are simple
> ways around this :)
>
> Jim
>
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>> bounces at antlr.org] On Behalf Of Jiwon Seo
>> Sent: Sunday, November 13, 2011 9:58 AM
>> To: Christian
>> Cc: antlr-interest at antlr.org
>> Subject: Re: [antlr-interest] Using range operator (INT .. INT)
>>
>> 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-
>> addres
>> >> s
>> >>
>> >
>> >
>> > 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