Consider the following ANSI C program: int main() { Integer x; return 0; } Which one of the following phases in a seven-phase C compiler will throw an error?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2021 Set 2 · Q3
Time
int main() {
Integer x;
return 0;
}Which one of the following phases in a seven-phase C compiler will throw an error?Select one answerSingle correct
Solution
Official answer: C) Semantic analyzer
Lexical Analysis, Parsing and SDTLexical Analyzer: Breaks the input source code into tokens. Integer and x are both valid identifiers (tokens of type identifier), so no lexical error is generated.
Syntax Analyzer (Parser): Validates the grammatical structure of the program based on Context-Free Grammar (CFG). The statement Integer x; syntactically looks like <type_name> <identifier>; (or <identifier> <identifier>;), which fits the syntactic declaration rule.
Semantic Analyzer: Responsible for type checking, undeclared variable/type detection, and scope resolution. Since Integer is not defined as a valid data type (neither built-in nor declared via typedef / struct), the semantic analyzer identifies that Integer is an undeclared type and reports a semantic error (e.g., *unknown type name 'Integer'*).
Machine Dependent Optimizer: Executes much later in the backend; the compiler will fail before reaching this phase.
Therefore, the error is thrown during the Semantic analyzer phase (Option C).
Try the question first, then check your work.
Examiner trap
Consider which phase is responsible for type checking and verifying whether a data type identifier has been declared.
This Lexical Analysis, Parsing and SDT previous year question is Q3 of the GATE CSE 2021 Set 2 paper. Find more GATE CSE PYQs on Lexical Analysis, Parsing and SDT in Compiler Design, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Lexical Analysis, Parsing and SDT PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Lexical Analysis, Parsing and SDT has 14 GATE CSE PYQs across 12 papers from 2011 to 2025. 9 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2021 Set 2.
How GATE tests Lexical Analysis, Parsing and SDTIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.