Generation of intermediate code based on an abstract machine model is useful in compilers because
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:
- Front-End: Analysis phase (Lexical, Syntax, and Semantic analysis) which is source-language dependent.
- 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 source languages for target architectures, we only need to write front-ends and back-ends (a total of components), rather than 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.
