What is the Difference Between Single Pass and Multipass Compiler

The main difference between single pass and multipass compiler is that a single pass compiler is a compiler that passes the source code through each compilation unit only once while a multipass compiler separates compilation into multiple passes, where each pass would continue with the result of the previous pass.

A computer program is a set of instructions for the computer to perform a certain task. Usually, programmers write programs using high-level programming languages. However, the computer does not understand these instructions. Therefore, it is necessary to convert the source code into a machine-understandable machine code. A compiler is a software that converts source code into machine code, and single pass and multipass compiler are two types of compilers.

Key Areas Covered

1. What is a Single Pass Compiler
     – Definition, Functionality
2. What is a Multipass Compiler
     – Definition, Functionality
3. What is the Difference Between Single Pass and Multipass Compiler
     – Comparison of Key Differences

Key Terms

Single Pass compiler, Multipass compiler

Difference Between Single Pass and Multipass Compiler - Comparison Summary

What is a Single Pass Compiler

There are a number of stages in the compilation process. A single pass compiler makes a single pass through the source text, parsing, analyzing, and generating code only once. In other words, it allows the source code to pass through each compilation unit only once. It immediately translates each code section into its final machine code. 

Difference Between Single Pass and Multipass Compiler

Figure 1: Compiler

Main stages of single pass compiler are lexical analysis, syntactical analysis and code generator. First, the lexical analysis scans the source code and divides it into tokens. Every programming language has a grammar. It represents the syntax and legal statements of the language. Then, the syntactical analysis determines the language constructs described by the grammar. Finally, the code generator generates the target code. Overall, single pass compiler does not optimize the code. Moreover, there is no intermediate code generation.  

What is Multipass Compiler

A multipass compiler makes the source code go through parsing, analyzing, generating, etc. multiple times while generating intermediate code after each stage. It converts the program into one or more intermediate representations in steps between source code and machine code. It reprocesses the entire compilation unit in each sequential pass.

Each pass takes the result of the previous pass as the input and creates an intermediate output. Likewise, in each pass, the code improves until the final pass generates the final code. A multipass compiler performs additional tasks such as intermediate code generation, machine dependent code optimization and machine independent code optimization.

Main Difference - Single Pass vs Multipass Compiler

Figure 2: Multipass Compiler

There are multiple advantages to multipass compilers. They are machine independent and include a modular structure. The code generation decouples from the other steps of compilation. Therefore, the passes can be reused for different machines or hardware. Furthermore, it represents more complex and expressive languages.

Difference Between Single Pass and Multipass Compiler

Definition

A single pass compiler is a type of compiler that passes through the parts of each compilation unit only once, immediately translating each code section into its final machine code. A multipass compiler is a type of compiler that processes the source code or abstract syntax tree of a program several times. Hence, these definitions explain the main difference between single pass and multipass compiler.

Speed

Speed is a major difference between single pass and multipass compiler. A multipass compiler is slower than single pass compiler because each pass reads and writes an intermediate file.

Synonyms

A single pass compiler is also called a narrow compiler while a multipass compiler is called a wide compiler.

Scope

Moreover, a single pass compiler has a limited scope whereas a multipass compiler has a greater scope.

Code Optimization

Another difference between single pass and multipass compiler is that there is no code optimization in single pass compiler, unlike in multipass compiler, which has code optimization.

Intermediate Codes

Intermediate codes also makes a difference between single pass and multipass compiler. There is no intermediate code generation in single pass compilers. However, there is an intermediate code generation in multipass compilers.

Compilation Time

Furthermore, a single pass compiler takes a minimum time to compile when compared to a multipass compiler.

Memory Consumption

Also, the memory consumption in a multipass compiler is higher than that of a single pass compiler. Thus, this is another difference between single pass and multipass compiler.

Programming Languages

Programming languages such as Pascal can be implemented using a single pass compiler while programming languages such as Java can be implemented using a multipass compiler. Hence, this is yet another difference between single pass and multipass compiler.

Conclusion

Single pass and multipass compiler are two types of compilers. The difference between single pass and multipass compiler is that a single pass compiler is a compiler that passes the source code through each compilation unit only once while a multipass compiler separates compilation into multiple passes, where each pass would continue with the result of the previous pass.

Reference:

1. “pass1 And 2 Compiler.” Scribd, Scribd, Available here.
2. “One-Pass Compiler.” Wikipedia, Wikimedia Foundation, 23 Mar. 2018, Available here.
3. “Multi-Pass Compiler.” Wikipedia, Wikimedia Foundation, 8 Feb. 2018, Available here.

Image Courtesy:

1. “Compiler” By I, Surachit (CC BY-SA 3.0) via Commons Wikimedia
2. “Multi-passcompiler” By Kenstruys – Own work (Public Domain) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply