Skip to content
Official PYQ · 2005

GATE CS 2005 Q14 — Parsing (LL, LR)

Explain with AI

The grammar A→AA∣(A)∣ϵA \rightarrow AA \mid (A) \mid \epsilon is not suitable for predictive-parsing because the grammar is:

Choose one option
View worked solution

Answer: A

A predictive parser (such as an LL(1)\text{LL}(1) parser) must be deterministic. This means that for any non-terminal and lookahead symbol, there must be at most one production rule that can be applied. Consequently, no ambiguous grammar can be parsed by a predictive parser.

Let us check if the given grammar is ambiguous:

A→AA∣(A)∣ϵA \rightarrow AA \mid (A) \mid \epsilon

We can show ambiguity by generating the string () using two different leftmost derivations:

  • Derivation 1:
    A⇒(A)⇒(ϵ)=()A \Rightarrow (A) \Rightarrow (\epsilon) = ()
  • Derivation 2:
    A⇒AA⇒(A)A⇒(ϵ)A⇒()A⇒()ϵ=()A \Rightarrow AA \Rightarrow (A)A \Rightarrow (\epsilon)A \Rightarrow ()A \Rightarrow ()\epsilon = ()

Since the string () has more than one leftmost derivation (and thus multiple distinct parse trees), the grammar is ambiguous. Therefore, it is not suitable for predictive parsing.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions