[antlr-interest] ambiguous grammar

Anakreon Mejdi amejdi at ertonline.gr
Mon Jan 20 05:30:38 PST 2003


  component:
    DOLLAR^ FLOAT
    ;
This should work.
There is no DOT because in the NUMBER rule if an DIGIT is matched the 
type is made FLOAT and the DOT is consumed.
For the same reason there is no NUMBER Token.

beeh1973 wrote:
> hi,
> 
> in my language i have float literals like .1 and
> expressions like $.1
> 
> i am using the following lexer rule to recognize numbers
> 
> NUMBER
>  : '.'        { _ttype = DOT; }            // a single dot
>    (((DIGIT)+ { _ttype = FLOAT} )          // a float number
>    ((EXPONENT))?)?
>  |
>    // some more cases for integers and floats > 1
>   ...
> 
> DOLLAR : '$' ;
> 
> 
> in the parser i try to match $.1 with this rule:
> 
> component:
>   DOLLAR^ DOT NUMBER
>   ;
> 
> while parsing $.1 i get an error that FLOAT is unexpected at that 
> point.
> 
> while i understand why this is happening; a call to nextToken simply
> returns the next token which is a FLOAT no DOT, i do not understand 
> how to
> fix the grammar. can anybody help me with this?
> 
> thanks in advance,
>         alphonse bendt
> 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list