[antlr-interest] Someting about range (to change)

Bart Kiers bkiers at gmail.com
Wed Jun 29 04:32:42 PDT 2011


Hi Fabien,

Note that the fact that `..` (let's call it DOT_DOT) does not appear in a
lexer rule, there _is_ a token being created because you defined DOT_DOT inside
a parser rule.

The lexer has a problem with input like:

  123..

The lexer tries to construct a LEFTY from it instead of a DEC_NUMBER
followed by a DOT_DOT.

Better let LEFTY _not_ possibly start with a Digit:

    LEFTY : Letter ('.' | Letter | Digit | '-')* '[';

Bart.


On Wed, Jun 29, 2011 at 7:53 AM, Fabien Hermenier <hermenierfabien at gmail.com
> wrote:

>  Hi Bart
>
> Here is. It's just a change in LEFTY:
> ---
>
> fragment Digit :'0'..'9';
> DEC_NUMBER: '1'..'9' Digit*;
>
> fragment Letter    :'a'..'z'|'A'..'Z';
>
> WS    :    ('\n'|'\r'|'\t'|' ') {$channel=HIDDEN;};
> LEFTY: (Letter|Digit) ('.'|Letter|Digit|'-')* '[';
> RIGHTY: ']' (('-' (Letter|Digit))|Letter|Digit)* ;
>
> number :DEC_NUMBER;
>
> range: LEFTY number '..' number RIGHTY;
> ---
>
> Le 28/06/11 23:51, Bart Kiers a écrit :
>
> Hi Fabien,
>
>  Can you post the grammar that produces the error?
>
>  Bart.
>
>
> On Wed, Jun 29, 2011 at 5:57 AM, Fabien Hermenier <
> hermenierfabien at gmail.com> wrote:
>
>> Hi
>>
>> I am sorry, but this is another problem related to sequence of integer.
>> I don't understand my error(s), despite severals
>> pass on the wiki page related to this use case.
>>
>> I want to parse a string with a "sequence" parameter into it, such as
>> "toto-[2 ..3]-toto".
>> Here is a short version of the grammar that works perfectly:
>> ---
>> grammar tryout;
>>
>> options {
>>     k=3;
>> }
>> fragment Digit :'0'..'9';
>> DEC_NUMBER: '1'..'9' Digit*;
>>
>> fragment Letter    :'a'..'z'|'A'..'Z';
>>
>> WS    :    ('\n'|'\r'|'\t'|' ') {$channel=HIDDEN;};
>> LEFTY: (Letter|Digit) (Letter|Digit|'-')* '[';
>> RIGHTY: ']' (('-' (Letter|Digit))|Letter|Digit)* ;
>>
>>
>> number :DEC_NUMBER; //HEX_NUMBER, OCT_NUMBER, ... are following but
>> removed for this example.
>>
>> range: LEFTY number '..' number RIGHTY;
>> ---
>>
>> This grammar accepts "toto-[1..3]-toto" or "toto-[1 .. 3]-toto".
>> Now, I want to be able to accept the LEFTY token or the RIGHTY token
>> even if they contains a '.' inside (not at the beginning). So I've
>> modified LEFTY as following:
>> LEFTY: (Letter|Digit) ('.'|Letter|Digit|'-')* '[';
>>
>> Now, ANTLR does no longer accept "toto-[1..3]-toto". It requires at
>> least one space between the first number and the range.
>> I have read the wiki page related to range, integer, and so one. But in
>> my case, I don't see where my grammar is ambiguous as no token
>> can start with a '.' . So it seems there is a concept I don't get. Can
>> anyone try to help me ?
>>
>> Thanks in advance,
>> Fabien.
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>
>
> --
> postdoctoral researcher at Flux
> School of Computing, University of Utahhttp://sites.google.com/site/hermenierfabien/home
>
>


More information about the antlr-interest mailing list