[antlr-interest] How to best resolve ambiguity?

Terence Parr parrt at cs.usfca.edu
Fri Dec 30 17:13:19 PST 2005


On Dec 30, 2005, at 5:06 PM, Martin Traverso wrote:

> Howdy,
>
> What is the best way to resolve the ambiguities caused by 'D' a in  
> rule c in the following grammar?
>
> grammar T;
> a: b ('+' b)*;
> b: c ('*' c)*;
> c: 'D' a
>    | 'x';
>
Which rule has the ambiguity?  All the (...)* loops, right?  That  
unterminated 'a' in 'c' will cause trouble...a true ambiguity I  
think.  That said, set k=1 in the (...)* subrules and it will  
greedily and happily do the "natural" thing I think.

Ter


More information about the antlr-interest mailing list