[antlr-interest] Problem with Self 4.1 grammar

Gavin Lambert antlr at mirality.co.nz
Mon Mar 24 04:12:12 PDT 2008


At 23:27 24/03/2008, Jim Idle 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.

Shouldn't do.  If the whole ". Decimal" block is made optional 
then the predicate should prevent it from consuming the dot if 
there aren't following digits, since having a predicate overrides 
the normally k=1 behaviour of the lexer.

Specifically:
   Real
     : Decimal
       ( ('.' Digit) => '.' Decimal )?
       ( ('e'|'E') ('+'|'-') Decimal )?
     ;

 >Either Integer, Real or Eol ('.') is what I think is being
 >looked for?

Probably, yes.  I was just offering an alternative solution (to 
always output Real, never Integer), in case the target language 
doesn't care about the distinction.  If the distinction *is* 
important then the explicit empty alt with type-reassignment that 
you proposed would be the better choice.  Maybe I didn't say that 
clearly enough :)



More information about the antlr-interest mailing list