[antlr-interest] Problem with Self 4.1 grammar

Jim Idle jimi at temporal-wave.com
Mon Mar 24 03:27:43 PDT 2008


Gavin Lambert wrote:

Actually I don't think that will work because it will see the '.' and 
eat it with the First Decimal, which is probably not what is wanted, but 
it would work if it was what was wanted of course. Either Integer, Real 
or Eol ('.') is what I think is being looked for?

Jim
> 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