GATE CS 2024 Set 2 — Question 43
MCQ+2 / -0.67MediumThree-Address CodeIntermediate Code GenerationCompiler Design
Compiler Design → Intermediate Code Generation → Three-Address Code
Last updated
Question
Consider the following expression: . The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6).
Which one of the following options fills in the missing entries CORRECTLY?
| (0) | + | ||
| (1) | |||
| (2) | uminus | (1) | |
| (3) | |||
| (4) | / | ||
| (5) | + | (3) | (4) |
| (6) | |||
| (7) | = | (6) | (5) |
A.
(1) =[] (3) * (0) (2) (6) []=
B.
(1) []= (3) – (0) (2) (6) =[] (5)
C.
(1) =[] (3) * (0) (2) (6) []= (5)
D.
(1) []= (3) – (0) (2) (6) =[]
Correct answer
(A) (1) =[] s i (3) (0) (2) (6) []= x i
Solution
The expression is .
We can break this down into three-address code (triples):
(1)
(3)
(6)
We can break this down into three-address code (triples):
1.Compute :
(0) + p r2.Access : This requires an array load operation. In triples, this is often denoted as
=[] s i (load from array at index ). This corresponds to triple (1).3.Compute :
(2) uminus (1)4.Compute : This multiplies the result of (0) and (2). So triple (3) is
* (0) (2).5.Compute :
(4) / u w6.Compute the sum:
(5) + (3) (4)7.Assign the result to : The assignment requires an array store operation. The LHS is the target. In the given table, triple (7) is
Thus:= (6) (5), which means "assign the value of (5) to the location defined by (6)". Therefore, triple (6) must define the location . The operation for array store access (l-value) is typically []= x i. (1)
=[] s i(3)
* (0) (2)(6)
[]= x iThis matches Option (A).More questions on Intermediate Code Generation
2024 Set 2 Q21Consider the following two sets: | Set X | Set Y | | :--- | :--- | | P. Lexical Analyzer | 1.…2024 Set 1 Q26Which of the following is/are Bottom-Up Parser(s)?2024 Set 2 Q29Which of the following statements is/are FALSE?2024 Set 1 Q37Consider the following syntax-directed definition (SDD). | Production | Semantic Rules | | ------ |…2024 Set 1 Q38Consider the following grammar , with as the start symbol. The grammar has three…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free