Skip to content
Official PYQ · 2006

GATE CS 2006 Q32 — Parsing (LL, LR)

Explain with AI

Consider the following statements about the context free grammar

G={S→SS,S→ab,S→ba,S→ϵ}G = \left \{ S \rightarrow SS, S \rightarrow ab, S \rightarrow ba, S \rightarrow \epsilon \right \}

  1. GG is ambiguous
  2. GG produces all strings with equal number of aa’s and bb’s
  3. GG can be accepted by a deterministic PDA.

Which combination below expresses all the true statements about GG?

Choose one option
View worked solution

Answer: B

To determine the correct statement(s), let us analyze each statement individually:

Statement I: GG is ambiguous

  • A grammar is ambiguous if there exists at least one string in its language that has more than one leftmost derivation (or parse tree).
  • Consider the string w=abw = ab. We can derive it in multiple ways:
    • Derivation 1: S→abS \rightarrow ab
    • Derivation 2: S→SS→abS→abϵ=abS \rightarrow SS \rightarrow ab S \rightarrow ab \epsilon = ab
  • Since the string abab has multiple distinct leftmost derivations, the grammar GG is ambiguous. Thus, Statement I is TRUE.

Statement II: GG produces all strings with equal number of aa’s and bb’s

  • The production rules of GG are S→SS∣ab∣ba∣ϵS \rightarrow SS \mid ab \mid ba \mid \epsilon.
  • Every non-empty terminal string generated by this grammar must be formed by concatenating the blocks abab and baba. Thus, the language generated is L(G)=(ab∣ba)∗L(G) = (ab \mid ba)^*.
  • Consider the string w=aabbw = aabb. It has an equal number of aa's and bb's, but it cannot be generated by GG because any string in L(G)L(G) must start with either abab or baba.
  • Since aabb∉L(G)aabb \notin L(G), Statement II is FALSE.

Statement III: GG can be accepted by a deterministic PDA

  • The language L(G)=(ab∣ba)∗L(G) = (ab \mid ba)^* is a regular language because it can be represented by a regular expression.
  • Every regular language can be accepted by a Deterministic Finite Automaton (DFA).
  • Since any language accepted by a DFA can also be accepted by a Deterministic Pushdown Automaton (DPDA) by simply not using the stack, L(G)L(G) is accepted by a deterministic PDA. Thus, Statement III is TRUE.

Therefore, only statements I and III are true.

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

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