You might try the following:

fragment IP : ;
fragment IPNET : ;

NUMBER
  : NumberFormat
    ( POINT NumberFormat POINT NumberFormat POINT NumberFormat {$type =
IP;}
      ( SLASH NumberFormat {$type = IPNET;}
      )?
    )?
  ;

NumberFormat
  : '0' | '1'..'9' DIGIT*
  ;

Then validate a proper IP either at the end of the number rule, or
possibly in the parser, so you can print an informative message about a
malformed IP.

Sam

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of micha
Sent: Tuesday, November 18, 2008 6:54 AM
To: [EMAIL PROTECTED]
Subject: [antlr-interest] possible bug?

the followinig lexer grammar:
 lexer grammar Lexbug;

 SLASH: '/';
 POINT: '.';

 fragment DIGIT: '0'..'9';
 fragment BYTE: DIGIT | '1'..'9' DIGIT | '1' DIGIT DIGIT | '2' '0'..'4'
 DIGIT | '25' '0'..'6';

 IP: BYTE POINT BYTE POINT BYTE POINT BYTE;
 NUMBER: '0' | '1'..'9' DIGIT*;


produces 13kb of java code and all works well.

If I add the definition:
 IPNET: IP SLASH NUMBER;

then I get 22MB output (!)

Is this o.k.? I didn't thought, that this rule requires so much code :-)

cheer
 Michael





List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-addr
ess


List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-interest@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to