[antlr-interest] NOT in v3

Jim Idle jimi at temporal-wave.com
Mon Mar 12 12:36:24 PDT 2007


While there are a few approaches to this, I suspect (without looking up
the IP6 space ;-), that if we assume there is always one ':' leadin and
then one "empty" field (or perhaps there is optionally something else
there, but this approach would make that easy too),  then you want to
view the ':' as the terminator of the last field rather then the
introducer to the next field, which give you:

grammar ac;

addr
	: ':' ':' ( ac ':' )+
			 ac '.' ac '.' ac '.' ac
	;
	
ac	: (HEX | DEC) ((HEX |DEC) (HEX|DEC)?)?
	;
	
HEX : 'a'..'f';
DEC	: '0'..'9';

With appropriate tweaks to actually match the real requirements, but
this gives you the idea I hope.

You could also use predicates and so on to look for the '.', but it is
always best to express the grammar such that these things are not
needed, if possible.

Jim

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mark Bednarczyk
Sent: Monday, March 12, 2007 11:54 AM
To: 'ANTLR Interest'
Subject: [antlr-interest] NOT in v3

I'm trying to use a NOT (~x) in a production, but keep getting internal
error whenever the ! character appears in any of the rules. Here is one
such
rule:
 
myrule
	:	':' (':' ac ~(':' ac '.') )+ 	
		':' ac '.' ac '.' ac '.' ac
		-> ^(IP6C ':' ac*)	

When I remove the ~(..) part, it compiles, but doesn't match. I'm trying
to
specify a condition to terminate the ()+ production so that the parser
will
move on to the second line. Otherwise it seems to be too greedy and
matches
1 too many ac subrules and the latter part never gets matched. (i.e.
input="::ff:192.168.1.1")

Any ideas or is it something I'm doing wrong?

Cheers,
mark...




More information about the antlr-interest mailing list