Skip to content
Official PYQ · 1997

GATE CS 1997 Q4.9 — Runtime Environments

Explain with AI

The expression (a∗b)∗c  op…( a * b) * c \; op \dots

where ‘op’ is one of ‘++’, ‘∗*’ and ‘↑\uparrow’ (exponentiation) can be evaluated on a CPU with single register without  storing the value of (a∗ba * b) if

Choose one option
View worked solution

Answer: A

The precedence of the operators is: ↑\uparrow (highest) > ∗* > ++ (lowest).

Let us analyze the evaluation of the expression (a∗b)∗c op …(a * b) * c \text{ op } \dots on a single-register CPU:

  • If op\text{op} is ++: Since ∗* has higher precedence than ++, the expression is grouped as [(a∗b)∗c]+…[(a * b) * c] + \dots. We can load aa, multiply by bb to get (a∗b)(a * b) in the register, multiply by cc to get [(a∗b)∗c][(a * b) * c], and then add the remaining terms. No intermediate storage of (a∗b)(a * b) is required.
  • If op\text{op} is ∗*: Since ∗* is left-associative, the expression is evaluated from left to right as [(a∗b)∗c]∗…[(a * b) * c] * \dots. We compute (a∗b)(a * b) in the register, multiply by cc, and continue multiplying the rest without storing any intermediate results.
  • If op\text{op} is ↑\uparrow: Since ↑\uparrow has higher precedence than ∗*, the expression is parsed as (a∗b)∗(c↑… )(a * b) * (c \uparrow \dots). To evaluate this, the right operand (c↑… )(c \uparrow \dots) must be evaluated before the final multiplication. If we compute (a∗b)(a * b) first, we must store its value to free the single register for evaluating (c↑… )(c \uparrow \dots).

Thus, the evaluation can be done without storing (a∗b)(a * b) if and only if op\text{op} is ++ or ∗*.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Runtime Environments questions