Generating Three-Address Code (Quadruples, Triples, Indirect Triples) for (x = a*(b+c) - d/e)

Generating Three-Address Code (Quadruples, Triples, Indirect Triples) for (x = a*(b+c) - d/e)

Verified Sources
Nov 4, 2026

To generate intermediate code for the expression x=a∗(b+c)−d/e,x = a*(b+c) - d/e, we typically follow a standard compilation strategy: break the expression into subexpressions, compute each subexpression into a temporary location, and then combine temporaries according to operator precedence and evaluation order.

Key representations you asked for:

  • Three-address code
  • Quadruple
  • Triple
  • Indirect triple

Because I couldn’t complete the required web research (tool usage limit), the final content below is derived from standard compiler-construction definitions and conventions commonly used in coursework and textbooks.


Three-Address Code / Quadruple / Triple (Intermediate Code) - Compiler Construction

Three-address code generation (with temporaries)

  1. 1
    Step 1

    Use precedence: parentheses first, then multiplication/division, then subtraction. So compute (b+c)(b+c), then a∗(b+c)a*(b+c), compute d/ed/e, then subtract.

  2. 2
    Step 2

    Let t1t1 hold (b+c)(b+c). Generate: t1=b+ct1 = b + c.

  3. 3
    Step 3

    Let t2t2 hold a∗t1a*t1. Generate: t2=a∗t1t2 = a * t1.

  4. 4
    Step 4

    Let t3t3 hold d/ed/e. Generate: t3=d/et3 = d / e.

  5. 5
    Step 5

    Let t4t4 hold t2−t3t2 - t3. Generate: t4=t2−t3t4 = t2 - t3.

  6. 6
    Step 6

    Generate: x=t4x = t4.

Generated three-address code (TAC)

Using temporaries (t1, t2, t3, t4), the three-address code is:

  1. (t1 = b + c)
  2. (t2 = a * t1)
  3. (t3 = d / e)
  4. (t4 = t2 - t3)
  5. (x = t4)

Note: Each TAC instruction is of the form ([result] = [arg1]\ \text{op}\ [arg2]) (assignment has one operand target but still fits the “three-address” style when viewed as an operation with operands plus destination).

Pro Tip

When producing TAC, always compute the deepest parentheses first, then higher-precedence operators (* and /) before lower-precedence operators (+ and -). This determines the temporary dependencies and affects the triple/quadruple indices.

Quadruple Representation

A quadruple list is written as: [ (op,\ arg1,\ arg2,\ result) ] The destination (result) is explicitly provided.

We map:

  • index 1 → (t1 = b + c)
  • index 2 → (t2 = a * t1)
  • index 3 → (t3 = d / e)
  • index 4 → (t4 = t2 - t3)
  • index 5 → (x = t4) (assignment can be represented as ( (=, t4, -, x)); some conventions store arg2 as blank)
#oparg1arg2result
1+bct1
2*at1t2
3/det3
4-t2t3t4
5=t4—x

Triple Representation

A triple list stores: [ (op,\ arg1,\ arg2) ] and the result of entry (i) is implied as “(t_i)” (or generally: the value produced by that triple’s index).

Thus the i-th triple produces (t_i).

ioparg1arg2
1+bc
2*a(1)
3/de
4-(2)(3)
5=(4)—

Where ((1)), ((2)), ((3)), ((4)) mean “use the results of those earlier triples.”

Warning on Conventions

Different courses/textbooks handle assignment in quadruples/triples differently (e.g., using op '=' with arg2 blank, or omitting '=' and treating x as a final target). Stick to one convention consistently across TAC → quadruple → triple → indirect-triple.

Indirect-Triple Representation

An indirect triple is commonly presented with:

  • a triple table (the (op, arg1, arg2) without explicit result names),
  • and a name table (or mapping) that says what temporary/register corresponds to the result of each triple index.

1) Triple table (same as before)

Let triple indices be 1..5:

  1. ( (+, b, c) )
  2. ( (*, a, 1) )
  3. ( (/, d, e) )
  4. ( (-, 2, 3) )
  5. ( (=, 4, \text{—}) )

2) Name table mapping indices to storage locations

Let the mapping be:

  • name(1) = t1
  • name(2) = t2
  • name(3) = t3
  • name(4) = t4
  • name(5) = x

Now when a triple references an earlier result by index, indirect-triple uses the name table to resolve which temporary holds that value.

Triple index itriple (op, arg1, arg2)name(i)
1(+, b, c)t1
2(*, a, 1)t2
3(/, d, e)t3
4(-, 2, 3)t4
5(=, 4, —)x

This is “indirect” because operands that refer to earlier computations are indices, and the actual storage (t1/t2/t3/t4/x) is obtained through the name mapping.

Consolidated View (TAC vs Quadruple vs Triple)

Same computation, different encoding

Common Exam-Style Variants

Knowledge Check

Question 1 of 4
Q1Single choice

Which subexpression should be computed first for x=a∗(b+c)−d/ex = a*(b+c) - d/e when generating TAC?