GATE / CS ARCHIVE

GATE CSE 2002 / QUESTION 2.18

Context dependence in C programs

Theory of Computation · Other / Mixed Topics · Full GATE CSE 2002 paper

GATE 2002, Q2.18 2 marks · MCQ
Report issue

Other / Mixed Topics

Question 2.18, GATE 2002: Classify the C programming language.
(A) Context-free; (B) Context-sensitive; (C) Regular; (D) Fully parsable only by a Turing machine.
Tap to enlarge
Your answer
Answer & solution

Answer: B under the usual syntax-plus-static-constraints interpretation (no official key was published)

Step 1: Distinguish parsing from all static validity checks.

Step 2: A phrase-structure grammar can describe expression and statement shapes while a symbol table checks whether identifier uses agree with their declarations. The latter checks depend on context not captured by merely recognizing those shapes. The answer’s scope is this conventional language-classification question, not a claim that a context-free parser alone proves a C program fully valid or that it decides termination.

Conclusion: C includes context-dependent restrictions such as consistent declarations and uses of identifiers, beyond a context-free phrase-structure grammar. The usual classification including such static checks is context-sensitive, B. A compiler may still use a context-free parser supplemented by symbol-table analysis; this does not make all well-formed C programs a context-free syntax-only language. Runtime behavior and whether a program halts are separate from this classification.

Original paper, page 5