There are three ways to store TAC in a table. Quadruples have four fields: op, arg1, arg2, result. Triples have three fields (op, arg1, arg2) and no result field: a later instruction refers to the result of an earlier one by that instruction's row number, written (k). Indirect triples keep the triples table and add a separate list of pointers that gives the execution order.
Take x=a∗(−b)+c. Its three-address code is:
t1 = uminus b
t2 = a * t1
t3 = t2 + c
x = t3
For a copy, the quadruple has the source in arg1 and the target in result. In a triple, the copy is written with the target in arg1 and the reference to the value in arg2.
For an indexed store x[i] = y or load x = y[i], quadruples use one entry, with the operators written []= and =[]. Triples need two entries, because there is no result field. The store x[i] = y is the triple (k) []=, x, i, followed by the triple (k+1) =, (k), y. The load x = y[i] is the triple (k) =[], y, i, followed by the triple (k+1) =, x, (k).
TABLE SIZE IN FIELDS
quadruples: 4n,triples: 3n,indirect triples: 3n+n
For a table of n entries, counting every field including blank ones and each pointer in the instruction list as one field. The same code does not always give the same number of entries in each form: an indexed assignment takes one quadruple but two triples, and a quadruple can store a result straight into a named variable where a triple needs a separate = entry.