0

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.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
NoNameY0
  • 612
  • 2
  • 8
  • 18

1 Answers1

1

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.

minopret
  • 4,726
  • 21
  • 34
  • so both questions are ambigous – NoNameY0 Mar 14 '13 at 00:40
  • Yes. If you needed to prove a grammar is unambiguous you'd have a somewhat bigger job. You'd generally proceed to divide and conquer the grammar, analyzing it into separate cases. Your cases would be such that no two of them have any productions in common and together they account for all possible productions from the grammar. You'd keep dividing cases into smaller subcases until you're able to take each case and show that no production from that particular case has more than one derivation. – minopret Mar 14 '13 at 00:43