[antlr-interest] Ambiguous grammar
    Ondrej Krc-Jediny 
    ondro.krc at gmail.com
       
    Wed May 26 13:33:33 PDT 2010
    
    
  
Hello,
I am new to ANTLR and I'd appreciate help with my problem. At first
some grammar rules I am going to talk about:
DIGIT: '0'..'9';
LETTER: 'a'..'z'|'A'..'Z';
REAL
    :   (DIGIT)+ '.' (DIGIT)* EXPONENT?
    |   '.' (DIGIT)+ EXPONENT?
    |   (DIGIT)+ EXPONENT
    ;
INTEGER: DIGIT+;
IDENTIFIER: LETTER+;
range_expr:
  expr ('..' expr)?;
expr: expratom ('+' expratom)?;
expratom: INTEGER | REAL | IDENTIFIER;
This grammar allows '1.' and .1' as correct real numbers. Also, it
allows range expression '1..2', which gets parsed incorrectly as two
real numbers 1. and .2. Redefining token
INTEGER: DIGIT '..'?;
doesn't help, because then also valid range expression 'i + 1..2'. Is
there any way how to parse the '..' correctly in all cases?
Thank you very much,
Ondrej.
    
    
More information about the antlr-interest
mailing list