Compiler Design — Phases of Compiler

Genius Learner
2 min readAug 5, 2020

Compiler phases :

Basically compiler phases can be divided into 2 parts . or ,

A compiler has 2 phases -

1) Analysis / front end phase

2) Synthesis/Back end

How compiler works /compiler phases/ structure of compiler

The compilation of compiler process contains the sequence of various phases. Each phase takes source program in one representation and produces output in another representation. Each phase takes input from its previous stage.

Phases :

Lexical analysis

It reads the program and converts it into token . It converts a stream of lexeme into stream of token.It takes source code as input.It reads the source program one character at a time and convert it into meaningful lexeme.Lexical analyzer represents these lexeme in the form of tokens.

Lexeme means sequence of character.

Syntax Analyzer

These next phase is called the syntax analysis or parsing.It takes the token product by lexical analysis as input and generates a parse tree (or syntax tree ) .In syntax analysis phase , the parser check that the expression mode by the token is syntactically correct or not.

It takes all the token one by one and uses context free grimmer to construct the parse tree.

Semantic analyzer

It verifies the parse tree , whether its meaningful or not . For example , assignment of values is between compatible data type, and adding string to integer , also the semantic analyzer keeps track of identifiers .their types and expressions , whether , identifiers are declared before use or not etc .

The semantic analyzer produces an interpret syntax tree as an output

Intermediate code generator

In the intermediate code generator, compiler generates the source code into the intermediate code . Intermediate code is generated between high level and the machine language . The intermediate code should be generated in such a way that the program can be easily translated it into the target code.popular intermediates codes-there address code.

Intermediate code is concerted to machine language using the lost two phases which are platform dependent

Code optimizer

--

--

Genius Learner

I am an teacher on online and and offline . Love to teach everyone.