Skip to content
Official PYQ · 2004

GATE CS 2004 Q8 — Parsing (LL, LR)

Explain with AI

Which of the following grammar rules violate the requirements of an operator grammar? P,Q,RP, Q, R are nonterminals, and r,s,tr, s, t are terminals.

  1. P→QRP \rightarrow Q R

  2. P→QsRP \rightarrow Q s R

  3. P→ εP \rightarrow \: \varepsilon

  4. P→QtRrP \rightarrow Q t R r

Choose one option
View worked solution

Answer: B

An operator grammar is a context-free grammar that satisfies the following two conditions for all its production rules:

  1. No production has ε\varepsilon (the empty string) on the right-hand side.
  2. No production has two adjacent non-terminals on the right-hand side.

Let's analyze the given grammar rules (where P,Q,RP, Q, R are non-terminals and r,s,tr, s, t are terminals):

  • Rule I (P→QRP \rightarrow QR): Violates the requirements because the non-terminals QQ and RR are adjacent.
  • Rule II (P→QsRP \rightarrow Q s R): Valid because the non-terminals QQ and RR are separated by the terminal ss.
  • Rule III (P→εP \rightarrow \varepsilon): Violates the requirements because it is an ε\varepsilon-production.
  • Rule IV (P→QtRrP \rightarrow Q t R r): Valid because no two non-terminals are adjacent, and there is no ε\varepsilon on the right-hand side.

Therefore, rules (I) and (III) only violate the requirements of an operator grammar.

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

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