[antlr-interest] Ambiguous grammar
Jim Idle
jimi at temporal-wave.com
Wed May 26 13:50:46 PDT 2010
Please see the FAQ:
http://www.antlr.org/wiki/display/ANTLR3/Lexer+grammar+for+floating+point%2C+dot%2C+range%2C+time+specs
Also note that there is a search engine:
http://antlr.markmail.org
For this group, and it is really good:
http://antlr.markmail.org/search/?q=range
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Ondrej Krc-Jediny
> Sent: Wednesday, May 26, 2010 1:34 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Ambiguous grammar
>
> 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.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
More information about the antlr-interest
mailing list