[antlr-interest] Problem with Self 4.1 grammar

Gavin Lambert antlr at mirality.co.nz
Mon Mar 24 02:43:19 PDT 2008


At 21:11 24/03/2008, Carter Cheng wrote:
 >Real
 >	: Decimal ( ('.' Decimal) => '.' Decimal ) ( ('e'|'E') 
('+'|'-')
 >Decimal )?
 >	;

If you want 'Real' to be your only numeric token (encompassing 
both integral and decimal values), then an alternative to Jim's 
suggestion is to simply put a '?' after your ". Decimal" block.

One of the problems you're having here is that the predicate will 
have no effect, since it doesn't have an alternative.  Either 
explicitly putting in an empty alt (possibly with a type-change) 
as Jim suggested or using ? to make ANTLR internally generate the 
empty alt will resolve this.

 >Integer
 >	: Decimal
 >	| Base GeneralDigit+
 >	;
 >
 >Decimal
 >        : Digit+
 >        ;

Both of these rules should be fragment rules, as should any other 
rules they end up calling.



More information about the antlr-interest mailing list