TYPES OF COMPILERS

TYPES OF COMPILERS

Hello Readers, in this blog we will explore the types of compilers and elaborate each one in detail. Before going over to its types, let us first understand what a compiler is and its functions.


No alt text provided for this image


A] What is a Compiler?

--> A compiler is a computer program that translates source code from a high level programming language(ex:Perl,Ruby, COBOL etc..) into a lower level language(especially assembly language and machine code) to create an executable program.

A compiler is likely to perform all of the following operations: pre-processing, lexical analysis, syntax analysis, semantic analysis(syntax directed translation),code optimization and code generation.

Compilers implement these operations in phases that promote efficient design and correct transformation of source language(input) to target language(output).

Thus a compiler software cannot afford to make mistakes or generate incorrect results in output, because these errors are often difficult to detect and rectify!

No alt text provided for this image




B] Types of Compilers

--> Now that we know what a compiler does, let us try to understand the types of compilers.

Broadly, there are three types of Compilers:

  • Single Pass Compilers
  • Two Pass Compilers
  • Multi pass Compilers

Lets see each one in detail:

I] Single Pass Compiler

No alt text provided for this image

In a single pass Compiler the source code directly transforms into machine code. For example, Pascal language.

Note the following points:-

  • One-pass compiler is used to traverse the program only once. The one-pass compiler passes only once through the parts of each compilation unit. It translates each part into its final machine code.
  • In the one pass compiler, when the line source is processed, it is scanned and the token is extracted.
  • Then the syntax of each line is analyzed and the tree structure is build. After the semantic part, the code is generated.
  • The same process is repeated for each line of code until the entire program is compiled.

But this has certain limitations:-

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.


II] Two Pass Compiler


No alt text provided for this image


A Two pass Compiler is divided into two sections, viz.

1. Front end: It maps legal code into Intermediate Representation (IR).

2. Back end: It maps IR onto the target machine

The Two pass compiler method simplifies the re-targeting process. It also allows multiple front ends.

1}. First Pass: It refers to

· (a). the Front end of a compiler

· (b). the Analysis part

· (c). It is Platform independent

In first pass the included phases are Lexical analyzer, syntax analyzer(parser), semantic analyzer, intermediate code generator;collectively these four phases work as the front end and the analysis part implies that all phases analyze the High level language and convert them to a three address code representation.The first pass is platform independent because the output of first pass is a three address code which is useful for every system and the requirement is to change the code optimization and code generator phase which come in the second pass.

2}.Second Pass: It refers to

· (a). the Back end of a compiler

· (b). the Synthesis Part

· (c). It is Platform dependent

In second pass the included phases are Code optimization and Code generator;collectively these two phases work as the back end and the synthesis part implies that it is taking input as the three address code representation and converting them into Low level language/assembly language.The second pass is platform dependent because the final stage of a typical compiler converts the intermediate representation of a program into an executable set of instructions which is dependent on the system.


III] Multi Pass Compiler

No alt text provided for this image

The multi pass compiler processes the source code or syntax tree of a program several times. It divided a large program into multiple small programs and process them. It develops multiple intermediate codes. All of these multi pass take the output of the previous phase as an input. So it requires less memory. It is also known as 'Wide Compiler'.

Advantages of a multi pass compiler are:-

· Machine Independent: Since the multiple passes include a modular structure, and the code generation decoupled from the other steps of the compiler, the passes can be reused for different hardware/machines.

· More Expressive Languages: Multiple passes obviate the need for forward declarations, allowing mutual recursion to be implemented elegantly. The prime examples of languages requiring forward declarations due to the requirement of being compilable in a single pass include C and Pascal, whereas Java does not have forward declarations.

Now that we saw the types of compilers according to their pass structure, lets see some more types of compilers.

C] Other Types of Compilers

1} Cross Compiler

No alt text provided for this image

A compiler which runs on one machine and and produces the target code for another machine. Such compiler is called a cross-compiler.

i.e The compiler runs on platform X and target code runs on platform Y. Ex:Free Pascal

2} Load & Go Compiler

Compilers usually produce either absolute code that is executed immediately upon conclusion of the compilation or object code that is transformed by a linking loader into absolute code.

But this compiler generates machine code and immediately executes it.

It means that compilation,assembly, or link steps are not separated from program execution.

Examples are Dartmouth BASIC, WATFOR ..

3} Threaded Code Compiler

No alt text provided for this image

The threaded code has a form that essentially consists entirely of calls to subroutines. And the compiler replaces given strings in the source with given binary code while compiling.

4} Just-In-Time Compiler (JIT)

No alt text provided for this image

In this type of compiler, applications are delivered in byte code,which is compiled to native machine code just prior to execution.

The JIT compiler is enabled by default and is activated when a java method is called.The JIT compiler compiles the bytecodes of that method into native machine,compiling it 'just in time' to run.When a method has been compiled, the JVM calls the compiled code of that method directly instead of interpreting it.

5} Parallelizing Compiler

No alt text provided for this image

Parallelizing Compiler converts a serial input program into a form suitable for efficient execution on a parallel computer architecture.

The goal of automatic parallelization is to relieve programmers from the hectic and error-prone manual parallelization process.

Examples of Parallelizing compilers are the Rice Fortran D compiler,Polaris compiler.

6}Incremental Compiler

No alt text provided for this image

Incremental compiler is a compiler which performs the recompilation of only modified source rather than compiling the whole source program.

It tracks the dependencies between the output and source program.The process of incremental compilation is effective for maintenance.

Examples are SWI-prolog, the eclipse platform which has a java incremental compiler etc..

Hope you found the blog useful and informative!

Klein Senteza

Graduate of Makerere University.

1 个月

Very useful

回复
Aishwarya Yuvaraj Phirke

SDE III @HSBC | Ex-SDE Intern @Syngenta | RoboSoft Core Software Developer @The Robotics Forum, VIT Pune | TEDxVITPune | Ex-Vice #Chairperson @EPEC VIT, Pune.

4 年

Very informative!!

回复
Isha Bansod

MS Computational Science at UvA and VU

4 年

To the point and very informative!

Manav Chandak

Kemical Konnect | Synthocure Pharma LLP

4 年

Great work!

Utkarsh Gogna

MSCS Graduate Student at Northeastern University Boston

4 年

Great research,very helpful

要查看或添加评论,请登录

社区洞察

其他会员也浏览了