Skip to content
Official PYQ · 1994

GATE CS 1994 Q1.18 — Parsing (LL, LR)

Explain with AI

Which of the following features cannot be captured by context-free grammars?

Choose one option
View worked solution

Answer: C

To determine which feature cannot be captured by a context-free grammar (CFG), let us analyze each option:

  • A. Syntax of if-then-else statements: This can be easily defined using a CFG. For example: S→if E then S∣if E then S else S∣otherS \rightarrow \text{if } E \text{ then } S \mid \text{if } E \text{ then } S \text{ else } S \mid \text{other}
  • B. Syntax of recursive procedures: CFGs naturally support recursion (self-nested structures), making them perfectly suited to define recursive procedure structures.
  • C. Whether a variable has been declared before its use: This is a semantic check rather than a purely syntactic one. Formally, verifying that a variable of any arbitrary name ww is declared before it is used is equivalent to recognizing the language: L={wcw∣w∈Σ∗}L = \{ w c w \mid w \in \Sigma^* \} By the pumping lemma, LL is a well-known non-context-free language. Thus, this feature cannot be captured by a CFG and is instead handled during the semantic analysis phase using a symbol table.
  • D. Variable names of arbitrary length: This can be defined even by a regular grammar (which is a subset of CFGs). For example: Identifier→letter Rest\text{Identifier} \rightarrow \text{letter } \text{Rest} Rest→letter Rest∣digit Rest∣ϵ\text{Rest} \rightarrow \text{letter } \text{Rest} \mid \text{digit } \text{Rest} \mid \epsilon

Therefore, the feature that cannot be captured by context-free grammars is C.

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

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