Compiler Design Lab
Compiler Design Lab
implemet
tabs and mee ine.
tho
thowe f Confiletion reust.
Jeye) eaks the code hato tokes Wich ae
He snaleest imdisual mits
omai n gecus is to rak daon the code
Cter
iuto mclle tohons.
Sounce Code>
mtert e
(AsSIGN',a!), ('oprRATOR , '[4\-*),
(KEYWoRD', n'\b(flelse (eskilelfen)\6),
(SkIR, [tlnt ), C'MISMATc H '),]
onatch
= token.
ffndayeale)
ceole!
('NUMBER , )
('NMGER', '4)
(NUnBIR, '
('NUD8tRY)
(hmgER, ' )
('NUnBER
Psaqsuam: 2.
ler toal
Toale> Lex oa
data, it may be an
eorateh at
eecompeed
Jeyunxe of characters hat can nat te Ddimitenb
fusher >kewonda, ddentfend, ofenaton4
kygonds 1> /nt, cha, loat, const
uyvicable, and usen
Commad,
Dlimtersl> Punctuato: Smbels wsed such cus
demicaland, biocel!.
ELSE
2fAREN)
'RPAREN,
t Raren
c':'ELSE
tvalue.value)
Jetwnt
n'[a-2A-Z-][4-zAz0gy'
lexulintet le w value)
chaneeter'talu loJ})
d a t a
elsei
#Tokenize
tet lerentekeny
buak
Ley
4323)
4,al
(ELSE,'else,
5,545)
n ( N m b e n ,
LexToke
benerale
vald awithm.etic
yeatos
and |.
tood
tool wed
YACC A
a
Tesgt
cheekU whether
C
ond
Ssunce Code:
lex
jfot pley od
PLUs',INUs','TiMEs', ovgE')
ttos (NUMBE R,
-imes= ' |
tedivde
fitald chovoten:.t-valel3)
de t-Nunent):
ttt. vale)
te vabe =
TiEs
"ht("Ete an aitntie
cyuo. ;
beak
not S;
cytrssion 3tS*2
aithmetie
Eidon an
Valid entreuiow
)Bupm
wlak aletern thocd by any mumberd littons on
t-Uale iutt.Uelu)
tnt
clefl4.eehld) :
ritvaliel choracterni "t. ala[oj)
4.tyvit1)
Iryenly Lex )
ti2]=/:
ely peelf)
briak
4 not S:
Conti e
riat ("losult:yeguH)
bnter exbusdoni
Trogham o1
Obilctua'ite a to
closwcnadod net-tate)
Mack.femcllmetstate )
tunn clowe
("0','): /'1'7,
(",): j'?2'}.
("30''a'):|',
(':i'4'?,
St ates -['e', ",22']
for tate jn states
clenws(thenstio, state)
clorou =efpi lo
gii' 'y2'}
Esilon cloue
Cbictive t’ Wsite hroam to couyod NEA 4h
E-translton to NEA othout transion.
heosg 3> To Convet an NEA bh stranstfion
to an NEA thout s f i o nd cIe
he ecloscoe of Cach ttte, uich | the set
tates seachahle oom a ttate w "
conideing all passible tronstis n
Cach i ymkol, taking to acteuut Hhe
we
acudt le Anal ttatea
reorch
to include any state that can be
a final state dhang tronidtond.
Sowce ode 8>
def filoncesowlofa, tate):
clyswe jtote}
tack [tate]
shle stack:
S-Stock.popo
next-stete
transhttows'J [SJ:
merttale mot in clonune!
clocoe addlnetstate)
aack.afenol me stslate )
Setun clogune
dy
Ambel!-'z':
aaonstat eJlsymbol].ufdateehsnle
epsorclaya
intalstatessjtate fn tete in mfa ['tated] if ang in naltinalstate
ofa,atat o)fon f n
>utunj stote': nfalstate'], alphabet':nfal'athabet ],tramtt
tewsrton,'start.tale': fa sttstete], nalttotes'=
final-tetes3
ofa wth.efilon
'tateso, 2i'2',
Whabt': 1'a, 'b'},
9':'b'={',2':f 'a':f'23}1, 'c7slon tro
'Stattete'= 12o
'final-tat':|213
#ransfion'.i22': 'bset), a' =f'2','20':1k'
22',o'),'a i''}, '2'-1'%'-j'2r'}, a'-set0i3
Stout tate:'e', inalstat '=121'3
Paaam-6.
yeetues>0ite fcg 'ram to Cowent NFA to DFH.
zoAtate
heony &> An NEA can hove ZOO, one
On a
qiven tocte on
move foom a
a
defrfato.ofalnfa:
starit-set- fruzeaset lbyasttI)
qeue-deyeltstatset )
stocte-mapfAtartset:ao3
da-tsa'11
Coant-|
whe queue?
eh Aym in ma.ahab:t
nertet setC)
Curent: .ijset
i mot
Cotinue
Adotumabineyd. sel]-f'AsCount}'
Countl
qucuafpnd(nertset) mapld-otJ
mplcwvent1JCSy m-s fate.
anltate
fa-ocpts.add
CHotmainextset])
dlaachtbdtnd
tatt-wap alelo, 'ç&o,
netwn
onfa-NFAC
states L'A '8,],
0tat 'A
accaptslc']
'A:o:A 8], '':LA?
s':':''y3
tate,duitont: nftoay
stod es. tat.tant acejds.
rint ("f A datest)tCstcles ))
int"tart Stete : '),Atat-ttate)
Jistlorcet-stotes)
fint Accabtst ates: ).
a3'1
DFAStotestt'o, '6,'2,
Stant tate. o
Accept states: L'As'a)
6 1 - - O - a
A l - - 1 -> 0 8 2
382
to to0 de
dtotes
Ohe set l cotaln all
difeet
chauge in fottion)
d dfatdietocd)
ktukle orertCi n t-dine nmerafdns
d[k].addrq)
s t - dvaluesty
dfa- DF AC
E-['o''),
tat'A,
f-l'c'],
'A''o': '8,'1: 'A'3,
'3'.{'o': 'c',':'o},
'c':{'o:C, ",'},
Stat 3
Acced:['ao']
Inabs: Q6-- 6->a0
8 - - | -6 0
lne is
Com met o mot.
a comet begins sih tho t sjnbol.
heory>an ythoncheck i a gheu line o con met by
mbol at he
funce fthis
line, wtile faces.
retun keyond.skeyuatd(opnd)
LiDnd =tupt(nter a oord: ")
pziatlf"iandy a
else:
Entor a cond: br
fyon keyord
Objeotiei> lWrite a ogm to finc wheth en the