108k views
3 votes
Show that the grammar ({S}, {a, b}, S, P) with productions S → bSaS| aSbS | λ is ambiguous.

User Snf
by
7.8k points

1 Answer

7 votes

Final answer:

The given grammar ({S}, {a, b}, S, P) with productions S → bSaS| aSbS | λ is ambiguous.

Step-by-step explanation:

In the given grammar ({S}, {a, b}, S, P) with productions S → bSaS| aSbS | λ, we can show that it is ambiguous. Let's analyze the productions:

  1. S → bSaS: This production allows us to generate a string that begins with 'b', followed by any number of 'a's, and ends with 'b's. For example, we can generate 'babaabb'.
  2. S → aSbS: This production allows us to generate a string that begins with 'a', followed by any number of 'b's, and ends with 'a's. For example, we can generate 'ababbaa'.
  3. S → λ: This production allows us to generate an empty string.

Now, consider the string 'ab'. We can derive this string using two different derivations: S → aSbS → ab and S → bSaS → ab. Therefore, the grammar is ambiguous as it can generate the same string using different derivations.

User Nick Becker
by
8.5k points