Which of the following phase of the compiler, gathers type information and…

2024

Which of the following phase of the compiler, gathers type information and saves it in either the syntax tree or the symbol table, for subsequent use during intermediate code generation?

  1. A.

    Semantic Analyzer

  2. B.

    Code Analyzer

  3. C.

    Syntax Analyzer

  4. D.

    Lexical Analyzer

Attempted by 102 students.

Show answer & explanation

Correct answer: A

Concept: In the classical compiler pipeline, the front end has three distinct phases: lexical analysis (produces tokens), syntax analysis (uses those tokens to build a parse tree/AST reflecting only grammatical structure), and semantic analysis (checks static semantics -- most importantly type compatibility -- and attaches the derived type information onto the syntax tree's nodes or into the symbol table). Only after this annotation is the tree "type-complete" and ready for the back end (intermediate code generation, optimization, code generation) to consume.

Application: The question asks for the phase that "gathers type information and saves it in either the syntax tree or the symbol table, for subsequent use during intermediate code generation." That is precisely the semantic analyzer's job: it type-checks expressions and declarations, then records the results (types) on tree nodes or in symbol-table entries so intermediate code generation can use them.

Cross-check: Contrasting with the alternatives confirms this: syntax analysis only builds the parse tree's structure and has no notion of types; lexical analysis only produces a token stream (identifiers, keywords, operators) with no structural or type information at all; and "Code Analyzer" is not one of the standard compiler phases. So among the given options, only the semantic analyzer performs the type-gathering role described.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs