0% found this document useful (0 votes)
123 views14 pages

Compiler Design Basics

Lexical analysis is the first phase of compilation that divides the source code into the smallest units called lexemes. It identifies lexemes by patterns and groups them into tokens with semantic meaning. The lexical analyzer uses an input buffer and tracks the lexeme begin position to efficiently parse tokens without multiple readings of the input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views14 pages

Compiler Design Basics

Lexical analysis is the first phase of compilation that divides the source code into the smallest units called lexemes. It identifies lexemes by patterns and groups them into tokens with semantic meaning. The lexical analyzer uses an input buffer and tracks the lexeme begin position to efficiently parse tokens without multiple readings of the input.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Pay Ho

Date
unit-I Intyaduchion
LanguOge_PaACe SsoYI

Compilex t isa suslem so4hware Lsich


takel nput ad High-1owel Lamgno ge amd Pcou
lpLuta_ Ascelmlly Macline leAal lama
P Asembler LE is a cutem Cware wuch ae
iap
T oj _atcemby lammoAR 0Ard Podul mtpu
a maclaine lewalaanase

3inkeY iakx ir a 4lana Salhoare whc


ake 1apu a maclaine-liwl lbngAo A2 Cobjzc
module Wale 1ikho objeetomadulo wd
PLoluca 0utpua Binayenghana (Axaile)
Lsa de LoadoA oads iho pLoQLaia b .
exe Lle) maia memoM o oACuttna

LanaiA PACeRCing SYslem


SolrcoPAnQmoAMm(Hish-lave La

PaePaece Kca|
modih sd Hrgh- leval l g

Compiles
fsSem b loa
Assemles
machine bn
Linker Loacdss

Fi llwha laMguagR Paocessing uslen


Page No.

Dalc

P3-PAOeKtoA ia lolta0e whch tak ing o


hlV lomgwo PaAhounApeiminoiry0peD.1
OnAtuko removing whilespaco ond o mmanBCud
PAAAA wtput admodtkhd hiah-leed louy
he Shucture ol a Campiloplhau 0 umpl122

There are mainly tuo phales oCompile-

1 nalytis phoie

Analytit phaje Analytii phale [Link]-


0n Ihe olurce PAga and Collec tokormatious.

plhaa
Thera are 4- Sub-phateA in fAnalsis phe
i exial Analy3i
i ) Sunlas Aralay30h
mSemanhic Analy3e
CiV) Intamediate ode enerdte.

yntke titplha ie w fhe 0kolmatiau collecle


prkormy_sunthesin mit oMad
b malytir phate
PAndu u[puf atemhly lamga-
Sunfhuin
here axe 2- Suh phalËA o
phate-
Code oplmi2aneu
UD Code uenTahiou

d Lexical Analysic Take iaput ad High-lwo_


Smalleat unib calledL
langua edivica itmo
a l i a unii qzoup then into meaninay

"**** *"***
Paga Mo
Dale

Sequmce Called [Link].), OLn [Link]


mhau PattenA toked_AXL 9mAroled.

Clud
D Syalao Ano3e Takes inputo okamh qemero
ed by laical Analy polt tofem Inh qzoAra
igmmma accpt Iokaw tsn igemaah
LAnkas reo ls ynka TToL. UIEtmolelit
heks whether topu valic o noE

CLLDSemantic Analu 3e):Semanns anoyau aivA


me aniag to he lemoml: Maia ole al fue
luic Semanhe anals32 u e pe hacking aud e2
Cashina LE paducs oupAA pansaeo

hay [Link] code cenaohel 1Eake inut


a_pa2se reo9enLaEed ySemanhc ama30
nd PAduc-aistpaj Lakrm2liala ado (TC
here are many tosmi [Link]
Coda un ta rdo Poctkisnakaniau phc.
Itue Ihreo addriCode c TC
md Paspor hizd o Three addzei Cod
1 vers threQ_OddzeSI uuchouCaa haNe
at-mos trno6perandu (LeuHhaa threa opgravdd
a l acCeptalble)-
2 Raht side o Hhe dsigomenE slalemem (o
Lalain atmost one opATatol. Noopuroahog_i alko
acLaplehle)
3 Some tiaas Compilez ma enaaie
empara
yaiable lo hold paahial Dl
Page No.

Date

de_aphni3cah a Tek input a inlermediale


aan&mled b alesmediale cede ggneats
peToA sphmi3ahiom h it and produca outat
o ophm ied inleamadiate ce.
)_Cade genezake) Take ioput as ophimises inkhmed-
iala Code and (ouvarh o assembi La a

Let u ska example ol

Posihisn= Înihal+Aale G0
Lahere
Posihiminihialaalk aeal
fosibim inihio alë tGoo
Symbolab le
Leaical nale2e

4-Potikimaal Kid.1=id.2>t><id.3>< KCo>


eltaihiale Synlax Analy3ea
3are al
dd.i
ld, 1
id.3 <io>

Semanht Anaiu 3eA


Com

Sid2xpod LidAal
idsi

idral nt eveal (G)


.

PagoNo.
Dato

ted,Vnal Hemp, AAo

Lnkamediale Code genRato

ti: tattoAeal (co


ta: id3 * E1
t3 Id2 + t2.

(ode ophimiaahy

t : fdgt 60.0
ldi= id2 + L

Code Gaenarata

MOVERAREh, idalaate)
MULT AREL 60.0-
A DD AREidaliniha)_
MovEMAREG id1Lposihin)

Compile) (muhuchau Tools


CompileY mschiou toola axgHhe so
uned b Compile dawelapzA Lor Generahaj
derent phas Compllo
Page to

Da'e

Lautuhisn wdian.
20n2 (ammonly [Link]

SCanN2r_GAnLra aoue leeical Arvo20h


Ae gaulal iepraim patern

FariPAgenxatd: unmatico PAcu Suno


qsammahicaldeccriphm oa
noly32 n_a
mmlA

D2dua
3Suntax direckad tianslaho Bngia
tallechaM o Aouhal al nerahing paYiL
2
and Tnkimadiak Code._

Gensm hel
A:Lodegenerahd qeneraiodPzoduce_Coda
ulk B 6o
hyfaking 1opula allechlm
iqivalou
-lahag ADch ialkrm2dialo laugaasR mó
ASSambl laaga2-

Dala oud Gnalys15 nein' s1athss 1akaimatim


about hmd valus are tamimitled am_h e
Daat ofpAoranm 1nh d ha parT olha hngha
Dala laso analssis is a ke part e Cede
aptami3ahom.

amiles Cauthauchimm Taalkih paavides intga=


Hed t o4 AnuhaLi b lenashuchiag yarioud
phafD LamDi lei

-END-
uait Lexta Analyi/2

Lole o Laxical Analse


l rical analua n h ake Hhe
Batie 3ole sividiu i nh
high-lve lawgAa
inpt a
asica unit qiouup
Cmallat nik Callad o Calla leoam
em ial maaniaa al 122iase
hePattexn han bkw
Genarated. 1 identiL the lekame aA
or2 ialssumbalLle
iolenhkiy Then i t ankr fhe id

Soure Lexical PaTses Semantnc


Pa AraLynh faztnttfot t AnalySis

Sumba
fotle

fiq: Lllushaks ilerachiam bebwan laxico Araly3o


and Parti

TheCal 4etNextloken iathe okav2 sura. 12quu


Lenical analy3es D Send nas nkan o the Part
unhlaxica) oarol30
he procei i l Caniaue
Sanda l lthe b k a n
Amt mSeding okeni h he
pale lexital analy37 alto perjor hre2
impartant faSk
Vo
o

2.

161-PPE F FEEERET|| P ITD


ae Ne L Oato
Date
-
Inputbuffeuaa
Lnpu bufkatag is a autept MAel la leeicol
ami43e aemaiale okema helpiim nLAA
e specdof_S
eading the ioput.
Lexeme Begin
LIlws ralzl a paiy o iopubuffexA.
Fia
k iaA lance e_Cannot be SuYe iwe
hae Seon o3ward paiale
fiae ihd af asM idsnhiAu untile see a Once he net leseme is deler mined
cdlkaiacez
that ii nat IsHcs ol digit and thereAe i not paa- fs Sto tha ckhoracke of is l g ht end and
of he eveme ioA td. Th is will increos he hme LeemeBegin i Set to he characies mmediatel
agenale fokon. tc 1he lexoem e just found,
He se useua Luen tasle ad o one Sentiae DAa a so tex Sdeme ishanovs
aiord poiake Aeosls achalack itt_n4ods to
tae_memoTu Space hen tapuf i smal
arna
one sslem_reod Cammand e an Yead Lalaiclh [Link] lkasvae
' cLaackerinoa bu PexLathes taan ug i) lsheihe t ha aeacled eno o He
one (uiem call ÞL chasiacies1A he 4izst bufts bue eR nof sa llhai am Jlaad owol
i then we eload_SeComd bute amd vice pel.
Vezsa- Everyime hsa lest, kiduc e iciem So
Ends ie ioptisIndicaied ackasack OvRCome this pAsLlem w odol Senhosla b
Called a laf end ach bue Senioels ara spectal
clhasaclea 1ahasas udard poiaer Arada .
Tsa Daioles fa the ioput axe maiataiaee: au itat at has xeackad end lautpelSa-
Lexeme Baqa' Mak fhe b2gionlag o Hhe tuat it wil xelood axmaiaaa hiek e u
Luaent leeeme, okoie 2slent vL Áxe_atemphi Po au a Sennnelh a Cale ad Saa
h deesmine depiclesin ias belus isAL 1his ill
f o a n a l d _ Scans aheod unhla poiern
malcbe AYDid peargarming SeLond teut
a e4|+Cef
Seninel.
Sentlnel
LeoanaBagin
Page No. Page io.
Date
Date
Speciicaiou op Tokens Stringioves Some lixed alphobet
Regulas_expstns axe impostont y Operah on Lamgoa
DxeARnt TlaAenpa tim patternA so. ia
hii Seiom we are qoing sshady Sameolhe
nokahasofajilosd p-1esslom. _iunie
) lontalenah
Alplhabek, ShiAgR and lamguageA- ii closuxe
a kleene closuye
Alplaas a liaile So of Sumbak Typital Posiive Closure
Linanaple mols oxe letfsdiqih_and iy_Unian Luniem sa samiliar_ k lamiliol opAaatia
[Link]- he Sot0,11 a blaary olpralat. an_Set-and is nothing but taag al fhe tonaponenh
e wo sets.
Singk is a alle CeqsamLe oSmholi ahich
ShingA onadmal D CaCalenahiu CcnaCaeMah'ou of taso lamgnogL
[Link] wnng a giak Smlaly BY ase notaing but, au'ngstrng
The lengia o the skiag is nottuingu om ma laagg
numbRA O OCCuesn Les ia Haat: Shia Comcolenahlng hem
fo Az [Link] C closure
Hhe length o shich is epzeaeiked Ca kleene clos ure_ Kleene
is 5 closuxe o4 a
LaanguagR nathing e t CenCalemahing
Loncalenahm olha shotng i notdng but
appencag- SeCandt a g ho Hha emd o fse (b Posiive closuz: Posihva closure a
Danauqe L isnothiug but Conatemohn o L
1 oA moe Hines. Lt is apeNemted as
foR = TKiEr_6 : korana
Table ta fhe next Page repYeAenhcleinitis
dp2 TkLETwaraua _aperohas m lang A
lamgiuage A Laaagage any ounlable SoFof
age No. Pago No.|
Date Date
Opeiathas. 2ejiaihata aud Nokahot Realai L»p-121ion
UM= {s; S is in LSs la M e hae Seam someof_t nokatos ia he
HContaienahiaaol L&M LM ={ SE si in Land tie PXevio Sechom unng fuse_ nofaia_e Caa
klesne cotuYe o4 M TrpeAeAml eyulau LpTeSClon pattern-
Posiive closure o4 Regda eopretcn patam Losidaah
= u L
lable Deitima a openaiay ma lassa LeHe LeHe | dgit)
Let Lbetne teto Lette l={A-2a-zt amd loahove patlean- Letia édtatt aAe alplkaJara.
Dbthe Sste digi D=io.1- iuxtaposihlau C Ae pr2Denk Cenacalenahau L lacdi
CaeAAMlen4-Asad_K TAp TAms kleene closu2
1 LUD is the Sat a letiea amd ait-[E
DroducOs the lasngage laitia 62=shingssleraga- Letusep Scame of he regalau epprMicu wluela
Esinga PAAduces diffeeat_lemgnagsd.
LDi the sat o 2o shrigs langata uo- Lat E=faib
Lach Casishiaof 11he tegalas LxprLisiatn bdenok the
anage aba.
3 4is sito4 all4-latta srig
2. lal) Calb) dmotes jhe Lonaagl aa,ab,ba,bbi
is the t op al Shings af letiers iaclasslsg Es
3 a danoles the lanaguega Cmtistag ofall
Sin 20__mae a Haa ia
LCLU DD is the Cat af all shin4 0 etLer_amd E a aa aaa --
digik beaianiag lsiia. a leteR. Calk)* denets tae lauganage E abaaab,aa
bbaas --{
aath da moles the lanngmags a.b,abaaD.
aaabt_
Pege
Pay
at
Kecogninm afTakenr ThansLhon diaam
Jnthd SEcim eshndy someoL he eken Regdasespxekicn patezn_one Cavared iahn
and iDatican
SLl2ed looclon Lold" taouihu diog.o
digi [o-9 Tansihan dag10ms hanea Coll2cins
Io-11t
Mumbii
op node od czcles talled aks._
Cdaes ae disoled ym mai(ab o
LA-2a-2- ansih'm diagaama lo o thea sale_4 oifh a giv
a p cymbol
A he hansihm diaglon in u
Laasales are calerminishc meaniaa Haa
Then fhen
Aop
2=|2=|=l4
1n addiim laeical asaaael Shipcuabiespece hreg importaW Cavenhons abau ansihaM dia A
And Cormmenk TLLoami3ing aokan
Carlala slale are soid ho be accaphine inl.
The hks inddcale a a laLm_ha een Lownd
(blankalnooline)+_ le ao0 ud incCale am accop h'ng Sale ay a
-double cAcle, aind i here is o achign o be aken
Tokanwsis_diLurenEom ofhu otens tn that p ically Akaning a eken e. fh par cek We shall
uhan hie_l2cognia2 1twe do not Lekurn it - atlach Hha achon o he acCophg sae.
fhe Parse, b atel Lslalf he proCen c
leaicai amalysiiHea Hhe chasasdes 1elleund b ki I foward_potakaWonk hh Ahaetoe p0siha
the ohilaspace. back tha cam be indicaled
he acceph' SFale . lagpung a sing le
) Ong sl is designaled as Slart sate d_
ita fe t i tadicaled a am
Loze aloled * Sfart" Rmlengham ntonans
oshare
Pa3 No.
Page NcL Dale
Taantiim dio gAama Taansihou diogaam a2 idanhkes
a/md koy0rdA
elop (Reterved loerdd)-
elop =>l?=]=l< Same Tele 2op1e sin g aomaiho iag2o
S lan (&alop,1E) Kun0r dA.
Ld LefteA (Leffeal diiE)*
urn(ilop, NE)
o1 @Aaurn(gaToleam),Ca
)* Talurm (zelep, 1T)
* eln Crelep, EG) idmhte
21rVed hanrda (bemorda) a o
O Aaturn (relop. GE) 1 1n the bLqinning 2ne allHae koyhooAds
fhield of mLal aLle idanh faose 0 -
()relun ([Link])_
koTdd. ohe wo uad am iduailkho Call ho
uslal LACplaco iFin fe qmool le. 1P we
TiantiGa diog2om22nuwnb. GoETokerd shile
oud kaonnd we cal a schin
(ECt1P diath)P_ he lome koonrd-LsiHh al9 fhe
(ompares
numbes2 [Link])P he 4mdho l e i 2 m a l e h Jound i
Queioso
isit
k ard f he iaput looomo malehos he_2h
Lolica placad a i all he leauiaord HeM it c
ale okom as idenhikier
. Selond mefnod oconexoalo s2padale-
ontihsy [Link] o a he loa0rdA
fox a g laansinon duag2

You might also like