[antlr-interest] An ambiguity question

Seref Arikan serefarikan at kurumsalteknoloji.com
Tue Aug 29 09:27:03 PDT 2006


Hi,
While taking a look at the past messages, I saw an interesting one. This 
is from Martin Traverso:

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';

Essentially, I want it to parse stuff like:

x * x + x * x
D x * x + x * x    (should parse as D ((x * x) + (x * x)) )
x + D x * x + x * x  (should parse as x + D ((x * x) + (x * x)) )
D x + D x  (should parse as D (x + D x) )
etc.

Now, Terrence has answered this one, but I'd like to ask the following:
How does the ambiguity occur?  Would someone please provide me an 
example input to the question below that will cause the problem?  A 
little explanation on this one would be great

Best Regards
Seref Arikan



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.6/430 - Release Date: 8/28/2006



More information about the antlr-interest mailing list