Consider the following expression grammar :
Which of the following grammars is not left recursive, but is equivalent to ?
View worked solution
Answer: C
To eliminate immediate left recursion from a grammar, we use the standard transformation rule:
If we have productions of the form: where does not begin with , we can replace them with:
Let's apply this rule step-by-step to the given grammar :
-
For the non-terminal :
The production is . Here, , , and .
Applying the transformation (using as the new non-terminal instead of ):
-
For the non-terminal :
The production is . Here, , , and .
Applying the transformation (using as the new non-terminal instead of ):
-
For the non-terminal :
The production is . Since it is not left-recursive, it remains unchanged:
Combining all the transformed productions, we get:
This matches Option C.
Elimination of other options:
- Option A: This is the original grammar, which contains left recursion in both and .
- Option B: Left recursion is eliminated only for , but is still left-recursive.
- Option D: This grammar is not equivalent to (e.g., it cannot generate the same set of strings, and the operator precedence/associativity is lost).
Free practice · Your answers on this page are not saved.
