Friday, May 15, 2020

CLASS 1 : INTRODUCTION






WORKING OF COMPILERS


The above diagram show the different working performed by the compiler in different phases such as:
1. LEXICAL ANALYSIS
2. SYNTAX ANALYSIS
3. INTERMEDIATE CODE GENERATOR
4. CODE OPTIMIZATION
5. CODE GENERATION

Compiler are used to convert high level language into machine level language.
Here whole program is broken into series of tokens.
Tokens are characters as a Input.

1. LEXICAL ANALYSIS:
In lexical analysis phase compiler check weather one input is valid or not (i.e means it check the validity of input).
Inputs are: Keywords, Identifiers, Operators, Controls etc.

2. SYNTAX ANALYSIS:
In syntax analysis phase compiler check whether syntax is correct (valid) or not. (i.e it perform grammatical checking).
Example: a = b (correct statement)
'a' is variable
'b' is variable
= is operator
ab = (Incorrect statement)
It is incorrect statement so it give syntax error.
Note: Grammar is a set of rules.

3. INTERMEDIATE CODE GENERATOR:
It is automatic processing. If we write such as
a = b + c + d + e
Our system have 3 instruction sets so if we write like above then automatically compiler take or assign temporary variables.
T1 = b + c
T2 = d + e
and perform operation.

4. CODE OPTIMIZATION:
Optimization means to minimize whether memory or time or statement.

For Example is using inline function which increase processing and minimize time because it convert calls into their definition which will enhance the processing speed.
Other Example is using return statement in any function such as:

main()
{
-------
-------
-------
return();
-------
-------

It show how tends to get your output.

5. CODE GENERATION:
Here in this phase object code is generated into machine level language.

SYMBOL TABLE MANAGEMENT:
Symbol table contains the information like the type of variable and other information.

ERROR HANDLING:
Since all the phases generates the error so this phase handle the errors.
Example:
( a + b
The above statement gives error,right parenthesis is missing, either we remove the left parenthesis or we add the right parenthesis.
So all these type of error are handle by this phase.

There are following tools are applied in the above phases:
1. FINITE AUTOMATA (FA)
2. GRAMMAR
3. PUSH DOWN AUTOMATA
4. TURING MACHINE

No comments:

Post a Comment