Arrange the following phases of a compiler as per their order of execution…

2023

Arrange the following phases of a compiler as per their order of execution (start to end)

(A) Target code generation

(B) Syntax Analysis

(C) Code optimization

(D) Semantic Analysis

(E) Lexical Analysis

Choose the correct answer from the options given below :

  1. A.

    (B), (E), (D), (A), (C)

  2. B.

    (E), (D), (B), (A), (C)

  3. C.

    (E), (B), (D), (C), (A)

  4. D.

    (B), (D), (E), (A), (C)

Attempted by 323 students.

Show answer & explanation

Correct answer: C

Correct order (start to end): Lexical Analysis, Syntax Analysis, Semantic Analysis, Code Optimization, Target Code Generation

  • Lexical Analysis: Breaks source code into tokens (identifiers, keywords, literals).

  • Syntax Analysis: Uses tokens to build a parse tree (checks grammatical structure).

  • Semantic Analysis: Performs type checking and enforces contextual rules using the parse tree.

  • Code Optimization: Improves the intermediate representation for performance or size.

  • Target Code Generation: Produces the final machine or assembly code from the optimized intermediate form.

Why this order?

  • Tokens from Lexical Analysis are required by Syntax Analysis to construct the parse tree.

  • Semantic checks operate on the parse tree and symbol information, so they come after parsing.

  • Optimizations are applied to the intermediate representation before generating final machine code to ensure the target code is efficient.

Explore the full course: Mppsc Assistant Professor