Fwd: [antlr-interest] Lexer not as smart as it should be?

Suman Karumuri mansuk at gmail.com
Fri Oct 21 12:16:04 PDT 2005


This seems to work as well(atleast no non-determinism error). As antlr
generates codes, which itself is means that there is no
non-determinism.However, when i give an input i get an exception that is in
bold. It can be fixed by adding a condition for WS.

--------------------------------------
options {
language = "Python";
}
class Ilexer extends Lexer;
options {
k = 1;
}

protected
INT: ('0'..'9')+
;

IP: a:INT '.' b:INT '.' c:INT '.' d:INT
{
if(int(a.text)<255):
print a.text
add other range checks in this rule.
}


suman at suman:~/temp$ python Ilexer.py
2.2.2.2 <http://2.2.2.2>
2
["2.2.2.2 <http://2.2.2.2>",<5>,line=1,col=1]
error: exception caught while lexing: unexpected char: 0xA
--------------------------------------------

>From what i understand syntactic predictes slow down the lexer .Correct me
if i am wrong.

-Suman
On 10/21/05, Jon Schewe <jpschewe at mtu.net> wrote:

> This worked:
>
> protected
> DIGIT
> :
> '0'..'9'
> ;
>
> protected
> IPNUM
> :
> DIGIT
> | (DIGIT DIGIT)
> | ('0'..'2' '0'..'5' DIGIT)
> ;
>
> protected
> INTEGER
> :
> ( DIGIT )+
> ;
>
> IP_OR_INTEGER
> :
> (IPNUM '.' IPNUM '.') => IP { $setType(IP); }
> | (DIGIT) => INTEGER { $setType(INTEGER); }
> ;
>
> protected
> IP :
> IPNUM '.' IPNUM '.' IPNUM '.' IPNUM '/' DIGIT (DIGIT)?
> ;
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051022/ae536726/attachment.html


More information about the antlr-interest mailing list