What is the difference between One-Pass Compiler and Multi-Pass Compiler?

One-Pass Compiler

One pass compiler reads the code only once and then translates it. The one-pass compiler passes only once through the parts of each compilation unit. It can translate each part into its final machine program. In the one-pass compiler, when the line source is processed, it is scanned and the token is extracted. This is in contrast to a multi-pass compiler which modifies the program into one or more intermediate representations in steps between source program and machine program, and which convert the whole compilation unit in each sequential pass.

A one-pass compiler is fast since all the compiler code is loaded in the memory at once. It can process the source text without the overhead of the operating system having to shut down one process and start another. A one-pass tends to impose some restrictions upon the program constants, types, variables, and procedures that must be defined before they are used.

Multi-Pass Compiler

A multi-pass compiler can process the source code of a program multiple times. In the first pass, the compiler can read the source code, scan it, extract the tokens and save the result in an output file.

In the second pass, the compiler can read the output file produced by the first pass, build the syntactic tree and implement the syntactical analysis. The output of this phase is a file that includes the syntactical tree.

In the third pass, the compiler can read the output file produced by the second pass and check that the tree follows the rules of language or not. The output of the semantic analysis phase is the annotated tree syntax. This pass continues until the target output is produced.

Let us see the comparison between One-Pass and Multi-Pass Compiler.

One-Pass CompilerMulti-Pass Compiler
It reads the code only once and translates it at a similar time.
It reads the code multiple times, each time changing it into numerous forms.
They are faster.
They are "slower." As more number of passes means more execution time.
Less efficient code optimization and code generation.
Better code optimization and code generation.
It is also called a "Narrow compiler." It has limited scope.
It is also called a "wide compiler." As they can scan every portion of the program.
The compiler requires large memory.
The memory occupied by one pass can be reused by a subsequent pass; therefore, small memory is needed by the compiler.
Example − Pascal & C languages use one-pass compilation.
Example − Modula -2 languages use multi-pass compilation.