You are on page 1of 52
Onur =7r Semantic Anarysis Inkexmediate code: "tn dag of compiler te do convert the source Preqram inko machine Program — This ackivily can be done divectly, kt tt & not aleoous possille do generate Ath a mocline code ively in one pam, — Then, typically compilers generale inlemediade. lanquoge i the generotion of an intermedtiade lonquoge leads do a efficient code generotion, Forms of inleamediole code: —There ore, erally 3 dypes oF icdesmediode code Aepresentediona OY) Abshoct Symox yee SD Dolish notation anc MW Three adden code. CO Abstract Syntax tree: “the noadwol' Wevahiol: shishue o epreented toy syrtax drees . Direct Acyolic graph or DAG & ver! moe sirclen to syntox droe bad they one in move compact fotpees Foums. I=” Consider the ope shinq x:z -axb+-axb wf a (.) min, \ a ee \ | | o Sybex tree Darg cid Polish Notation: T Bordally y the Vneasdgation “4 ayptox trees eas polish-nototion, dn thin aeprerenbacion the: operetoy ton be cody omodiaded with the corresponding Speands. Thin ty dhe most poduat wary of 4epresrentotion — in exprenion evaluation ~ The polish rotation abo called. ox “prsfis notection’ in which the epector ccm Buk anch then opesands ove arvronged. EB (oab) (cd) con be uokHlen os #4ab-ed 5 polish notedion ate As | a b/(C GC) There bo r/eveue polish notedion hich & Weel wAtog postgix notodion GS xis Caxb)+ (ash) | Revere polish notedtion is : a %O-b Xo be t= ‘. s / a I £8 tonshrodk suotax dec and postfix. notodion fox «the Following exprenion, Co+tCoeey)T d— © [cPag) Syotox bree tree} i Nototion is abe # +d efqel- 3-Three addvess code: 2p tree acldven code feum ot the most three addvenes cue used do sepresent any stro The generol pm ar=bopc. Plthee abee cue operands thot con be names, tonstants , conmpile, generoded cempovonies and ‘op eprerents the operotor & as beetd . The three adden code tic bee Mee Av ond 4 temporary tic haa Names generoded by compiler. gt There cre admost three addveno| ae allowed. Chico Poe operands ancl ane fox seyatt). Hence name of thin se present “Hon & Hye adder code \mplementation 4 three oddven code: = three oddwey code & an obchrach Fourn of Inleemedtiote code thot con be j Aecord lemented or a with the Hwee fields. ~ There are thee expen aepresentadions sed fx thowe adden code such ou Quadnaples , biples ond indivect Aiples Quadrople Representation: ~The Quadrople ts a she with at the most four Felds os op, rgd, axga, result. — The ‘op’ (es w» used do seprerent the inlenal code fox operoton , the ogi ard ong cepresent Ae hoo operands wed and remit field is used to Stove the resol aL on ex premion St! Consider the ilp. stodernent iz -axb+ orb. The three adduen code is 1 Q result tie ules a Steevie (0) uninws Oo ty tye b eee Oe 4 b ttyl = uminus a : OP) undirew ty tut ty xb (ig t, b ty tere ha ty M 4 4 & & aie te aN es ee ae Triples: -In the dSple sepreentation the we | emperor Neebable —% owolded by refering the pointers in the. symbol doable Number to) ay top % (uy ts) 80 the to) aw @) (D> cy) ts) ‘a earninus, Se ais -a b+ -a%b. Number op ont ona. uninws — * (o) ob andes * @) b + a) @ ic x (coy Indiveet triples: ndevect tile ogi orga a ay b a 3) b Gr) (uy) nx rs) entation the listing o| hiple been done. Anal lishing poicders are sodl instead of using Stoterment Statements to) a) w tr) ey Cr) &) uu) (u) us) ts) ae) Je: Lbtde the Quodraples, tiple and Indirect Hiples fox the exPrersion — (axbyr Ce+d)— (atb+c4d) Soll The free added code can be tirakb fie undnus + fait C4d tuis hat tei = ath tye teat, tyis {-t, Lovotion op ong aga aesull a) x a b 4 Y rade 4 t ® - e a 4 iF 4 i) ty = + a b ts Ce) = te t, t (as sian , x + o a Tepes a) a) ®) (ay és) we) w a) (>) @) tu) ws) Cb) w Locotion oh x rns 4 Indiveet Tiples: Location “ Cu) (12) Css cu (13) aay Ct) b d (a) b (3) te) Stodernent a ny) Q) a) ® aa) (y) (ey ts) as) ©) (te) (ay Crt) Need of Semantic Analysis ~ Seoarke analysis & done In odex to oblaun the precise meaning af programing corubvch. —The need for romantte Anal Symbol doable pod in declaration, ~ Secondly the dada hype ideokBer b obtotned one Ape seeking of the whole expremion and shel » done in order bo follow the type sustes a the lorguoge. ~ Thudly to ideo, Stope 4 ident Fev, Type enalyss and ‘Type cheeking: — The ‘pe onalais and dpe checking > an \eoporant ackvily alone in dhe Aemantte onaligis phase. “the reed of dupe checking b To delet the Sernrou' ardsing im the expronion did bo Incompod ble peand. G8) To geneote “imlemediate code! fe expremion ound colernents « Typically language Supports uso ‘pes 2 cloto byes — boute and consheded. - The bosic dota. hy pes ove —inleqer character, eal, boolean, enumeaded Centr) dodahype- is’ Ast, ib to bulld al keeps broek + Narnes extallished| WY = The conshweted dota. bypes one, — Arvouss , se cords (shuehue), set and poicte. The conahnse led cloderhypes bull esing baste dodo pes [Lye SEPrEstions — The setemabic woy 4 expreming type of language conshvct is called type _expremion. tthe bose Aype & called ‘pe expworsion. Hence int choo, foot , double ; enum ae type exprentons. a IWhile Performing ype checking two specta cotohype ove needed such as ‘type -exvor and void. the ‘hype- never bb Ay 2epocting endr oceeined) duing type checlein ard “woicl’ indicates thot there b no ‘Mpe Cntuie) omotiated voith the stademment 3. The ype nome t abo a hype expromion. fo Gomple Apedey fot inT_eTR ~The shot defines INT-PTR as ype exprension whid b ackwally oO inrlegox pointer 4 the type condnclos ae alo type exprenions. The ‘ype conshctors axe costa , puodirct , shuet, pater, function. Representations of type expressions: a teroy: An Herouy ovary (9,7) da hype expremion whee ‘2’ i an index get which ir casually an integer ard cloda hype a} the oven elements & given hy Gs chor avr[r0] Porro (Oj, , chav) Z \ J & clatabype(T) Index (2) inde datahype Gi) Product: The ype expremion fo the cartesian product ts given by Thx Ta whee Ty ard Ty ave wo datahypes. GO Shek: Shuck ts gives. by kexy werd) ‘shuet’ abso a ype exprenion I shuck ha i char Name [ro]; Fook — marks; 3 shut ght shodent [ro]; — Here the Ape name ts sha having the type expression On, shuct ( Crame x apvrcry (Oj) 9, choo) XCmoaks Plot) ~ the hype exprenion for student iy given an, auay (o)1.---9, shed Joo Pointers: The. ‘pe exprenian fx pointer & given on pointer (tT) whee ‘T’ & clotohype. Ee Plowd- KAYE Then type exprenion & ‘alentiften ayy giver os porter C Hoot) Type Comiersion: There ae foo Aypes of conversions rm lenphtett conversions oa Gxplret conversions lk the conveuion vv done autornadicalty by the then Sb wv» called * welictt convenions’ tor) "coeyctons” Ex integer convented ho Float. > The conversion wv sald to be “enplicit® PP the Progrorome ApeciFically wovles someting for convert one type 40 another. Ex: int a,b; be Plocd (ods HThe Rdentfer ‘ol ts type-couled and thts ty how explicit comeuion fom int +o Ptocd tokes place 4 Type cheeking wle for coercion from int to float: E —oum E- hype te integer E 3 num. num E hype i= Ploot ed ee eae aa © — & op & — Erhype ie if Ev hype isint anol Gehype Hen tot ele Vf Es kype ye int and Ey types load then Flood: che 9 Eve hyper [ood and. &. hype is tot Ahern flood. che 9 E\-hypeie ood ord E> hype: Jloot then float else tupe- exyor. Stonple type checker: — Type checker th a dransledion scheme in oshich the hype of each ex premion From the. bypes 4 Sabexpreni % Obtained. ~ In thin the hype of idertifier must he cleclared hefove the ure a that tdentifien —The type checker can decide the Ajpes for array, Pointers , sladernents and Aanebions. = tet us. consider. &, gramnran fox Source Languoge S—> OJ E > — oy old nist T > chor lint | Ploot BST > Eitoured |Z, [Md © > Clorl Ire ed |e mode [eCe}/*e] eope/ E(e). “The ‘ype checkex emures Following Heng, G) Each dente mut be cleclased befre the use. WO the we % ident fiex must be within scope- Oi fey Sdentifier nmuut not have multiple definitions at a Hme within the same scope. ~The given Grarrmon har bate dota. hypes os char, int, Poot and fe zeporting the errors Ay pe—evvor: Translation Seheme for above grammar | Production wle | Type _exprewion. S— DFE thts means all declouadions bepre expremion. DT a — List. éypers T-hype % food dype Cid-enhy, doa * *P ae T + chax — £7. type t= cha} Production mde Type, exprrenion at T tnt ft. type = int? To? Rost [eit Apes Pak Let BL, — {Ly Aypers pointer Cust. type} | cist — Ly Loum] ~ {ly Aypes = orviay Cony. nui, vol-y , LisTtype Syphax divected definition: —A syntax directed delinition (spn) b a CFG together with othibules and ules — Mbibutes ae omodated with Gromrnen symbol ard miler ve amnodoted with productions. eee Ee eet sqbol and ‘a! & one 4 tH all§buey then we evrtle xa do denole the value of 'y’ a O Porticutarr Porre—Aree node tabeled ‘x’, Inhevited ond Syothesiged Albibule: Syothesized: Attbule: A synthesiyed attkbute foo pon—deumtnal ‘| ot a porretree node N’ is defined by a Aemant ywle amodaded with the production at ‘A’. Alole geal cies produchon must hove ‘A’ os 4s head. Inhesited athtbute: An Snheded attBbude fer a non-daninal ‘8 ot a porue, hee node ‘N’ defined by a semante we omocicded with the production ot the parent 4 ‘N Nele dhot the pooduction rut have ‘B’ os © Aurel in ib body. b Synthesized athibute: conidex crG -§ > EN © — ext /e-t/t Trae frie ]e Fo —> dit Production Semante mules. S—> EN | Sol += Cava E> aT Eeval = Evol + Teval c at ‘ a Hao : Ace He . if Valeo vat * alee TWF Tval = Fevoh F —>(e) teva = E.val F— dit Eval = digit. lewel lt evaluotes exprenion terminated! by an end maker ‘a’. Jy the S00, each a the non -dern’nal hey a Angle synthesiged att bude, Colledl val’ dhe oho suppose that the terminal digit hor a syothesiged ath bude ylexval’ ehich & the tnt retucnedt by the lexical analyser ~ Sybase directed defnition uses s- all’ bdedl definition -fn 0 posure free , of each node the semantic vale oe computing the s_ athi bute clefinition in bottom wp Fashion, Steps to compote $- athibute definition: bide — spp using the approprote demante achons fy productions B the anpatoled pore free o genesoded ond altSibude value, ove compuded. in boHom- up manner: 3 The value obtodned at root node br the Bok ep Concho porue tree syotox tree and annotated for the ‘lp tng b SX b41. 4 ya a Z 7 Z™ wi s 6 ee 2 (a) Syntox tree pe ie Ls i | digi 1) F digit (6) digits) | Ce) forse bree i-dopotaled pare free: | s Evola 34 ‘ Zin | Ewvol=30 4 Tivobe ' | Tvalle30 fval e# \ | alge I Fval= 4 digits lexval = ! | Exabes digit. lexval = 6 \ digit lexvabe 5 Inherited attribute: -The value 24 inhertded athibue ata node ?n a poue hee wv alefined! on sthe athibude values ot the posent oO Ziblings & consider the grommet: ot ae Vs T — Got | looet | che | doewble. L > Ly, td ltd. 50D fe above grammar ts | S—9TL | Sito T.type L | Tepes ge TS foot Te dype 12 [took T int Ty chan | Tetype re chan L te thet Le io | ender hy peltdsenry, | Lin) | L— 4d erlec type (i deenhy, a a wi Hees \ \ wlve Moin, | ; Roi lo \ oO J, Pree et Condidlen aonced AE SFT tT 5 eT T 5 # F — digit Production Semonte Rusher, Tor qNinh= . vol Te vol = 7h ayn \ Ts pe! Tein = Tinh & F.vol Thayne Tayo an ‘ thaqn = Th ioh e digit F. val = digit. lexvol | debe ose oe lpi 3 es Tivol = 15 F.voleg Tiinh-3 eis a lexvel = 3 7 | % Pyoles Thinks is , \ F cay ros! cab syn ey ES ' , ‘ \ eer a ' / 1 \ * digit rom ss" a) 5p lexvak ih LA i (2) ne | Th syne tS digit lexvale s I E: pendency qope fox the annotated poxie bree : ayy: pa r * Ppplications oy Syotax Direcled translation. — Sqrtoue dheclel danlation technique ured - ype checking ard intemedixde code gereiation. orthe sade application of SDD » te conshwebion a Aumar frees. Since some compilou we. syrtone frees as 00 interrnediode nepresentadion ; 0 comno} four of sop teens ds ip sking indo a dre. — tele consilen foo son's fx consbrocting syntax frees for exprenions. the fick, an 5— athBhuded inition, i Auitable fx we duking botorn —up pouing: The Aecorel, L-othibuded ,ts auiteble for we detng dop-down pausing . Conshwelion 4 Syrtox trees: — Coch pode in a Ayntax trees sepresents conshuct, the childeen 4 dhe nale 2eprent the meoning jul components °F the consbwet. ~ The syrlox tree pode sepreventing an enprento E,+€, hos lobet ‘a! and too clildren aeprorenti ce aulexprenion E and E,. 1 lle implement the nodes pL a Aurtax bree ‘oy objects wit a Asudtalble amber of fetes. That ce: Ci) leaf node Gi) Infecier node () Fee en node: ~ leo Gd,erby (safes rales ction veates an identifies node with label “id' and o poines do ayoel doble » qven by ‘enhy! S lea Cruerr vo’S [rum [a] = hey (enction cealey noder Jo number with} label Spur’ oad ‘el’ fe vole | that nursber 1 foc Untemediate nodes — néde Cop, lett »ight } + tet “apt eters chon neater a node with the eld opercter hosing ‘opesedton' os label , ancl the dwo poirtens yr left $ wight produchon Sernantic Rules \ Es ear Enode= naw Node (4, & node, T.node) 2 Ey e-T E-ndde = rew Node ('_!, &. node, ‘TenOde}) See feed € «node = T- node 4. T— Ce) ‘T: nose = E «node ST Id T- node = rew leo} Cid, idemby) 6. TS nem Tenode = new leo Crum, neuneval U Kooehvetiog Syntax Heer cng dop deren geina: produschion Serrontic rules b este! € node < El ay Elinh 2 T+ node & €'—+ae! Els inh= news Node Ce, Chin Tray elayn = e ayn t + Fore Elsinh= news Node C2, Cink 7. nodel EL ayn: El-ayp \ wee El ayn = Elinh ST Ce) T- node = E-Node Beeoastal T. node = revo lead Cid id-ent 4+-T—S rum T- node = revo eal Coser maar € aos Pd \ : a me E : node orc cdenL Races E 1 ee i ' ss | Ts. nO ,Enode i+ jaan ae fia Ne bang rod 7 ' : ' \ ' sd! Hl \ ' i ene et ‘, i ; ; ieee al wv ; : ' Ls | ! ' ' ' 1 OO R= new leaf Cdl enbryo OR = new | Crum, 1) FO Pye hea oe (~,9,8,) BO Re me leat Cid enhy.c) >) fo = new ndde (+, PBA) Consider ‘lp a-ure and conshvet Ayrton tree: Divectee! Aoyelt Groph fhe Expression: (Dag) - DAG » o livected ah cicwen by iden jing the common subexprenions ~The difleence behoeen DAG ond Syntax roe is thet common Subexpronion hos move than one ond in suntox ee tho common suber -Mion would be aepeorentedl od duplivede Aublvee. Ge, Drow the DAG fax the exprenion (axb)+ Cc-a) # (ab) +b The post eder froverol & abecd—talx» xb+ Syptex trees ue fs x b ie \ “os L > cour Poe new lent Gd,o) Pat re leay Cid, by Revov leo} Od,b) Paz new node CX, Ey Pa) Pps raw node (%, 7, %) Res wae leo Ca, ) Ro = neo leo Gad) Pye vew node (%,P,Ro) P= nee leaf Cid, b) p ¢ nocle(+, PF; Pp = raw node (-;f,Pc) Eee (4, PsP) Pz = vow node (40, %) Pe = rew leat Cid,a) oe DAG: “The Aen yerce ° pectin oe DAG & . Poe wee (coy Gd, =. 9, = row (ea Gd, Pye new mode (x, P,P.) Car) - a fac ne feof Cid,0) na Ne b %= pow (ea Cid) f 3 P= ew wee (- 1Pu,Po) Ce ea) Pa = row node C4, %, Pe) Pr = mew mate CoO, Py) Pye raw node CL, p, ) Geation c three, acklres code: P>q PND veg 0k Osu 100; 3f lea goto to 48 MOU dire MU dase) lor: goto . Nia tye t, ANo +, 1Os: fre] 3: des ty or 4, NOUR D meg gee et Wwe; ta: t=o0 Obs gee wos tom: Gir] to8. 2 Uo geo ww Ol teco lo; oo UL 2s ARG (rv) else 2 HAN Ce) Thee oddies coder Wet NE aca. tor tow goto No fori 8h esa goto Ob tos; gee ou tour ah ard qoto lob tos goto No Ob diye ary lot: 4, re HR logs Re +. tor. goto Ww No tate gel Ws ee t, M05 stop while shatement Lith me goto A goto band. &): fonshuct dice adden cade for He followin} F Deach) ond Cec rd) o« Cordy) |tten Ext)! Ulale dhe Intecmnedinte code fr the bltouay while A>BR and A<=9%8-5 do Biz A+B + wor ton 02; tos, Tou, 10st lob lori 10g. &x lu Latycaxs tye too TE Reeth, apie Lat Ars O48 1 fi Leng + stop Di Generole the fuee addien code for the ed J progam. le (ace and Ben) do . Bel Hen cac+\ elie wile pzeo do Bz AaB Thee addon codes WP (ace ten goto lor 04: IE (Acad) Hen us a m {or qr \o0 ib (B>) Ahem qoto toy rest . gic AAB qeto AS io. ni ae Hon goto ta ph a Ob oe ‘Hi gote 100 peed MIS: sho est f goto _ 100 cone statement: — the suntan Fo suttch—coue thot i Switch expremion core valuet » shit Cose value x shut Core value: sbmt dejfoult 2 Shak a3 Trorslotion Scher. fa switch cose: Prockection Semantic action swith Evaluate & inlo $ auch that 5 t& qolo cheek . Coxe VWs, Kiwde Rs, qe lout Core vg Ly: code fx S goto laxt (O48 NS Spay Ly: code fe Sa goto last defould S10 Lat tode An ny goto tat 3 check + if toy, gee by Pteu, goto b iF tow, get tne ee Switch Coh) case 12 ¢2aths breaks case as C=a—bs breaks j Three ad daess code 100% uy ch=! gee Li tol = if thea qe le loa s Lpotys=ath © loa eet Hors gee task 105 3 Lgstgi sa-b NG ee ok lot: . a last tos = Last§ €x.(5) Genevale three address code for Syrbel tables Eee panes” Pefinilion Si L table i a data shucluve usd 4 compiler te Keep track of semanlics Of variables that means sqrnbel table stoves the tn4prmation| abouk scope and binding thfown ation about Names - > Symbol table & beilk th lexical and syetax. analy sts phase 7? Sqmbol table i used by various phasesthar ase th Semanize phase ~ tape conflick Bsue . Zi code qeneralion- jrow much ren téene eae ‘ allocated « Lvalue ond) x value - the Vand Prefixes comes from leyt and athe site assignment &r [a]= v + Jevolue value Sprbe tetie see Names Altibubes Variables, constants ype" size , Scope — life line bindaty ~adduess lineng- Names atbhutes provediuey r Junctions No» of porornetens ,nebuan hpe Reprerentation | Nemes in Simbel dobles, —Thee ae dwo Apes 4 nose vrepresemtetions t: Fixed length name; A fixed spoce fe each nome is altocaded Gn Syniool deble. By tis ype 4 Arroge TF name is doo Amall then thee b a wae °4 apace Gey Moree. caleulhate Sol Ath8bude a b P Variable — length nome: The ansount of apace seqpivech by shodrg equol do shove the names-The names can he chpredll cody help 4 stealing index and length 4 each nore Nowe hal Stoutingi neler length a oO 10 10 4 1 2 (b 2 No. o idimenilana pase, bound}, sare | ‘4 Id Olasuseo tse qawn 2 3 Wis wel cCokecutatedrs vom sak bh Qrprigelion 9} Clock choke! lace: -A block shvclued lan ge a Kind af lonquage in cushich rection Of Aourte code & within Aome mmottehiog por q identities Auch a a onl * mo begin and end. I Such a Aection ges executed or one eit 64 one procedune ora Hon a Nouralty block shwchuedl larquages 4upport Shelued programming approach SEC, Cet, Jove, porcod, Argel. \mplementation 2} Symbol table; The fpttewing datashvehues ve und dor erga sedi of block shuchued lonquoger. & Leewe List a cere eren rey Gst 3 Hashten,. a ms A Bren Hat bo simplest kind oI mechani do implement dhe — symbbet dable- In thir an wvay & Led do sheves names and amociokd information . New fame can be added in the order they ovwtve. The pricks “avalible” i mufndadnad ob Re ed of al | cecal aed. Nome 4 re di Name & injoa Name 3 inlo 3 ' , Name y in f —To sehieve the: inpemadon about some name we Stout Prom begining oy @oay ond pon Aeeuching ophy avaliable pointer. : -\P we seach a pointes avaliahle without Arding a Wane. aH get on ever Muse of urdecloxed name! ~\altale Nwerting * a nee name we should ensure Hhok tk should ect he cleady Hoere «IP ttt abwadd Pruent hoe ten another erovo oc fey Scvolkidle seyred novel! Th odvartage of list egantgahon 2 thot it dake raininun amount of space Set|—orgonized Lidt: — The symbol deble inplerstation db done usin Linked list. A link dield added do cock record: ble beouch re corcls in ttre ovder pointecl by the link f Unk fseld. A poinks “Firs iy mointesinedl 40 point 4o Rast A0etword of -the symbel table Ig —Tth ve! ce do there names can be Name3, Name 4, Nome &, Name 4 mUllen die name bt Ae lorenced ov coded it is moved do the. feat 4 the Usb ~The mot frementy seleved name will derd to be front of the list. Hence aceen time to mest frequenty vejowed names will be the least Nome 4 (njot Buk Nose 9. Injo2 nlame 5 inlo 3 Alone 1 Infou Hasktes, orhteg. Hauling b an important technique cued 40 secuch He records. thin method aupercio to list orgorisation. In hashing scheme wo fables ce maintained ') Hosh deble » Symbol deable The Hash table contains ‘kK’ enbies Jrom 0 40 k-l. (There enhSes cre besckally pointes do symbol doable pointing do the names a symbol cbble To delermine wheter the ‘name! a» in symbol deible , we use a houb qurction ‘h’ Asch thod h (name) will dervlt any integer behveen 9 do kale any ome by position = h (noune) Hing this position we con olototn the exact location sf Peme in symbol dable. ees Gaieeale Wes eek aymbol ceble can be shown below. we can Aecuch ‘ C= - He bl —}--Sc]x SE] [Soke =) Bens PF [SS ay Source Language issues: : There cn enn eae fectures hot affect i Organization 4 menor «The orgorigation of door is delewsrect by omwverting the following qpestions The source lanquoge issuer ove | Ooes the source, language allows sgusuion: HVWkile handling securive calls dteve may be Aeverol — inulances of Aecumive procedures ted ove ackve Siewultaneously - Merory altorodion nut be needed 4o store each Intderwe coith th copy of loro voutables arel pore medoy poned. to hot re wutive provediuise - But the vo. a octive instances 15 dedermined by sun dene. kt) How the parameters we pamecl fo the procedud: Thee ae dwo methods 2 posemelers pening That one call —by-volue and Call by~ aefenente. the alloca shelegies for each 0] these methods axe dlijJeent [Some languages sup port parsing of po omelet ihsel 05 pouarny ma sehuin volire of the procedive ibe} could be a procedure ict) Does tthe procedune 2qfer non-local ames? How) ~-Any procedne hos a accen do {4s local names. Bub lanquoge should support jhe method of acvening non-local narnes by procedlives. Does the lanquoge support the memony allocation ane L Tecalice dynamically 9 The dynarcke allocation anc deallocation of enon brings the effective obtlizedion of menor. Storege Allocation Strateqies: ~ Run dime stooge & divided info: \\ Code Aveo ® Stodie dada avea 3° Stack area ue Heap Cen Thee are fee Ali fjevent shoroge altotodion holes bored on tts division Of weEN—dimme storoge That cue. \\ Stotie allocation: oe oe I (+ tr foe all the date objeck at compile dime. 2. Stack allocation, Kin ths a dlack t wed +o manage ttre auntie stooge Ib. Heap allocation: Hn thin the heap b wed do manage the dynane okt memo allocation, Stolic Atlocodtion: \} The, sig 4 dota object b bnocen ot compile dime. “The names o} these objects ae bound fo Aloroge ot 1 Compile dime only and such on altocation af dada. objecls % done by stodic allocetion. a: The binding of rame with the anount vi stovege| altoceded do not change at yun—Hme- 3: An thts the comspiler can dlelemine He anount of slowoge seqpived by each dada object + Ancl Mt becomes eaay a compiler to Bed the ackdions 4 there dada in the aclivolion seco. be AE complex time compiler Con fit the acdkenser of which the toageh code can finch “He dada it operctes on. Limitations 4 static allotations: eee —— tthe stoke allocerhon can be done only ‘P the size of doto. object & known ot compile Hime. athe datashvelures cannot be crcerled dynondeally ln the aeme that, the slate allocedion cannot monoge the altocation a) memouy ot aentine 3 Recursive procedines ove not supported by thin Aipe a altococion. Stack allocation: + Stack allotadion shodegy ba shodeqy tn which the stooge % organised os stock. 2 Ay ackvation bedins the octivalion secs one pushed onto tte aback and on completion a the actvolion the covrerponaling activation secods ean be popped - 3° The dodashuehuer can be erocled dyrantcally fo Stosk altocertion Limi tations: “The merwory. addening can be done using poindeu and — irdex segisless . Herve His type } allotocon slower than sobie allocotion Heap allocodion: The heap allocation altocaler the continous blo ek ef wervouy Blom aequred qe atoroge of acti veution sectors ters other dodo object. Thin allocated Can be deatloradedl ewhen actvahion ends Thin decltovoreel Cree) space con he fusthe seusedk by heap eronager, 2The valuei of non-local vouables nual he sefoined even oftes the activation uecord: B The elicient+ heap mancgement ean be done by i) Geoking o Linked Vist Jor the free blocks and when any mene in dealllocadedl thot block 9 memery is appendect in dhe Linked list- ) Attocade the most suidable block vr] memory Jom ane Linkd Usb bey use besb fr technique ger allocation ey block at Comparisions hehween static, eback and heap allocodon: Stole allocation | — stogk allocation | Leap allocation. Stoic allocation v In stack allocation, In heap, heap ts done for all codackiech stock ts used 40 cred do manoge at compile Fre manage suntinne, shrage diynanite. bn allow Dotashvehures conrot be Dodoshuederes arch — Dedeubwehues andl Creede dynarcially Has ote objects cam be date objects ean in Stadie aullotetion eed duynandealy pelea Compiler con dedenine aca the amount of Ateroge beatae) aeqyivedl by each dodo, objech Mensory allocations | Menor allocodion Menon allocations “The romes eo} data ting LIPO actvahon A conlk bleu ohieck cue bound to 0 cols anol dladevobjects of min from heap a. ot compile se pushedt onto the ae ‘Te Stook. Menvovy acldieniry dada okject (os) Bee eA ial egl fase A inked list & Maintained free loves. - Merits and | Merits and - |Medh and mo Leeifationss: Limitahons Limtehions te Aiemple to aupports clyrande efticiont mln iraplernen but support eal allovation but It ernment & done stabic attocakion, only d» slower Hho stable usiog linked sh-The Sindlerly -eerwive allocation shrodegy. deatlovadion spate Pricedue oe not 5, weumive con be vexed Bul Aupported by stoHe | procedlures bub sefesne rin block i alloration shradeqy. 40 non-lotol verte tales) allocated! using ochvalion wed host pe cannot be sefeinedl Activotion yeword: —lt tr a blok et mennouy sed fr managing in ouration ncecled by a aingle exeusion of oo proved Rehun values Hakiunt posameles Conbeok (dynamic) Link Recon (static) link Saved mochine Stabs Loco varoWer ‘Ternperoves. Maxtor fields or contents of achivolion revels axe a The temporary variobles cue neecled during the evaluation a exprenioms auch vavables ae atoed in dhe teenporn aey Feld Of achvohon secord. 1 a Local Veotable: The loat data & o dota thal % local do tte creuuldy © cedure in i ie ue Hee it geld 4 activa hon ® Soved machine zegisters: Ths petd olds the i j of a Vat linea seqareling -the stad | JHT before the proceduse tr called, Thin 4 nbn toadlne. . a - - so aa Fee It. Control link: rts field ophiones. ME palin to dhe activation ae cod of de calling, procedure - this link alto talled adynonic Unk. |s- Acco tink: Actual Posome ley: Thin geld olde the bon about the achat | peromerten. there plea) posomelers oe Sap pamed. to [the ‘called’ poceduse. © Accom Wok: ‘The jield i» optionel. i refew do tue non—loral cola in other achivation rccord. Thr field obo called Srabe Wolk yeld. i Rebun valuer Ths field i used to shee Hds rest 2 © unetiog wol\. The Aige o} each eld 4 achvation secod eo determi. -ned ot the time when a procediue & ‘called.’ Access do ron-lotal names: Hondling non-local data Stade re (09 texieal sope f Dynamic. Scope: He Accem link > Deep aceon -—» Displasp shallow Hlth i» wed by block eed bay non-blek shvebued lenquoges shvehuedl longueges Store scope: Q) Accen Vinks The inaplerertartion “} stodic Atope Cor) lexical Atope ton be obtained by using pointer to each octivation recod These pointer cue called aceon links \e procedue ‘po nested wittin a proedwe ‘¢ Hon acew Wonk of “P' points to oceen link af most vecent achivotion ro ced of procediue ‘op EF! ConBder dhe ppllowing plete of code arc the auntioeg ack dune exeedion °t Hee program Vea mnt; a: Ptocedure a, A Vas ad: int) bean ars, end; Paccedure @ Ci: tna); ——— 600 Var bi tnt: Procedure c} (ed Varck: tnt; 5 beeyina y cnet; begin. te Ctez0)—then SCi-1) — 260) elre cy end beqin acy, ordi tect ») (a) tert ¢ acest Wak acece Itt Os ac) a: acess liwk gc) Seb Acese link 200) iy Kcect [ink 16 24 Cod dest Cay deat cugditke accenlink ay aL BO BO) accen ink accom Vink pbs try te) Blo) Aceen link aceen link . ia tyb: Vyby Cy c Octew link accen link a ky 4 Accewmlin kk dah GW Displows: Aa ex peruive do transverse down aceon link every Hine uber o pochadar non-loral variable o arcened| To speed up tee ace to non-lovals can be aclieved by maintaining an arviay ef pointer called cli plovy (0) An coma of pointes to acbvalion record cm maintouned, tp) Arcouy D> indexed by nesting level. ce) the pointes point to only cotenible ach vector ne cord: (da) The clinplos, changes wher 0 new achvation Ocuws § ft nust” be newt when conbol 2eleny) fern Hee now oot} vahon. 2 Duarte. Scoping! ay Deep ante: he tdea keep o tock % actue vowtohler, ue conhel inks intleadl of cccem Links and csten we work 4o find o vouwioble Hen Acarch the stack hor top do bottom Looking wost secon} ackivahion accord thot contain He Apace des derived voriobles . Thin metod of aceersing non— total variables a called deep acton. GE S hallow accom: the ideo i to herp 0 cont shovage with one slot fx even variable name. IP dhe namer cue not creodedt gf surp-Hme 462 Hen that storage layok can eee fred ot compile dime ottenvise when new achvation of provedure cho-nges the storage enter fo ty lotalr of enby and exid Compoxition behween Deep and shallow accem: Beep aceon dekes more time do accen thre non— lorols cbile shallow acces allows to accey . ~Shaltow accom hos a overheact Oe hound Liney Procedure eny ¢ exit. ~ Deep accey needs a symbel table at wun dime ~The memo allocation and deatlocation & done deallocede block '30! €eplicit allocation of variable stzeql blocks: > duct heguemt memocq allocetton and cleallocet Tithe heap memony. becomec.—fraqmented hel Meane heap may concicte ef come wleck thet ave -fted and Come —thet Are Riloceted, > —fox allocating variable hed blocker Some cuch as —firel 4H woroel HH and bert fH Are Uted] by icthen a bloce of ize *S’ fc allocated and tf ve Cearee for the free block tn the heap Memory Ctretebi wT Dynamic sloyage atlaotion -eshoiquee: Two hypes CY Expl alovedion Gi) Ireplicit allocation. Expt allocodson, “the explicit allocation ton be done fox fixed size and variable sized flecks Expat allacation for xed sige blotka: — Th bt che simplest technique a enpliat alloralion in which tae Aye of the block fox clic wenony i allocated i irect oer dechwicue a gree lish in ured. Free list d a sel of pre blocks. -thin Ust & observedl ester we want 40 allowle menor. [2 same fremory i deallovoted ton the fee list gels appended the block ove linked +o each other fn a lint Shuchue - The menom allocation can he done by pointing Previous node to te rely allocetedt block. Sinwilooty raenory deallowation can be done by de-sefevencing tthe previous Wak. ~- The pointer oolich points do qivt block of memory b& talled owallioble 4 26 ae Avel first available tree block whore cive>s fe Uleed ~then-that technique fe called —fived 4H Method Lometimer al the free blocker are collected ek T10 form a large free block. -thit vHimetely avoids Hthe problems of fragmentation, WD buphett allocaton:- > twpliett allocetion % Performed veiny User Program and Auntime packager by the Surtime package fe hequiced| “10 Pence the — etorefe block fc not fe Ute Block eize Copton-t) feces eee ree eee Befesence Count Coptio Mark Cophion-?> poinlar —t blocks eM SF there are two problems —that are faced tr tmaplictt Memory allocation. fret problem fe Aecoquictog blocte boundarter, ff —the block Site tr Aince then Utes data can be castly aceccible Cecond problem fo to determine phic block tr Tn Ure. > There Are two apposacker tec for fraplictt Aleo Means Uf the. Aeference Count of particules block cleop comm th “po Athen block ie hot Aeferenced tne and hence H can be decllaxted, WD -Mavktng techniqueri- thie fe an atlernetive Approach te determine Nheatha the block fs in Ute of not» dn this method —the Ure program fy Cutpended tewporary and —tozen pointers Co) bit Mepe are Uced “th Mark —the blocker which Use 4 geet

You might also like