Which of the following grammars requires left factoring?

2025

Which of the following grammars requires left factoring?

  1. A.

    A → aB | aC

  2. B.

    A → aB | bC

  3. C.

    A → a | ε

  4. 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.

Explore the full course: Niacl Ao It Specialist