Skip to content
Official PYQ · 1995

GATE CS 1995 Q1.10 — Parsing (LL, LR)

Explain with AI

Consider a grammar with the following productions

  • S→aαb∣bαc∣aBS \rightarrow a \alpha b \mid b \alpha c \mid aB
  • S→αS∣bS \rightarrow \alpha S\mid b
  • S→αbb∣abS \rightarrow \alpha b b\mid ab
  • Sα→bdb∣bS \alpha \rightarrow bd b\mid b

The above grammar is:

Marks were awarded to all candidates for this question. It is not scored as a normal quiz.

View worked solution

Marks to all

To determine the type of the given grammar, we analyze the production rules:

  • S→aαb∣bαc∣aBS \rightarrow a \alpha b \mid b \alpha c \mid aB
  • S→αS∣bS \rightarrow \alpha S \mid b
  • S→αbb∣abS \rightarrow \alpha b b \mid ab
  • Sα→bdb∣bS \alpha \rightarrow bd b \mid b

We observe the following:

  1. The production Sα→bdb∣bS \alpha \rightarrow bd b \mid b has a left-hand side (SαS \alpha) containing more than one symbol. In a Context-Free Grammar (CFG), the left-hand side of every production must be a single non-terminal. Thus, this grammar is not Context-Free.
  2. Since it is not context-free, it cannot be Regular (Option B) or LR(k)LR(k) (Option D), as both are subsets of context-free grammars.
  3. By elimination, the grammar is classified as Context sensitive (Option C).

Note on formal classification: Strictly speaking, the production Sα→bS \alpha \rightarrow b is length-decreasing (∣Sα∣=2>∣b∣=1|S \alpha| = 2 > |b| = 1), which technically makes the grammar unrestricted (Type-0). However, among the given options, Option C is the intended choice.

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

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