10 Multiple Choice Questions (MCQs) related to Intermediate Code Generation

10 Multiple Choice Questions (MCQs) related to Intermediate Code Generation, useful for UGC NET, SET, and GATE exams:


1. What is the main purpose of intermediate code generation in a compiler?

A) Convert high-level code to machine code
B) Generate an intermediate representation for optimization and portability
C) Detect syntax errors
D) Allocate memory for variables

Explanation:
Intermediate code generation creates an intermediate representation (IR) that is machine-independent, allowing for optimization and easier translation to machine code.

Answer: B) Generate an intermediate representation for optimization and portability


2. Which of the following is NOT an intermediate representation format?

A) Abstract Syntax Tree (AST)
B) Three-Address Code (TAC)
C) Postfix Notation
D) Machine Code

Explanation:
Machine code is the final output of compilation, not an intermediate representation.

Answer: D) Machine Code


3. Which of the following is a characteristic of an intermediate representation?

A) It is directly executed by the processor
B) It is machine-independent
C) It is a high-level language
D) It does not allow optimization

Explanation:
Intermediate code is machine-independent, making it useful for compiler optimization and target code generation.

Answer: B) It is machine-independent


4. What is the most common form of intermediate representation used in compilers?

A) High-Level Code
B) Three-Address Code (TAC)
C) Binary Machine Code
D) Relocatable Object Code

Explanation:
Three-Address Code (TAC) is widely used as it simplifies optimization and translation to machine code.

Answer: B) Three-Address Code (TAC)


5. Which of the following is an advantage of using an intermediate representation?

A) Increases compilation time
B) Reduces portability
C) Allows for code optimization before machine code generation
D) Makes debugging difficult

Explanation:
An intermediate representation allows optimization and improves portability across different architectures.

Answer: C) Allows for code optimization before machine code generation


6. Which of the following statements about Three-Address Code (TAC) is TRUE?

A) Each instruction has only one operand
B) It is directly executed by the CPU
C) It breaks down complex expressions into simple statements with at most three operands
D) It cannot be used for optimization

Explanation:
TAC simplifies expressions into basic operations with at most three operands, making it suitable for optimization.

Answer: C) It breaks down complex expressions into simple statements with at most three operands


7. Which of the following is an example of a Three-Address Code (TAC) instruction?

A) A = B + C * D
B) t1 = C * D; t2 = B + t1; A = t2;
C) MOV A, B
D) PUSH AX

Explanation:
TAC breaks complex expressions into simpler steps with temporary variables, as shown in option B.

Answer: B) t1 = C * D; t2 = B + t1; A = t2;


8. What is the main purpose of using Static Single Assignment (SSA) form in intermediate code?

A) Reduce the number of instructions
B) Improve readability of the source code
C) Ensure that each variable is assigned only once
D) Generate direct machine code

Explanation:
In SSA form, every variable is assigned exactly once, which helps in optimization and register allocation.

Answer: C) Ensure that each variable is assigned only once


9. Which of the following intermediate code representations is based on a stack machine model?

A) Three-Address Code
B) Postfix Notation
C) Abstract Syntax Tree
D) Control Flow Graph

Explanation:
Postfix notation (Reverse Polish Notation) follows a stack-based evaluation model.

Answer: B) Postfix Notation


10. In the context of intermediate code generation, what is a basic block?

A) A single line of assembly code
B) A set of statements with only one entry and one exit point
C) A recursive function
D) A high-level function definition

Explanation:
A basic block is a sequence of statements where execution always enters at the beginning and exits at the end without jumps or branches in between.

Answer: B) A set of statements with only one entry and one exit point

Comments