Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have the following question taken from a compilers course exam:

Show that the following grammar is ambiguous.

S = XcY
X = a
Y = b | Z
Z = bW
W = d | ϵ

I drew the following tree:

grammar diagram

Am I correct in thinking it is ambiguous because acY can end up at acb (one of which is followed by an epslion) following different paths?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

Yes. Since epsilon means you can rewrite W as the empty string, acbW -> acb. As you have shown, there are two leftmost derivations for the string acb, which by definition means the grammar is ambiguous.

share|improve this answer
    
Thanks for clearing that up ! –  Tom celic Jan 1 '13 at 23:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.