Naveen Kumar.T.P Compiler Designing
Naveen Kumar.T.P Compiler Designing
Naveen Kumar.T.P Compiler Designing
COMPILER DESIGNING
1
A seminar report on
COMPILER DESIGNING
Submitted in partial fulfillment of requirement of III semester in
MASTER OF COMPUTER APPLICATIONS
Of
Visvesvaraya Technological University
By
NAVEEN KUMAR.T.P
1SJ04MCA16
Under the guidance of
Mr.B.R.PRAKASH, M.C.A, CCNA.
Lecturer, Dept., of M.C.A
S. J. C. Institute of Technology
Chickballapur 562 101.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
2
Sri Jagadguru Chandrashekaranatha Swamiji Institute of Technology
CERTIFICATE
This is to certify that the seminar entitled
COMPILER DESIGNING
Submitted in partial fulfillment of the requirement of the degree of
MASTER OF COMPUTER APPLICATIONS
Is a result of the bonafide work carried out by
NAVEEN KUMAR.T.P
1SJ04MCA16
During the academic year 2005
Internal Guide,
Mrs. V.PRAKASH, M.C.A.
C. A
Lecturer, Dept., of M.C.A
S. J. C. Institute of Technology
Chickballapur 562 101.
S.J.C.I.T.
CHAIRMAN
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
ACKNOWLEDGEMENT
I consider it as a great privilege to extend our heart felt
gratitude to our esteemed principal Dr H.S. Ningappa, of our institute for
his untiring zeal, which constantly inspired me towards the attainment of
ever lasting knowledge through out the course. I am greatly indebted to
him for his encouragement.
I would like to express my sincere and heartfelt gratitude to my
seminar coordinator Dr. Gangabhoraiah, for his valuable suggestions
and constant encouragement.
My sincere thanks to Prof N.Sridhara, H.O.D, Dept of M.C.A, for
his constant encouragement and providing the necessary facilities.
No amount of words would be enough to describe, for the
support, valuable suggestions and technical expertise given by my
guide Mr.B.R.Prakash without him the seminar wouldnt have seen the
light of the day.
I also would like to thank all the staff members of MCA and friends
who helped me to make this seminar a success
NAVEEN
KUMAR.T.P.
1SJ04MCA16
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
INDEX
SL .NO.
CONTENTS
1.
INTRODUCTION
2.
PHASES OF A COMPILER
PAGE
6
7
3.
COMPILATION PROCESS
8 - 11
4.
12 -
17
S.J.C.I.T.
5.
6.
CONCLUSION
19
7.
BIBLIOGRAPHY
20
Dept. of MCA
18
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
1. INTRODUCTION
Compilers were came into existence in 1950s. The first compiler
developed was the FORTRAN compiler. A compiler is system software. A
compiler reads a program written in one language the source language
and translates it into an equivalent program in another language the
target language. As an important part of this translation process, the
compiler reports to its user the presence of errors in the source
program.
The above explained concept is as shown in the below figure,
SOURCE
PROGRAM
COMPILER
TARGET
PROGRAM
ERROR
MESSAGES
FIG: COMPILER
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
2. PHASES OF A COMPILER
Conceptually, a compiler operates in phases, each of which
transforms the source program from one representation to another.
Phase I
Lexical analysis
Phase II
Parsing
Phase III
Semantic analysis
Phase IV
Code optimization
Code generation
Phase V
Phase VI
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
SOURCE PROGRAM
LEXICAL
ANALYZER
SYNTAX
ANALYZER
SEMANTIC
ANALYZER
SYMBOL-TABLE
MANAGER
ERROR
HANDLER
INTERMEDIATE
CODE
GENERATOR
CODE
OPTIMIZER
CODE
GENERATOR
TARGET PROGRAM
PHASES OF A COMPILER
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
3. COMPILATION PROCESS
The compilation process includes the following primary steps.
INPUTING SOURCE PROGRAM
Original high-level language program
PRODUSING OBJECT PROGRAM
Machine language translation of the source program
FINAL STEP
Object program is written to an object file
Using the different phases does all these things. The different
phases that are mentioned previously are discussed as follows.
SOURCE
PROGRAM
LEXICAL
ANALYZER
PARSER
TOKEN
SYMBOL
TABLE
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
10
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
11
PHASE II : PARSING
Semantic analysis
The compiler makes first pass over parse tree to determine
whether all branches of the tree are semantically valid
If they are valid, the compiler can generate machine language
instructions
If not, there is a semantic error; machine language instructions are
not generated
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
12
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
13
INTERMEDIATE
CODE
SOURCE
PROGRAM
FRONT
END
INTERMEDIATE
CODE
CODE
OPTIMIZER
CODE
GENERATOR
TARGET
PROGRAM
SYMBOL
TABLE
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
14
Lexical Analyzer
id1 := id2 + id3 * 60
Syntax Analyzer
:=
id1
id2
+
id3
60
:=
id1
S.J.C.I.T.
id2
+
id3
Dept. of MCA
*
Inttoreal
|
60
2005
Semantic Analyzer
NAVEEN KUMAR.T.P
COMPILER DESIGNING
15
Temp1 : = Inttoreal(60)
Temp2 := id3 * temp1
Temp3 : = id2 + temp2
Id1 : = temp3
CODE OPTIMIZER
CODE GENERATOR
S.J.C.I.T.
MOVF id3, R2
MULF #60.0, R2
MOVF id2, R1
Dept. of MCA
ADDF R2, R1
MOVF R1, id1
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
16
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
17
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
18
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
19
SOURCE
PROGRAM
P-CODE
COMPILER
COMPILE
OBJECT PROGRAM
(P - CODE)
P-CODE
INTERPRETE
R
EXECUTE
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
20
COMPILER COMPILERS
A compiler-compiler is a software tool that can be used to help
in the task of compiler construction. Such tools are also often
called compiler generators or translator writing systems.
The process of using typical compiler-compilers is illustrated
in the following figure.
SCANNER
LEXICAL
RULES
GRAMMER
COMPILE
R
-COMPILE
RS
SEMANTIC
ROUTINES
PARSER
CODE
GENERATOR
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
21
good
code
optimization
involves
data-flow
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
22
6. CONCLUSION
Finally we can conclude our discussion. In
this
session
we
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
23
7. BIBLIOGRAPHY
REFERENCE:
1. COMPILERS PRINCIPLES, TECHNIQUES, AND TOOLS
(ALFRED V.AHO, RAVI SETHI, JEFFREY D.ULLMAN)
2. SYSTEM SOFTWARE
(LELAND L.BECK)
3. PC-QUEST MAXINE
WEB SITES:
www.cse.spsu.edu
www.cs.tau.ac.in
www.modern-compiler-design.com
www.advanced-compiler-design.com
www.pearsoned.co.in
S.J.C.I.T.
Dept. of MCA
2005
NAVEEN KUMAR.T.P
COMPILER DESIGNING
24
S.J.C.I.T.
Dept. of MCA
2005