Intermediate Code Generation

Intermediate code generation is a phase between the front end (lexical, syntax, semantic analysis) and the back end (code optimization, code generation). The intermediate code is an abstract representation independent of the source or target machine.

Parser → Static Checker → Intermediate Code Generator → Code Generator

Advantages of Intermediate Representation

Forms of Intermediate Representation

1. Graphical Representation

Two forms: Syntax Trees and DAGs.

image.png

2. Postfix Notation

An operator follows its operands. No parentheses needed — unambiguous due to fixed operator arity.

Expression:  a = b * -c + b * -c

Postfix:     a  b  c  uminus  *  b  c  uminus  *  +  assign

3. Three-Address Code (TAC)

Each statement has the form:  x := y op z  — at most one operator on the right side. Compiler-generated temporaries are used.

Form Example
x = y op z t1 = a + b
x = op y t1 = -a
x = y a = b
goto L goto L1
if x goto L if a<b goto L1