Excellence Lexer ANTLR3

I want to create a token from '..'in the ANTLR3 lexis, which will be used to combine expressions like

a..b     // [1]
c .. x   // [2]
1..2     // [3] 
3 .. 4   // [4]

So I added

DOTDOTSEP : '..' 
          ;

The problem is that I already have a rule:

FLOAT : INT (('.' INT (('e'|'E') INT)? 'f'?) | (('e'|'E') INT)? ('f'))
      ;

And in the example [3] above it is 1..2compared as FLOAT(I’m not sure why, since after the first one .there is one more .not INT, but it is).

I wonder if there is a way to change the priority of lexer rules, so it DOTDOTSEPmaps first, then FLOAT.

Looking here, it seems like I'm losing, "The rule having the greatest count is the winner.",but I wonder if there is a way around it.

PS INT is defined as below ...

fragment DIGIT
    : '0'..'9'
    ;

INT : DIGIT+
    ;

Edit. , , FLOAT. ( , , .) ( ) lexer, .

+5
1

http://sds.sourceforge.net/src/antlr/doc/lexer.html?

, :

fragment
INT : DIGIT+
    ;

fragment
RANGE : INT DOTDOTSEP INT
      ;

fragment
FLOAT : INT (('.' INT (('e'|'E') INT)? 'f'?) | (('e'|'E') INT)? ('f'))
      ;

NUMBER
    : (INT '.') => FLOAT       { $type=FLOAT; }
    | (INT DOTDOTSEP) => RANGE { $type=RANGE; }
    | INT                      { $type=INT; }
    ;
+7

All Articles