GateAI
Lexical Analysis, Parsing and SDT

GATE CSE 2021 Set 2 · Q3

MCQ1 markEasy

Time

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?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) Semantic analyzer

Lexical Analysis, Parsing and SDT
  1. Lexical 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.

  2. 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.

  3. 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'*).

  4. 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.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

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 in GATE CSE

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 SDT

More from GATE CSE 2021 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2021 Set 2 · Q3 · MCQ

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.