Which of the following grammars requires left factoring?
2025
Which of the following grammars requires left factoring?
- A.
A → aB | aC
- B.
A → aB | bC
- C.
A → a | ε
- D.
A → B | C
Attempted by 61 students.
Show answer & explanation
Correct answer: A
Left factoring is used when multiple productions of a grammar share a common prefix, making it difficult for a parser to decide which rule to apply.
Given:
A → aB | aC
Both productions start with a, so the parser cannot decide which path to take immediately.
We rewrite it as:
A → aA'
A' → B | C
This removes ambiguity and makes the grammar suitable for predictive parsing.