Question:

Consider the following expression: \(x[i] = (p + r) * -s[i] + u / w\). The following sequence shows the list of triples representing the given expression, with entries missing for triples (1), (3), and (6). \begin{center} \begin{tabular}{|c|c|c|c|} \hline (0) & \(+\) & \(p\) & \(r\)
\hline (1) & & &
\hline (2) & \texttt{uminus} & \((1)\) &
\hline (3) & & &
\hline (4) & \(/\) & \(u\) & \(w\)
\hline (5) & \(+\) & \((3)\) & \((4)\)
\hline (6) & & &
\hline (7) & \(=\) & \((6)\) & \(x[i]\)
\hline \end{tabular} \end{center} Which one of the following options fills in the missing entries CORRECTLY?

Show Hint

For three-address code generation, process the operations in order of precedence and create intermediate triples for subexpressions.
Updated On: Jan 23, 2025
  • \((1) =[] \, s[i], \, (3) * (0) (2), \, (6) =[] \, x[i]\)
  • \((1) =[] \, s[i], \, (3) - (0) (2), \, (6) =[] \, x (5)\)
  • \((1) =[] \, s[i], \, (3) * (0) (2), \, (6) [] = \, x (5)\)
  • \((1) []= s[i], \, (3) - (0) (2), \, (6) []= x[i]\)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

To break down the expression \(x[i] = (p + r) * -s[i] + u / w\) into intermediate triples:
1. Triple (0): \(+\) operation for \(p\) and \(r\). Already given as: \[ (0): + \, p \, r. \]
2. Triple (1): Assignment of \(-s[i]\). Using the unary minus (\texttt{uminus}) operator: \[ (1): =[] \, s[i]. \]
3. Triple (2): Unary minus applied to \((1)\). Already given as: \[ (2): \texttt{uminus} \, (1). \]
4. Triple (3): Multiplication of \((0)\) and \((2)\): \[ (3): * \, (0) \, (2). \]
5. Triple (4): Division of \(u\) and \(w\). Already given as: \[ (4): / \, u \, w. \]
6. Triple (5): Addition of \((3)\) and \((4)\): \[ (5): + \, (3) \, (4). \]
7. Triple (6): Assignment of \((5)\) to \(x[i]\): \[ (6): =[] \, x[i]. \] The correct missing entries are: \[ (1): =[] \, s[i], \, (3): * \, (0) \, (2), \, (6): =[] \, x[i]. \] Final Answer: \[ \boxed{\text{(A)}} \]
Was this answer helpful?
0
0

Top Questions on Syntax Directed Translation

Questions Asked in GATE CS exam

View More Questions