Answer: B
A grammar has left recursion if there exists a non-terminal X such that X⇒+Xα for some string of grammar symbols α. Left recursion can be either immediate (e.g., X→Xα) or indirect/mutual (e.g., X→Yβ⇒Xαβ).
Let's analyze each option:
- Option A:
SAB→AB→Aa∣b→c
The production A→Aa is an immediate left recursion. Thus, this grammar is not free from left recursion.
- Option B:
SAB→Ab∣Bb∣c→Bd∣ϵ→e
Let's trace all possible derivations starting with each non-terminal:
- From S: S→Ab→Bdb→edb, or S→Bb→eb, or S→c. No derivation starts with S.
- From A: A→Bd→ed, or A→ϵ. No derivation starts with A.
- From B: B→e. No derivation starts with B.
Since there is no sequence of derivations where X⇒+Xα for any non-terminal X, this grammar is free from left recursion.
- Option C:
SAB→Aa∣B→Bb∣Sc∣ϵ→d
We can derive:
S→Aa→Sca
Since S⇒+Sca, this grammar has indirect left recursion.
- Option D:
SAB→Aa∣Bb∣c→Bd∣ϵ→Ae∣ϵ
We can derive:
A→Bd→Aed
Since A⇒+Aed, this grammar has indirect left recursion.
Therefore, only the grammar in Option B is free from left recursion.