You are on page 1of 15
[Translation Software Aiteusierr TON Soemmns Srawes Tn Te Guerarron Or A Proona Syotax Analysis Grane 1+ Lexical Anelysis + Vanecestory Croractss (white space, commests ) are removed [+ Source. pogo is converted to tokens “Pxenreer cow ® = Count = 4 To FO TTotar wummern Of Trews Ane Powe “Mews” = Eunron 12. S Gusts = Foe Coust “Tota Nummca Or Tens Ane Prowe ” “Weus" = a ExoroR 2 Ktyword Taste Sven Tare + Reserved yisds ( Fore To, Penn) eAdeshficr(wriobh, cotatt) nome ued + Operaroas = the doko type + Theie matehing Eaters + fale (variate, consent orroy , preccre) = becotion [vate Keyword Token < 01 Token ll, 02 [-————_] Symbol Value ‘Type l = 03 start © Venable | = 04 t a Constant 7 7 wunber 2 Variable MexodeienaS counter 3 Variable |_— IF @AG 2 e Constant THEN ae ___| enter 4c ELSE aD REPEAT 45 || UNTIL 4F || r0 50 INPUT 31 ourPUT 52 —— znpFor 53 Questeon_(Prsrenre) 4 Acompiler uses a Keyword table and a Symbol table Part of the keyword table is shown. Keyword Token < 01 — + 02 —___| 03 Se | Ze IF 4a | THEN 4B 4 ENDIF 4c ELSE 4D REPEAT 4B | UNTIL aE — 70 50 INPUT Bl OUTPUT 52 | ENDFOR 53 Entries in the symbol table are allocated tokens. These values start from 60 (hexadecimal). ‘Study the following piece of pseudocode. counter <@ INPUT Password REPEAT IF Password <> "Cambridge" ‘THEN INPUT Password ——)_—enrF Counter < Counter +1 ——| uNTIL Password = "Cambridge" oureur Counter | (@ Complete the symbol table to show its contents after the lexical analysis stage. —_ anal Token Value Type I Counter 60 Variable (a) Complete the symbol table to show its contents after the lexical analysis stage. Token ‘Symbol Value Type 60 Variable | $1 | Congtont Posuiced | 82 | Vorable “Conboidge” | 63 Constant 4 | cu [Constant (3) (b) The output from the lexical analysis stage is stored in the following table. Each cell stores one byte of the output. Complete the output from the lexical analysis using the keyword table and your answer to part (a). 60/01) Gf /St 2 [ME wal 62 O4)63 |B) | 62 MC) Wo1OL |60) 02/64 YF) W2 Jos KS |F2\60 2 How she contents of the heywod ond symbsl Kabks aftared bo troeslate the eource code. pesquat Keywords (opcptes ore Oasked up (inthe Keyser tebte) + Wey words foperabas are cepresertad by the tohens + Identifiers are Nodhed up in (the symbol table) + Identifiers are comerted to Ucollions foddretseg + Used to create 0 Sequence of fohens (For the progeon) Addition task completed ot the erica analysis shige thot does nat evolve the vse cto keyword or a symbol toble the we ct a keyword of a symbol fuble + Wthie space. removed + reduntoot chords ore cemeved |, comovel P comments Grave 2+ Syptse Analysis TTashs gofemed wo eyotns orchpis : Constecting posse bee feorsieg |. chedsing the table & folnens to ensure that Yhe cules Jyntarl grammer of the Lonquoge are obeyed Je Rrodusrg on gree teport - Cw ot 62) ¥ % “We press Ff working ut fo given shkemert is Coane volid euardig to the given Bie prodution cules fe coded parsitg - “The geormalicod cules OF syntax foro progeomminn Donguage need _to_be jet out clearly so a progammes can vsite cade thok obeys the cules Ine _qoommmccen cures oF SYR Tore POYomnn| yore Neer 9 be leet out clearly soo pogemmes an write ede shat cbiys the cules Jando camper can be_buitt to dec thet a grog com sys these cules. The cules can be shown graphically in_a SNNTAY DEAD RAM or sing a mato. Uonguige such 08 Backus - Nain foam (BNE) mabtion Baacns- Nonus Fenn | ____ ts 9 ewolhemabicat way af defining estoy 1s pefined by” Obs zIatytoretriens cote, | cepasents of < OfeTr > ¢ Number >... ¢ Drerr> ¢drort > < Numer, 22> ¢ Orarr> | < kere > re A IBV CDIETEMGrH ITI FMR ~~. A_ word consigt F two etter 2 CLEVER > creTIEe> A word conut F ony tumbers F ktter < wonn > < Letren > | ¢ LE Tie >< woRD? Assignnent statement < Acsrommont stamemtnt > rts CvARIARED 2 < V BRTarer COPERATORD< VARIANE? 5 Ses. Drecnan < Drei > Diort> rs sterspue < Asscotmor staremtnt > it CVARIARED = < V RATHLED COPERATORD< VARIAALE? 5 sssgnment sateen sateen rane }+(>)-+[ rata} arms eves (~*~ < Letren > |e Letter 2¢ worn? AE Kword > tie < Letter > | clether >< Digit? + The we geaccotion stoge produccs an objet code . + The grogom showy have cored” eyotar . Te object code ig in wothine-reagable Pore + Stave 4 + Optimization Why Gde optimigalion is necewary! + Optuningllion sacans that the code esi tove fewer mstsuthiens s optirined code ouugies Los page in memary |, Fewer insteadtins eadutes He extrution time the grogiem Original code w % + y Object code EDD | app | sTo vexsyes| ipo | ADD | app sto |_______loptinised code w = x + y|Object code LD | app | sto | sexxlene xen x vewsen app —————_ sto < Case 2: (6) This line of code is to be compiled ‘assembly language, is shown below: LD 234 //loads value B ADD 235 //adds value C seress7—//stores result in temporary location ee-S€7 Loads value from temporary location ADD 236 //adds value D S870 233 //stores result in A Code. optimization . sence] this final stage. ‘After the syntax analysis stage, the compiler generates object code. The equivalent code, in ()_Name the final stage in the compilation process that follows this code generation stage, (Gi) Rewrite the equivalent code given above to show the effect of it being processed through SOE, opsemsamen, (Gi) Rewrite the equivalent code given above to show the effect of it being processed through this final stage. bo... 234, A00. 236. ——— find 226 | S70 2323 Benefits of opkimising the code. + Code ras Renser instrustons | occupies fess space in memory | fine taken to execute whale progeam decreays Revs As a method of scpecsenting on orithenctionl exprexsion 151 Tisrix foam: A-@ Reverse Burn Nomtron » AB- Cese 1: Usive REN bo eyolwke the eprersion using stods (b) The interpreter is executing Duraid’s program. The expressions are in infix form. The interpreter converts the infix to RPN. M210 The RPN expression for ¥ is pry -+ Q=2 uoMrot+r ® Rea The interpreter evaluates this RPN expression using a stack. (i) Show the changing contents of the stack, as the interpreter evaluates the expression for y. Use the values of the variables and constant given in the program. The first entry has been done for you. 2 2 u 4 6 ¢ 10; 00 cy s s ° ¢ ¢ Ww (4) + Amoys solve 86h bo ight s Whenever operator enters the stoch use thet operator on two velues ot fhe top ase 2: Twern fo RPN Conversion. lay A+B AB- &) A-Bac Nore: USE Bonn ALWAYS A-ec4# oO highest priority ABCE- a+ Some _pioity I> Sorte, privity lo (pre) * (R-F) Soke brocket first P+» Re- ———. Po+RP-» Ww (o-b) » Core) 17 ab- # ac+/7 ab- ¥ac4/7 (veer te Roun) ab -oc+s 7/ Pra -R IS Pra- RY Pat -Bs, ParRSi— oO -Ale + 4/CC-0) “Ale +4 O- A-B/» 4 I CO- Bracket: first A-Brue /c0 -~ A-Bruscn- 7 Cast 3: RPN to Infx conversion INTE? USE STACK ConcePT TO Sone sucl QUESTION iy AB- A-e a) Posmy RP-- — (sraar feoot Leer To Rta) Pra Me Rp ~ — (Pralarr ae-- (era)e (8-0) - ((R1a) em) (2-2) yy MWZ4Y-w a wre yet a weeny x (wer-y) MW) baw Watt - bra cdsa +- bva (c+d+0) (b+ 0) - (cr3 40) Case 4: eoeticad Quatios. uctlin 1. EeqQin tow RON is used by an interpreter to colmoke expressions « * Expression ore oAuays evelucted left to eights + Each cperetor uses the tive previous valacs on the stork Cencept uatry minus) LAE clement is © mmber push thet oumber ent the dock PIF dement on epuater then pop the fist two numbers bom stock + perforin tok operakion on thage numbers . Pura the gest back onto stock . rd once the Oost items im the expretion hor been deolt with. Ruder co 2» Aborto of using BPN for he cxaledan fn exprettion + No eced for rules & precedence ( BOOMS) «No acd Por beachets le Rew evaluction of spercfors ty oh uweys Dele to ecyht lOuslion op S: Whik-does the steterrent “Ne cect for cles oF precedence "means ? + Rates F prectesce rears different opuctors hove diferent pricrities Coowdtiply is done _bePore addition ) «Nn RON evalubion cf operctors is left to eight No need for brackets Quslin no Us ldeatify wh ccosns , a dake ructuce that cald be used be eoluoQs an expression in RPA 2 STMUMRE + Stack Bown: “To epeands ere popped from ne stack in the covers order to how trey were pushed mS: § how as terpretec 04 Fam L Wow eccor is found tre stabiment is erceuked Aisi ad ~ apache is tepenke J fot oxcsag ikerokion i wae bt aes cade , Wterpretcbion hos tobe re exocy time the pref fan tun

You might also like