Intermediate Code Generation in Compiler Design (original) (raw)

Last Updated : 10 Mar, 2026

In the analysis-synthesis model of a compiler, the front end of a compiler translates a source program into an independent intermediate code, then the back end of the compiler uses this intermediate code to generate the target code (which can be understood by the machine). The benefits of using machine-independent intermediate code are:

1-34

Intermediate Code Generation is a stage in the process of compiling a program, where the compiler translates the source code into an intermediate representation. This representation is not machine code but is simpler than the original high-level code. Here’s how it works:

If we generate machine code directly from source code then for n target machine we will have optimizers and n code generator but if we will have a machine-independent intermediate code, we will have only one optimizer. Intermediate code can be either language-specific (e.g., Bytecode for Java) or language. independent (three-address code). The following are commonly used intermediate code representations:

**Postfix Notation

**Example 1: The postfix representation of the expression (a + b) * c is : ab + c *
**Example 2: The postfix representation of the expression (a - b) * (c + d) + (a - b) is : ab - cd + *ab -+
Read more: Infix to Postfix

**Three-Address Code

While a standard three address statement includes three references, there are instances where a statement may contain fewer than three references, yet it is still categorized as a three address statement.
**Example: The three address code for the expression a + b * c + d : T1 = b * c T2 = a + T1 T3 = T2 + d; T 1 , T2 , T3 are temporary variables.

There are 3 ways to represent a Three-Address Code in compiler design:
i) Quadruples
ii) Triples
iii) Indirect Triples
Read more: Three-address code

**Syntax Tree

The syntax tree not only condenses the parse tree but also offers an improved visual representation of the program's syntactic structure,
**Example: x = (a + b * c) / (a - b * c)
Parse Tree

Key Points: