GATE CS 2021 Set 2 | Question 13

Compiler Design › Parser · MCQ · 1 mark · Answer: C

  1. Question 13Compiler Designmcq1 mark
    Consider the following ANSI C program.
    int main() {
        Integer x;
        return 0;
    }
    Which one of the following phases of a compiler will detect the error (if any) in the above program?
    • A.
      Lexical analyzer
    • B.
      Syntax analyzer
    • C.
      Semantic analyzer
      ✓
    • D.
      Machine dependent code optimizer

    Answer: C

    Solution

    Integer is a valid identifier token (passes lexical analysis) and Integer x; is syntactically a valid declaration form (passes parsing). The error — that Integer is not a declared type — is caught during semantic analysis.

More GATE PYQ on Parser

All GATE CS Compiler Design PYQ →

Attempt GATE CS 2021 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →