Compiler Design - Phases of Compiler

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

Code optimizer is an optional phase. It is used to improve intermediate code so that output of the program cloud run faster and take less space . It removes the unnecessary lines of the code and arrange the sequence of statements in order to speed up the program execution without wasting resources.It is platform machine dependent or platform dependent. 

 

Target code generator

 It is the final stage of the compilation process. It takes the optimizer intermediate code as input and write code that machine can understand. The code generator translates the intermediate code into and sequence of relocatable machine code. It also machine dependent





 Important and Related post :

>> What is application software and system software
>> incremental model with details.
>> Software Engineering | Classification of Software Requirements
>>What is operating system 
>>What is traffic monitoring system 
>> what is computer virus and names of virus.
>>What is embedded control system  
>> What is compiler .
>> What is linker.
>> What is Interpreter
>> Modern Principles Of Software Development
>> Types of Software Testing
>> Software Testing | Basics
>> Software Engineering | Debugging Approaches




Post a Comment

0 Comments