Translate A=b(c+d)/eA = -b * (c + d)/e into Quadruples and Triples

Translate A=b(c+d)/eA = -b * (c + d)/e into Quadruples and Triples

Verified Sources
Sep 12, 2026

Intermediate Code: Quadruples vs Triples (3-Address Code)

Given the expression A=b(c+d)/e,A = -b * (c + d)/e, we translate it into intermediate representations:

  • keyword: An array of instructions of form (op,arg1,arg2,result)(op,arg1,arg2,result).
  • keyword: An array of instructions of form (op,arg1,arg2)(op,arg1,arg2) where results are referenced by index.
  • keyword: IR where each instruction uses at most two operands plus an implicit destination.
  • keyword: A symbol (e.g., t1t1) storing intermediate results.
  • keyword: Rule that multiplication/division bind tighter than addition/subtraction.

A standard evaluation order that respects precedence is:

  1. Compute the parenthesized sum (c+d)(c+d).
  2. Multiply by bb and apply the unary minus.
  3. Divide by ee.
  4. Assign to AA.

The key question is how unary minus is represented:

  • As a separate keyword: Often implemented as t:=xt := -x or as t:=0xt := 0 - x. Below, we use an explicit unary operation negneg (common in textbooks/exercises), but I also show the alternative form using 00 where needed.

Mermaid view of the data flow:

Construct triples (then map to quadruples)

  1. 1
    Step 1

    Create a temp for c+dc+d (call it t1t1).

  2. 2
    Step 2

    Compute t2=bt1t2 = b * t1, then compute the unary negation t3=t2t3 = -t2.

  3. 3
    Step 3

    Compute t4=t3/et4 = t3 / e.

  4. 4
    Step 4

    Final instruction sets A=t4A = t4.

Triples Representation

In triples form, each instruction is stored as: (op,arg1,arg2)(op, arg1, arg2) and later instructions reference prior results by index. If the triple number is ii, its value can be referenced as [i][i].

We will build 4 computation triples (then a final assignment as a 5th “triple-like” form).

Let:

  • Triple 1: t1=c+dt1 = c + d
  • Triple 2: t2=bt1t2 = b * t1
  • Triple 3: t3=t2t3 = -t2 (unary negation)
  • Triple 4: t4=t3/et4 = t3 / e
  • Triple 5: A=t4A = t4 (assignment)

Triples list

  1. (+,c,d)(+, c, d) ⟹ value is [1]=c+d[1]=c+d
  2. (,b,[1])(*, b, [1])[2]=b(c+d)[2]=b*(c+d)
  3. (neg,[2],_)(neg, [2], \_)[3]=([2])[3]=-([2])
  4. (/,[3],e)(/, [3], e)[4]=b(c+d)/e[4]= -b*(c+d)/e
  5. (=,A,[4])(=, A, [4]) ⟹ assign

Note: Some conventions encode unary neg as (neg,arg,_)(neg,arg,\_) with a dummy second field. If your course uses (,0,x)( - , 0, x) instead, see the alternative in the accordion.

Quadruples Representation

In quadruples form, each instruction is: (op,arg1,arg2,result)(op, arg1, arg2, result)

We explicitly name temporaries as results of each instruction:

  • t1,t2,t3,t4t1, t2, t3, t4

Quadruples table

#oparg1arg2result
1+cdt1
2*bt1t2
3negt2t3
4/t3et4
5=At4A

This is equivalent to:

t1=c+d,t2=bt1,t3=t2,t4=t3/e,A=t4.t1 = c+d,\quad t2 = b\cdot t1,\quad t3 = -t2,\quad t4 = t3/e,\quad A=t4.

type="tip" title="Pro Tip: Choose a consistent unary minus convention" content="If your course disallows unary ops, rewrite negation as (−, 0, x). Then every operation becomes binary, making quadruples/triples uniform."

type="warning" title="Warning: Parentheses must be computed first" content="If you generate code that computes bcb*c before c+dc+d, you violate the precedence implied by (c+d)(c+d). Always start with the subexpression inside parentheses."

1: (+, c, d) 2: (*, b, [1]) 3: (neg, [2], _) 4: (/, [3], e) 5: (=, A, [4])

Common variations (to match your course format)

Computation Order Breakdown

How the IR instructions map to subexpressions

Expression Lowering Pipeline

Lower (c + d)

1

Create a temp: t1=c+dt1=c+d"

Lower b * (c + d)

2

Create temp: t2=bt1t2=b*t1"

Lower unary minus

3

Create temp: t3=t2t3=-t2"

Lower division by e

4

Create temp: t4=t3/et4=t3/e"

Assign to A

5

Final: A=t4A=t4"

Quadruples/Triples Quick Check

1 / 4
Question · Term

What is the difference between quadruples and triples?

Click to reveal
Answer · Definition

Quadruples store (op,arg1,arg2,result). Triples store (op,arg1,arg2) and reference results by index.

Knowledge Check

Question 1 of 4
Q1Single choice

In quadruple form, which tuple includes the destination/result field explicitly?