ATCD Assignment 3
ATCD Assignment 3
Date
Req no: BU2lcSENOS00301 Page
Assignment -
What is the structure of Compiler?
Discuss the decomposition of a
compiler into phase s and explain each
phase s
Ans Tne Structure of a Compier
Single box thak maps a
Source program Rntb a Semantically
eauivalent target program
here are ho parts to ths
analysis and Synthesis. Maeping
Ihe anaysts part break up the Sourca
program întO ConsHtuent piece and
Ymposes a arammaica Structure on
them
t then wse HhrS Structure to create
an Ratermeciae representaion of the
SOurce progam.
If the anasis part detectS that the
Sorce progcam is eiher Syntacically
semanttcally unsound
then it must orovice iotomaive messoge,
So the wer can take corrective action.
Ihe analysis part alao Collets înformation,
about the Source program and Stores
Rt fao data Shucture Caled a Symbo)
table, cohich is passech along oitth
the îotermediate reprenentathon to
the sunthests part
Ihe syothonis art Consttucts the
desired torget orogcam fom the
Rakermeoiate representotion and
tho ioformaioo fa the mbol
table
lhe anausis part ?o often caled
the froot end of the Compurer the
Sinthesis part Îs ttho back end
fr BacK -end
front end
tAoalysis. Sunthenty
Source Interme diote Mochin
Code Y
Representat'on
Cooracter sream.
Lexica Analyzer
token stream
Syntax Analyzer
Syntar tree
Serantic Analyzer
Syntax tree
ftror
Talble Internediae code Generator Handiin
întermediate reprerenteion
Machine - Independent Code
optimizer
întetmeciate representation
Code Generator
target mahine code
Machine - Dependent
Code Optimizer
target< macnine code
Lexical Analyzer
H lexicol anodyzer,or lexeris a
fundarOental component of a compile
or interpreter H proceSses the soure
code nf aa praqram and breaks It
inko disCre te units called tkans, îhese
tokens represent meaniagful language
eloments Such as Keyords,Rclentifers,
Titeralsoperaton, and Synbols, The laxers
Qutpuut serves as Pnpuk for subse quan
Stagenof ComRLaHonor tatetpreta kion
Syntax analyzer
A Siyatax analyzeoften caleda parser
isa Key conpanent ofacompilur or
Îoterpre ter. lt analyzes the seaune oE
Lokensgenerated by he lexical ancyzer
to entorca the Longuage's qrammacal
rules ensurinq correc SyntaX he parser
Contrucks a hierarchicad eSructure, Ke
an absttact Sntax tree (AST) ko represot
the program's Sntackic Struerure
faciutatíog fucHher analysts and Code
qeneraionAny Syntax erors are
reporhd diaring phane
Semantic analyzer.
A Semantte analyzer is a critica
componant in the compilaton process.
it gos beyond Siyntax analysis, exantoing
the ne aniaq and Correcness of the
prograns constructst enforces laguage
Specific SemanHc rules,type checking
and ensures proper wSage of Vatiables
and functions lhe Semantic analyzer
helpsdetect and reportLogtcal
Code generaor
Acode genrator is a cucial companant
in a compiler that ranslates hi¡h
\ewel Sourca Coce or an întermoci ote
represenkakion IR) toto machine Cado
or assembly Lanauage RpecFic to o
target Chnputer architecture t maps
tho programs logica construts to loww
lewel nzttucions registers andd memory
addreSs es,
App(fcaions
Ine
of
Compler Techooogy
programmer expresses an algorithm
wsiog Ehe Lnguageand the compiler
musk anslate thcr program to thak
targe anguage
Progcammers wsing Loo awel Programmi
Language hawe mo
More ContsolOuer
Compkaion and cOO prod Con podce moe
ebbicient code
opimizing comilers în clce techotques
to improve the perfornaneof
Qeneral code, thws of fsettfog
the Rnebicieny îatTodcec b
High leve abstracion>
Bootsrapping
Bootetapping s the techni for
prodcing a self- compiing compi ler
Ehal is Com:lr or assembler orttten
Lin the Soure programmig lagage
that ?t Rotens o compile
An iot ttal Core versio ot the Computer
is aeecated io a differeot languaae
(conicn coulcl be a6emblylenguage
SucceNiVe e xpandec versions of thhe
LCompiler are deweloped wsing this
miotmal subeSet obthe Language
Mang compilecs for many prograMming
Lonauages are hootstpped incducina
Compiers or BASICALGOL C D Pancal
PL/L Fackordava Ruet, Puthon a
more,
Page
*CroSS-Compîlr
Comole is a Compler Copable
dcreatiag exeutable cocle for a
plakfom other thanone on wbich
the compiler is Cunning
H crosS- Comiler is a compiler that
tuns on on machineanc prodcces
sbieck cod oc anothQr mochine
The Cross - Comopi er is uned to Rmplument
the compilec, ohtch is choteled by
three languagesi
he Source lanquage
) The object onguage
) he language in cohich f is ortttes
Lexica Tokns
Parser
begramAnayzer Get noxt token
Symbol
Tabel
Inpuk Bufferiog
To reccogoize tokens reading data
Source program from bard diak is
done Accesaiog hard disk eoch time.
Conbuming so `pecial baffer techoiques
bave been douelopec to reduce the
amouot of ower heac requiecd
One Sch techoiue îs tuoo bufFer schee
each of cohteh îs alternarey badad
Size of each buffer fs N CSize of disk
blok) Ex: 4096 bytes
One read CoMmaod is wsed to read N
Characers
Senttaed Rs a Gpecia characker thoat
Cangot be a part of sOurce program.
f feoer than N charckers rermain io the
aput Gle then Gpec¦al charater
by eoE, marks the end of
epresenked
Source la
Page
toruard
Laxeme beain.
*Lexeal Errors
ComiLe tme errors are ot three bupe
Errors
Data
execuwted.
îoouercome thás problens of canted
translaion Hme aod mnemorg Syerem
prograMmers loweloped another component
callec Loader, The task of adjusting
progcams hay may be placed in arbitarg
Core bcrions fs caed reocation
Relocoion oaders perFo ns fOur
Translators
Atranslator is aaprogram that akes as
iopta program writen io onelabguage
ond prodce as o t p t a program în
in
anotherLnauageBeside program
braneaioL, the traslakor per foms
Cnother very împor taa rolethe error
deeHon ny violation of d HLL
Bpecication wold be detecked anol
reported to the programmersa \mportant
o of tanslor are
) Translatina the LL program inpur tot
an equivalent ml program. cherewer
Providiog cliagooshc messages
progrommer víolets Specificaioro
the
of th HLL
classmate
Date
Page
Interpeker Compiler
Transloken program Scans the entire
proga
One statemnent at a an and tranates it an
tine a wbole fotO machin
Code.
terms of stîng
is the empty string-
s is the length of string 6
Langua9e
Sers of &triogs over sone Rxed olphabet
_the empy Ser fs a languge
ethe get containing empty Shrin
language
n
\angge
Set of al possible Rdeottters ts
Language
Operaóro on trfngs
Concatenation: y repreents the concatenation
SeSeS= S
srings and
gn= s9S..s(n imes) $°=e
PERATON DEEINATION
union of Land M
written LuM M
Kleen lsre
denoteszero or more Concakenation
of"L
positive cloure
Orten L denotes One orore concaterahin
classmate
Date
Page
Use of lex
lexyy Compiler
Input Sequene
Strea oF toKens
|lexyy: Sequenes
Lex Rle
Compiler Gu Compiler
Lex.l okens
Lex Souru
Program \nput Stream