GATE / CS ARCHIVE

GATE CSE 2024 SET 2 / QUESTION 43

Fill array-load, multiplication and destination triples

Compiler Design · Intermediate Code · Full GATE CSE 2024 Set 2 paper

GATE 2024 Set 2, Q43 2 marks · MCQ
Report issue

Intermediate Code

Question 43, GATE 2024: Expression x[i]=(p+r)*−s[i]+u/w has triples (0) + p r; (1) missing; (2) uminus (1); (3) missing; (4) / u w; (5) + (3) (4); (6) missing; (7) = (6) (5). A fills (1) =[] s i, (3) * (0) (2), (6) []= x i. B uses []= s i, subtraction, =[] x (5). C agrees with A except []= x (5). D uses []= s i, subtraction, =[] x i.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: Follow the expression tree from input values to the final indexed assignment.

1. Derivation. Triple1 must read s[i], denoted =[] s i. Triple2 negates that value. Triple3 multiplies results(0) and(2), forming(p+r)×−s[i]. Triple6 identifies the destination x[i], denoted []= x i, and triple 7 stores the accumulated result(5) there. Only A has all three operations and the correct index i. In C the destination incorrectly uses the computed value(5) as its index.

2. Explanation and checks. A triple refers to the result of an earlier triple by its parenthesized index; (5), for example, denotes the computed right-hand-side value, not the source-language subscript i. Loading s[i] must precede negation. Multiplication then combines p+r with that negative value, followed by addition of u/w. The final destination must still be element i of x. Confusing an array read with a destination reference or substituting the computed value for i changes the program.

Original paper, page 30 · Answer key