GATE / CS ARCHIVE

GATE CSE 1994 / QUESTION 1.18

A context-sensitive language check

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 1994 paper

GATE 1994, Q1.18 MCQ
Report issue

Semantic Analysis & Type Checking

Question 1.18, GATE 1994: Which feature cannot generally be enforced by a CFG alone: if-then-else syntax, recursive-procedure syntax, declaration before variable use, or arbitrary-length variable names?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

A CFG can describe nested statements, recursive syntactic structures and identifier shapes of unbounded length. Checking that a particular identifier was previously declared requires matching that name against the declarations valid in its scope, not merely recognizing a syntactic category. Compilers therefore use symbol tables and semantic analysis for this context-sensitive condition. The claim concerns unrestricted identifiers and general programs; a finite fixed universe could be encoded into a much larger grammar, but that is not the usual language model.

Original paper, page 2