Skip to content
Related Articles

Related Articles

Single pass, Two pass, and Multi pass Compilers

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 21 Nov, 2019
Improve Article
Save Article

We already know about all the Phases of Compiler design, now the Compiler Passes. A Compiler pass refers to the traversal of a compiler through the entire program. Compiler pass are two types: Single Pass Compiler, and Two Pass Compiler or Multi Pass Compiler. These are explained as following below.

1. Single Pass Compiler:
If we combine or group all the phases of compiler design in a single module known as single pass compiler.

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

  1. A one pass/single pass compiler is that type of compiler that passes through the part of each compilation unit exactly once.
  2. Single pass compiler is faster and smaller than the multi pass compiler.
  3. As a disadvantage of single pass compiler is that it is less efficient in comparison with multipass compiler.
  4. 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:

  1. We can not optimize very well due to the context of expressions are limited.
  2. As we can’t backup and process, it again so grammar should be limited or simplified.
  3. Command interpreters such as bash/sh/tcsh can be considered as Single pass compiler, but they also execute entry 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 multipass Compiler we divide phases in two pass as:

  1. First Pass: is refers as
    • (a). Front end
    • (b). Analytic part
    • (c). Platform independent

    In first pass the included phases are as Lexical analyzer, syntax analyzer, semantic analyzer, intermediate code generator are work as front end and analytic part means all phases analyze the High level language and convert them three address code and first pass is platform independent because the output of first pass is as three address code which is useful for every system and the requirement is to change the code optimization and code generator phase which are comes to the second pass.

  2. Second Pass: is refers as
    • (a). Back end
    • (b). Synthesis Part
    • (c). Platform Dependent

    In second Pass the included phases are as Code optimization and Code generator are work as back end and the synthesis part refers to taking input as three address code and convert them into Low level language/assembly language and second pass is platform dependent because final stage of a typical compiler converts the intermediate representation of program into an executable set of instructions which is dependent on the system.

With multi-pass Compiler we can solve these 2 basic problems:

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

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

    Differences between Single Pass and Multipass Compilers:

    ParametersSingle passmulti Pass

    My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!