One of the purposes of using intermediate code in compilers is to
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:
- Portability and Reusability: If we want to build compilers for source languages and target machines, using a common intermediate representation requires only front-ends and back-ends (total components) instead of separate compilers.
- 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.
