Open In App
Related Articles

Single Pass vs Two-Pass (Multi-Pass) Compilers

Improve Article
Save Article
Like Article

This article explores the concept of compiler passes in the field of software development, focusing on two types: the Single Pass Compiler and the Two-Pass Compiler (Multi-Pass Compiler). It explains their differences, advantages, and use cases, providing insights into the world of compiler design.

What is a Compiler Pass?

A Compiler pass refers to the traversal of a compiler through the entire program. Compiler passes are of two types Single Pass Compiler, and Two Pass Compiler or Multi-Pass Compiler. These are explained as follows. 

Types of Compiler Pass

1. Single Pass Compiler

If we combine or group all the phases of compiler design in a single module known as a single pass compiler. 

Single Pass Compiler

Single Pass Compiler

In the above diagram, there are all 6 phases are grouped in a single module, some points of the single pass compiler are as:

  • A one-pass/single-pass compiler is a type of compiler that passes through the part of each compilation unit exactly once.
  • Single pass compiler is faster and smaller than the multi-pass compiler.
  • A disadvantage of a single-pass compiler is that it is less efficient in comparison with the multipass compiler.
  • A single pass compiler is one that processes the input exactly once, so going directly from lexical analysis to code generator, and then going back for the next read.

Note: Single pass compiler almost never done, early Pascal compiler did this as an introduction.

Problems with Single Pass Compiler

  • We can not optimize very well due to the context of expressions are limited.
  • As we can’t back up and process, it again so grammar should be limited or simplified.
  • Command interpreters such as bash/sh/tcsh can be considered Single pass compilers, but they also execute entries as soon as they are processed.

2. Two-Pass compiler or Multi-Pass compiler

A Two pass/multi-pass Compiler is a type of compiler that processes the source code or abstract syntax tree of a program multiple times. In multi-pass Compiler, we divide phases into two passes as:

Two-Pass compiler

First Pass is referred as

Second Pass is referred as

  • Back end
  • Synthesis Part
  • Platform Dependent

Problems that can be Solved With Multi-Pass Compiler

First: If we want to design a compiler for a different programming language for the same machine. In this case for each programming language, there is a requirement to make the Front end/first pass for each of them and only one Back end/second pass as: 

Problem 1

Second: If we want to design a compiler for the same programming language for different machines/systems. In this case, we make different Back end for different Machine/system and make only one Front end for the same programming language as: 

Problem 2

Difference between One Pass and Two Pass Compiler 

One passTwo-pass
It performs Translation in one passIt performs Translation in two pass
It scans the entire file only once.It requires two passes to scan the source file.
It generates Intermediate code It does not generate Intermediate code
It is faster than two pass assemblerIt is slower than two pass assembler
A loader is not required A loader is required.
No object program is written.A loader is required as the object code is generated.
Perform some professing of assembler directives.Perform processing of assembler directives not done in pass-1

The data structure used are:

The symbol table, literal table, pool table, and table of incomplete.

The data structure used are:

The symbol table, literal table, and pool table.

These assemblers perform the whole conversion of assembly code to machine code in one go.These assemblers first process the assembly code and store values in the opcode table and symbol table and then in the second step they generate the machine code using these tables.
Example: C and Pascal uses One Pass Compiler.Example: Modula-2 uses Multi Pass Compiler.


In conclusion, the choice between a single-pass and a two-pass compiler depends on specific requirements and trade-offs. Single-pass compilers are faster and more compact but have limitations in optimization and grammar complexity. Two-pass compilers, on the other hand, offer greater flexibility for different programming languages and machine systems but come at the cost of additional processing. Understanding these distinctions is crucial for designing effective compilers.

Last Updated : 20 Sep, 2023
Like Article
Save Article
Similar Reads