What is the primary goal of translating expressions in a compiler?
A) To optimize the expressions
B) To directly map high-level code to machine code
C) To simplify the expressions and evaluate them efficiently
D) To check for syntax errors in the expressions
Answer: C) To simplify the expressions and evaluate them efficiently
2. Which of the following is commonly used to translate arithmetic expressions in a compiler?
A) Regular expressions
B) Directed Acyclic Graph (DAG)
C) Control flow graph
D) Abstract syntax tree (AST)
Answer: B) Directed Acyclic Graph (DAG)
3. In the context of translating control flow statements, what does a “branch” refer to?
A) A point where the program execution can diverge based on a condition
B) A loop in the code
C) A variable declaration
D) A mathematical operation
Answer: A) A point where the program execution can diverge based on a condition
4. Which of the following is the primary function of a control flow statement in a program?
A) To define the variables used in the program
B) To manage the sequence of operations based on conditions
C) To allocate memory dynamically
D) To handle exceptions during runtime
Answer: B) To manage the sequence of operations based on conditions
5. Which of the following best describes a basic block in control flow analysis?
A) A sequence of instructions with no branches, except at the end
B) A sequence of instructions that always results in a loop
C) A group of variables used in a function
D) A specific type of data structure
Answer: A) A sequence of instructions with no branches, except at the end
6. What is the typical outcome of translating a conditional jump (like an if
statement) in a compiler?
A) The execution skips the entire program
B) It creates a branch in the control flow graph
C) It eliminates the need for further optimization
D) It directly generates machine code for conditional checks
Answer: B) It creates a branch in the control flow graph
7. Which of the following expressions is typically translated into a temporary variable in Three-Address Code (TAC)?
A) result = a + b * c
B) x = 5
C) if x > 10 then
D) while x < 20 do
Answer: A) result = a + b * c
8. What is the role of a “goto” statement in control flow translation?
A) It creates a loop in the program execution
B) It specifies the target address for branching to another part of the program
C) It creates a new function
D) It allocates memory for variables
Answer: B) It specifies the target address for branching to another part of the program
9. Which of the following control flow structures is typically represented by a directed edge in a control flow graph (CFG)?
A) Variables
B) Loops
C) Branches or jumps
D) Function calls
Answer: C) Branches or jumps
10. What is a “return” statement in control flow translation commonly translated to in machine code?
A) A jump to the end of the program
B) A jump to the next instruction in the program
C) A branch that exits the function and returns control to the calling function
D) A loop that repeats the execution of the current function
Answer: C) A branch that exits the function and returns control to the calling function
11. How does a “while” loop typically get translated in a compiler?
A) By translating it into a sequence of basic blocks and conditional jumps
B) By translating it into a simple expression
C) By creating an infinite loop in the program
D) By removing the loop entirely
Answer: A) By translating it into a sequence of basic blocks and conditional jumps
12. Which of the following is a key step in translating control flow statements in a compiler?
A) Checking for syntax errors only
B) Mapping control flow structures to basic blocks
C) Generating the final machine code directly
D) Analyzing the scope of variables
Answer: B) Mapping control flow structures to basic blocks
13. In a program’s control flow graph (CFG), what does a “node” represent?
A) A basic block in the program
B) A variable used in the program
C) A specific operation in the program
D) A syntax error in the program
Answer: A) A basic block in the program
14. Which intermediate representation is typically used to translate conditional expressions?
A) Abstract syntax tree (AST)
B) Three-Address Code (TAC)
C) Control Flow Graph (CFG)
D) Directed Acyclic Graph (DAG)
Answer: B) Three-Address Code (TAC)
15. Which of the following is a typical result of translating a for-loop in a compiler?
A) It generates a single statement with no branches
B) It is converted into a combination of a conditional check and a jump
C) It is converted into a function call
D) It is ignored by the compiler
Answer: B) It is converted into a combination of a conditional check and a jump