[antlr-interest] A little problem with DOT in numbers and as line
terminators.
Sebastian Kaliszewski
sk at z.pl
Fri Mar 11 03:28:48 PST 2005
On Thursday 10 March 2005 23:52, Eric Merritt wrote:
> I am using a dot as both a decimal separator in numbers and a
> statement terminator. I run into a problem when a number is at the end
> of a statement. For example
>
> origin := 0 @ 0.
>
> Gives me huge problems because the NUMBER rule consumes the '.' and
> automatically expects another digit. When it doesn't find one it dies
> because it doesn't find the expected digit. What I need to to do is
> check the character after the '.' to see if it is a number. If a
> number follows it should continue to consume normally. If not it
> should unconsume the '.' and terminate the number rule. That would
> allow the '.' to be consumed by the DOT rule and form the expected
> statement terminator. Of course, I will still have problems with
>
> origin := 0 @ 0.
> 0 + 33.
>
> but I will cross that bridge when I come to it.
But it possible that it's the cause of the problem.
>
> I played around with semantic predicates and these will allow me to
> look ahead, but these will only allow the rule to continue or an
> exception to be thrown. Throwing an exception isn't the right
> solution.
But di you try syntactic predicate? i.e. ('.' DIGIT)=>
> Following is the number rule, I will gladly provide the
> entire grammar if there is a need.
>
>
> // a numeric literal
> NUMBER
>
> : (DIGIT DIGIT 'r')? (DIGIT)+ ('.' (DIGIT)+ EXPONENT)?
> ;
>
Did you try:
NUMBER
: (DIGIT DIGIT 'r')? (DIGIT)+ (('.' DIGIT)=> ('.' (DIGIT)+ EXPONENT))?
rgds
--
Sebastian Kaliszewski
More information about the antlr-interest
mailing list