What three-address code is
Three-address code is the intermediate representation most compilers produce between parsing and machine code. Every instruction has at most three addresses: two operands and a result, as in t1 = b * c. A complicated expression is broken into a sequence of these, one operator at a time, with temporaries t1, t2, … holding the partial results. Because each step is so simple, it is easy to optimize and easy to translate to any target machine.
How expressions are translated
The generator follows operator precedence and associativity: * and / before + and -, left to right. For x = a + b * c - d it produces t1 = b * c, then t2 = a + t1, then t3 = t2 - d, and finally x = t3. Unary minus is written with the operator minus, as in the Dragon Book: a = b * -c + b * -c becomes t1 = minus c, t2 = b * t1, t3 = minus c, t4 = b * t3, t5 = t2 + t4, a = t5.
Quadruples, triples and indirect triples
These are three ways to store the same code. A quadruple has four fields, op, arg1, arg2 and result, so the row for t2 = b * t1 is (, b, t1, t2). A triple drops the result field and refers to earlier values by their position: (, b, (0)) means "b times whatever triple 0 computed". Triples save space, but moving one breaks every reference to it. Indirect triples fix that with a separate list of pointers to the triples, so an optimizer reorders the list and leaves the triples alone.
if, while, && and ||
Conditions become jumping code. if (a < b) x = 1 compiles to "if a < b goto L1", "goto L2", "L1: x = 1", "L2:". With && and ||, only as much of the condition is tested as needed: in x < 100 || x > 200, the second test is skipped when the first is true. while loops get a label at the test and a goto back to it at the end of the body. Labels can be switched to instruction numbers starting from 100, the form many university exam answers use.
The DAG and optimized code
For a block of assignments, the DAG (directed acyclic graph) merges repeated subexpressions into a single node. In a = b * -c + b * -c, b * -c is built once, so the code regenerated from the DAG is three instructions instead of six. The DAG also handles the classic Dragon Book Example 8.10 (a = b + c, b = a - d, c = b + c, d = a - d), where b and d end up on the same node.
What it does not do
It covers the statements compiler-design courses use for intermediate code: arithmetic expressions, unary minus, assignment, if, if-else, while, relational operators and && || !. It does not handle arrays, function calls, pointers or declarations, and the DAG and triples tabs are for straight-line code only.
Where this fits
Intermediate code is generated after parsing, usually as the parser reduces each rule. The parsing side is covered by the LR parser for bottom-up and the LL(1) parser for top-down, both built on the sets from the FIRST and FOLLOW calculator.