[antlr-interest] ambiguity

Jim Idle jimi at temporal-wave.com
Sat Jan 28 11:54:50 PST 2012


elem_array: elem* EOF;

elem: SPACE // The final frontier
     (
       | LETTER_A LETTER_A
       | LETTER_B LETTER_B
       | LETTER_C LETTER_C
       | LETTER_D LETTER_D
     )
;

Should do it. You are basically trying to avoid ? in two rules, one higher
than the other, which leads to ANTLR not able to decide which path to take
when nothing is there.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Cristian Tārsoaga
> Sent: Saturday, January 28, 2012 10:56 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] ambiguity
>
> Hi everybody,
>
> I have a very simple grammar I cannot parse
>
>
> elem_array: elem*;
>
> elem: (SPACE LETTER_A LETTER_A)? (SPACE LETTER_B LETTER_B)? (SPACE
> LETTER_C LETTER_C)? (SPACE LETTER_D LETTER_D)?;
>
>
>
> Thing is, all 4 components of an element start with a space, all are
> optional, and such elements can be repeated.
>
> 1. I tried to use a big lookahead, it does not solve my problem.
> Can somebody explain why a k=100 does not solve it?
>
> 2. What is the solution to something like this? Predicates? How?
>
>
> Thanks a lot
> Chris
>
> 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