Final answer:
The provided ambiguous grammars can be shown to be ambiguous by deriving the same string in more than one way. Equivalent unambiguous grammars are then presented to enforce a single, clear way of deriving each string, thus removing the ambiguity.
Step-by-step explanation:
Demonstrating Ambiguity in Grammars and Creating Unambiguous Versions
The grammars presented have ambiguity, which can be shown by deriving the same string from the grammar in more than one way, leading to multiple parse trees for the same string.
Ambiguous Grammar
Original Grammar (a): S → SS | ab | a
This grammar is ambiguous because the string 'aabb' can be derived in two distinct ways: by parsing as (SS)ab where S → a and S → ab, or as a(SS)b where S → ab and S → b (there is no 'b' production but for the sake of argument).
Equivalent Unambiguous Grammar (a): S → Xab | a
X → aX | ε
In this unambiguous version, the grammar enforces a specific order of derivation, removing ambiguity.
Original Grammar (b): S → ABA
A → aA | ε
B → bB | ε
For grammar (b), the string 'aabab' can be derived with A producing 'aa', B producing 'b', and A producing 'ab', or with A producing 'a', B producing 'ab', and A producing 'a', leading to ambiguity.
Equivalent Unambiguous Grammar (b): S → aSb | ε
Here, each 'a' is forced to be followed by a 'b', matching them one-to-one and eliminating ambiguity.