Q. In three-address code, how is a binary operation typically represented?
A.
result = operand1 operator operand2
B.
operand1 operator operand2 = result
C.
result operator operand1 operand2
D.
operand1 operand2 operator = result
Solution
Three-address code represents binary operations in the form 'result = operand1 operator operand2', which clearly indicates the result of the operation.
Correct Answer:
A
— result = operand1 operator operand2
Q. What is the advantage of using an abstract syntax tree (AST) in intermediate code generation?
A.
It is easier to optimize than linear representations
B.
It directly represents machine instructions
C.
It simplifies lexical analysis
D.
It is more compact than binary code
Solution
An abstract syntax tree (AST) provides a hierarchical representation of the program structure, making it easier to apply optimizations compared to linear representations.
Correct Answer:
A
— It is easier to optimize than linear representations
Q. What is the primary purpose of intermediate code generation in a compiler?
A.
To optimize the source code
B.
To translate high-level code to machine code
C.
To provide a platform-independent representation of the source code
D.
To perform lexical analysis
Solution
Intermediate code generation creates a representation of the source code that is independent of the target machine, allowing for easier optimization and code generation.
Correct Answer:
C
— To provide a platform-independent representation of the source code
Q. What is the typical output of the intermediate code generation phase?
A.
Source code
B.
Assembly code
C.
Intermediate representation
D.
Executable code
Solution
The output of the intermediate code generation phase is typically an intermediate representation that can be further optimized and translated into machine code.
Q. Which of the following is a benefit of using intermediate code in a compiler?
A.
It eliminates the need for parsing
B.
It allows for easier debugging of the source code
C.
It enables code generation for multiple target architectures
D.
It simplifies lexical analysis
Solution
Using intermediate code allows a compiler to generate code for multiple target architectures from the same intermediate representation, enhancing portability.
Correct Answer:
C
— It enables code generation for multiple target architectures