What is the primary objective of applying left factoring to a grammar in…
2025
What is the primary objective of applying left factoring to a grammar in compiler design?
- A.
To enhance the grammar's ambiguity and parsing flexibility
- B.
To transform the grammar into its normal form
- C.
To eliminate left recursion from the grammar rules
- D.
To restructure the grammar to aid predictive parsers in making decisions
Attempted by 86 students.
Show answer & explanation
Correct answer: D
Left factoring is a grammar transformation technique used in compiler design to make a Context-Free Grammar (CFG) suitable for deterministic top-down parsing (such as predictive or LL(1) parsing).
When a parser is scanning tokens from left to right, it looks ahead at the incoming token to choose the correct production rule. If multiple rules for a single variable start with the exact same symbols, the parser faces a "backtracking" dilemma because it cannot distinguish between the choices using a limited lookahead. Left factoring resolves this.