TOC - Theory of Computation explain all mechanism about compiler. We can say that is a study of compiler. We will learn working of compiler their block diagram tells how compiler convert High Level Language to M/C level language what are the mechanism used for this process. We will learn about Lexical Analysis, Syntax Analysis, Intermediate Code Generation, Code Optimisation, Code Generation, Error Handling, Symbol table Management.These are the import part of compiler.
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 OPTIMISATION
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:1. LEXICAL ANALYSIS
2. SYNTAX ANALYSIS
3. INTERMEDIATE CODE GENERATOR
4. CODE OPTIMISATION
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.
Optimisation means to minimise whether memory or time or statement.
For Example is using inline function which increase processing and minimise 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