Types of compiler

Types of compilers:

Single-pass compilers: It is a type of compiler that processes the source code only once.
Multi-pass compilers: It is a type of compiler that processes the source code multiple time(to convert High-level language to Low-level language) i.e. to convert source code to target/ object code.
There are two phases of the compilation process:

Analysis: It breaks up the source code/program into small parts and creates an intermediate representation of the source program.
Synthesis phase: It takes the intermediate representation of the source program as input and creates the desired target code/program.
There are five phases of a compiler:

Lexical analyzer 

Reads the program and converts it into tokens using the LEX tool.
Tokens are defined by regular expressions which are understood by the lexical analyzer
Removes white spaces, comments, tabs.
Syntax analyzer

Constructs the parse tree.
Takes the tokens one by one and uses CFG to construct the parse tree.
Using these productions we can represent what the program actually is.
The input has to be checked whether it is in the desired format or not.
Semantic analyzer

Verifies the parse tree, whether it is meaningful or not.
It uses the parse tree and info in the symbol table to check the source program for semantic consistency with the language definition.
Intermediate code generator

Generates the intermediate code. Example: Three address codes.
This code is converted to machine language using the last two phases which are platform dependent. 
Code optimizer

We can get optimized code.
The code optimization phase attempts to improve the intermediate code so that it runs faster and consumes fewer resources.
Target code generator

The final phase of the compiler generates the target code/assembly code.
Symbol Table

The data structure is used by the compiler to store all the information related to identifiers, for example, their types, scope, location name, etc.
It helps the compiler to function smoothly by finding the identifiers quickly.
All the phases interact with the symbol table manager.
Error handler

It is a module that takes care of the events which are encountered during compilation and it takes care to continue the compilation process even if the error is encountered. The task of the error handling process is to detect each error, report it to the user and implement them to handle errors.
Posted on by