GATE / CS ARCHIVE

GATE CSE 2021 SET 2 / QUESTION 3

GATE CSE 2021 Set 2 Q3

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 2021 Set 2 paper

GATE 2021 Set 2, Q3 1 mark · MCQ
Report issue

Semantic Analysis & Type Checking

Question 3, GATE 2021: ANSI C program: int main(){ Integer x; return 0; }. No declaration of Integer is supplied. Which conceptual seven-phase compiler stage reports the error? A lexical analysis; B syntax analysis; C semantic analysis; D machine-dependent optimization.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Our answer: C in the textbook phase model

Integer is an identifier rather than a built-in C type, and no typedef declaration introduces it. The intended seven-phase classification is an undeclared-type/name error detected by semantic analysis, C. Real C front ends can report a parse error because typedef-name classification interacts with parsing; the answer describes the conceptual phase classification rather than a guarantee about every compiler diagnostic.

Lexing can recognize Integer as a legal identifier, so its spelling is not itself a lexical error. Semantic analysis normally resolves declarations and type meanings. The conceptual answer should not be read as promising that a particular real C parser will proceed to a separately named semantic phase for this malformed declaration.

Original paper, page 56 · Answer key