Skip to content
Official PYQ · 2014

GATE CS 2014 Set 3 Q17 — Intermediate Code Generation

Explain with AI

One of the purposes of using intermediate code in compilers is to

Choose one option
View worked solution

Answer: C

The correct option is C.

In a compiler, the compilation process is divided into two main parts:

  • Front-end (Source-dependent): Lexical analysis, parsing, and semantic analysis.
  • Back-end (Machine-dependent): Code generation and register allocation.

An Intermediate Representation (IR) acts as a bridge between the front-end and the back-end. The primary benefits of using an intermediate code include:

  1. Portability and Reusability: If we want to build compilers for MM source languages and NN target machines, using a common intermediate representation requires only MM front-ends and NN back-ends (total M+NM + N components) instead of M×NM \times N separate compilers.
  2. Machine-Independent Optimization: Code optimization can be performed directly on the intermediate code. Since this optimizer is machine-independent, it can be reused across compilers for different target architectures.

Why other options are incorrect:

  • Option A: Parsing and semantic analysis occur before the intermediate code is generated, so intermediate code cannot simplify these phases.
  • Option B: Error detection and recovery are primarily the responsibility of the front-end phases (lexical, syntactic, and semantic analyzers).
  • Option D: Register allocation is a highly machine-dependent task handled during the final code generation phase, which depends on the physical registers of the target architecture.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Intermediate Code Generation questions