Skip to content
Official PYQ · 1994

GATE CS 1994 Q1.12 — Intermediate Code Generation

Explain with AI

Generation of intermediate code based on an abstract machine model is useful in compilers because

Choose one option
View worked solution

Answer: C

The correct option is C: it enhances the portability of the front end of the compiler.

Explanation:

A modern compiler is typically structured into two main parts:

  1. Front-End: Analysis phase (Lexical, Syntax, and Semantic analysis) which is source-language dependent.
  2. Back-End: Synthesis phase (Code Optimization and Code Generation) which is target-machine dependent.

By using an Intermediate Representation (IR) based on an abstract machine model, we decouple the front-end from the back-end:

  • If we want to compile MM source languages for NN target architectures, we only need to write MM front-ends and NN back-ends (a total of M+NM + N components), rather than MimesNM imes N separate compilers.
  • The front-end remains completely independent of the target machine, which highly enhances its portability. It can be reused without modification for any new target machine by just writing a new back-end.

Analysis of other options:

  • Option A: Lexical and syntax analysis occur before intermediate code generation, so IR does not make their implementation easier.
  • Option B: While syntax-directed translation (SDT) is used to generate intermediate code, this is a mechanism of generation, not the primary architectural reason why IR is useful.
  • Option D: It is entirely possible to generate machine code directly from high-level languages (as done in simple single-pass compilers), though it is less modular and harder to optimize.

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

Published
Report a correction
Keep exploringMore Intermediate Code Generation questions