All mock tests are FREE till 31 December — register to save your progress
Paper 2 CS · UNIT 08 · MOCK TEST

Mock 8 – Semantic Analysis, Code Generation & Optimisation (Part 1)

Unit 8: Theory of Computation and Compilers · 17 questions · about 20 minutes. Press End Mock any time to see your score and the correct answers.

All 10 topic-wise mocks in this unit
0 / 17 answered 00:00
Q1. Which of the following is not a part of the general activation record of a procedure?

Directions (Q91–95): Consider the following Three Address Code sample for solving the questions:

100: t1 = y + 2
101: initial = x / t1
102: limit = 10
103: if i > j goto 105
104: goto 111
105: if num > b goto 107
106: goto 111
107: num = limit - 1
108: b = y + 2
109: i = i - num
110: goto 103
111: j = i - num
112: k = j + b
Q2. Which of the following is the optimized version of the TAC given in the passage?

Directions (Q91–95): Consider the following Three Address Code sample for solving the questions:

100: t1 = y + 2
101: initial = x / t1
102: limit = 10
103: if i > j goto 105
104: goto 111
105: if num > b goto 107
106: goto 111
107: num = limit - 1
108: b = y + 2
109: i = i - num
110: goto 103
111: j = i - num
112: k = j + b
Q3. Which of the following is the correct high level code for the TAC given in the passage?

Directions (Q91–95): Consider the following Three Address Code sample for solving the questions:

100: t1 = y + 2
101: initial = x / t1
102: limit = 10
103: if i > j goto 105
104: goto 111
105: if num > b goto 107
106: goto 111
107: num = limit - 1
108: b = y + 2
109: i = i - num
110: goto 103
111: j = i - num
112: k = j + b
Q4. What blocks do Block 3 and Block 5 dominate in the flow graph for the TAC given in the passage? (Basic blocks: B1 = 100–102, B2 = 103, B3 = 104, B4 = 105, B5 = 106, B6 = 107–110, B7 = 111–112)

Directions (Q91–95): Consider the following Three Address Code sample for solving the questions:

100: t1 = y + 2
101: initial = x / t1
102: limit = 10
103: if i > j goto 105
104: goto 111
105: if num > b goto 107
106: goto 111
107: num = limit - 1
108: b = y + 2
109: i = i - num
110: goto 103
111: j = i - num
112: k = j + b
Q5. Which of the following is the correct flow graph (adjacency matrix of basic blocks B1–B7, row → column means an edge) for the TAC given in the passage?
Q6. Regarding code optimization (peephole optimization), choose the correct sequence
A. Algebraic Simplification
B. Use of machine idioms
C. Redundant-instruction elimination
D. Flow of control optimization
E. Improved target code
Choose the correct answer from the options given below:
Q7. Match List I with List II
List IList II
A. Conflict ResolutionI. Three-Address Code
B. Common SubexpressionII. Precedence
C. QuadruplesIII. Syntax Directed Translations
D. L-Attributed definitionsIV. Directed Acyclic Graph (DAG)
Q8. Which of the following tasks could be attained using syntax trees in compiler design?
(A) Type Checking
(B) Code Generation
(C) Code Optimization
(D) Error Handling
Choose the correct answer from the options given below:
Q9. Arrange the following phases in the correct order as they typically occur in the compilation process.
(A) Lexical Analysis
(B) Semantic Analysis
(C) Syntax Analysis
(D) Intermediate Code Generation
(E) Code Optimization
Choose the correct answer from the options given below:
Q10. One of the purposes of using intermediate code in compilers is to:
Q11. Three-address code can be represented in special structures known as:
(A) Quadruples
(B) Triples
(C) Patterns
(D) Indirect Triples
Choose the correct answer from the options given below:
Q12. Arrange the following phases of a compiler in their order of execution (start to end):
(a) Target code generation
(b) Syntax analysis
(c) Code optimization
(d) Semantic analysis
(e) Lexical analysis
Choose the correct answer from the options given below:
Q13. Which phase of the compiler checks the grammar of the program?
Q14. A compiler for a high-level language that runs on one machine and produces code for another machine is called a
Q15. Which of the following statements are correct?
A. Syntax-directed translation can be applied in type checking.
B. Syntax-directed translation can be used in 3-address code generation.
C. Syntax-directed translation can be used in the construction of syntax trees.
D. Syntax-directed translation can be used to recognise valid tokens.
Choose the most appropriate answer from the options given below:
Q16. Which of the following statements are correct?
1. The first three-address instruction in the intermediate code is a leader.
2. The instruction exactly in the middle of the given three-address code is a leader.
3. Any instruction that is the target of a conditional or unconditional jump is a leader.
4. Any instruction that immediately follows a conditional or unconditional jump is a leader.
Choose the correct answer from the options given below:

Directions (Q96–100): A Turing machine for the language L = {anbmcndm | n ≥ 1, m ≥ 1} is designed. The model is M = ({q0, q1, q2, q3, q4, q5, q6, q7, qf}, {a, b, c, d}, {a, b, c, d, X1, X2, Y1, Y2, B}, δ, q0, B, {qf}), and part of δ is given in the transition table below. X1 and X2 are used to mark a's and c's, and Y1 and Y2 to mark b's and d's.

abcdX1X2Y1Y2B
q0(q1, X1, R)M2
q1(q1, a, R)(q1, b, R)M1(q1, X2, R)
q2(q2, a, L)(q2, b, L)(q2, X1, R)(q2, X2, L)
q3M3(q4, Y1, R)(q6, X2, R)
q4(q4, b, R)(q5, Y2, L)M5(q4, Y2, R)
q5(q5, b, L)(q5, X2, L)M4(q5, Y2, L)
q6(q6, X2, R)(q7, Y2, R)
q7(q7, Y2, R)(qf, B, R)
Q17. What is the move in the cell numbered M4 of the table?