سؤال

I was at a job interview, and this is the question they asked me,

Are these two below ambigous? If they are, provide a string. If they are not, prove why they are not.

I couldn't solve it, and would like to know the answer and the reason for the future.

Question 1

S-->XaaaX
X-->aX | bX | e(epsilon)

Question 2

S-->aaS | aaaS | a

Again, this is not HW.

Thank you. An explanation would help.

هل كانت مفيدة؟

المحلول

We recall that a grammar is ambiguous if (and only if) some production from the grammar has more than one possible derivation.

In question 1 the symbol S expands to XaaaX and then the available alternatives for expanding the symbol X include aX and epsilon (ε). Conventionally the symbol epsilon represents an empty string. Expanding X as epsilon in aX produces a. So there are at least two ways to get aaaa. Richard Mckenna, I'll leave it to you to find them.

In question 2 the symbol S expands to aaS, aaaS, or a. There are at least two ways to get aaaaaa. Again I'll leave it to you to find the derivations.

If you wish, you may write your derivations on this page.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top