Вы находитесь на странице: 1из 696
PRINCIPLES OF PROGRAMMING LANGUAGES: Design, Evaluation, and Implementation SECOND EDITION Bruce J, MacLennan HOUT, BNEHART AND WINSTON Now Yok Chicago Sanfrancisco Philadelphia Montes! Toronto” tondon Syaney Tolyo Morice Cly RlodeJonelo Moca {ME BEGINNING: PSEUDO.CODE INTERPRETERS 4 1 Hitoryone Molvaton 4 12 DesgnofarmsoCade | 6 413 imporentaten 17 14 Braluaton and Eplog 30 2._EMPHASIS ON EFRCIENCY FORTRAN le 24 Hetry ane Motvaton 33 22 Oedgn Smucras Orgonecion 35, 23. Dedgr Contorsiuctues 0 24 Delger Ooo Sructue 48 25 Dedgre Nome Siuctues 76 26 odors Stacie Sucties "28 27 Brckuton ond Eolog 99 Srwcter 96 3._ ELEGANCE AND GENERALITY: ALGOL 40 * 31, Hitoy ane Motvation 99 52 Dawg Smetuml Ogenscton 102 33. Dede Name shuctaree 05 34 Dodgr Dara siucures 122 35 Dede Contolsiuctues 129 Bocuse 158 4_ SYNTACTIC ISSUES: ALCOL-60 483 41, Design Syocte Smuctues 153 42. Desotptne Tool NF TEP 43 Gousuncnttey 70 Sacer 75 |$_RETURN TO SIMPLICITY: PASCAL on 1 History ondMotvaton 175 52 Dodgn Shuck rgonizaion 179 53. DasgreDotoSiuchoor 1 154 DesireNome Smiter 205 coms v 55. Dodgr-Centotsiuctues 207 56 Broustonend estoy 218 Becker 220 {IMPLEMENTATION OF BLOCK:STRUCTURED LANGUAGES 23 61, Action Recor ond Contod 220 62 Pecodre Cat andiatun 2 63. Deploy Matnec 24? 64 Boose 252 65 Summay 257 Boreas 258 7L_MODULAISTY AND DATA ABSTRACTION: ADA 264 14, Hilo ond Mebaten 264 72 Dedgh Swehaol Omonecion 265 73. Design Data Stoctures ond Nong 257 7A Dad Nemo Smictwee 278 Borceee 303 {PROCEDURES AND CONCURRENCY: ADA 81, Dedor:Contolsiuckees 308 82 Dedgn SyostcSruckres "22 Uist PROCESSING: USP PY} 24 Hoy ona Motiation 331 92 Desgr Smuctues Ogonnoton 234 93 Decor: Data Srucuer 34 Gorse 74 410. FUNCTIONAL PROGRAMMING: USP a3 101 Design-ContolStuchee 375 102 Daigreneme Swuctues 38 103 Ded Socte Suchiee 6 Berckes aD Wo cones |,_ IMPLEMENTATION OF RECURSIVE LIS-PROCESSORS: USP 114 Recushe niepreios 414 112 Serage Recimmation 427 113 Beuatonandésieg 435 Berceet 38 {2._OBIECTORENTED PROGRAMMING: SMALIALK 121 Hetoy ond Metetion 4 122 Dati Suctnd Ogonsaton 443 123 Date Casosand Suocioses 452 124 Dasigr Object anc Message Sencng 64 125 implementaen: Clases nd Oojecl, 472 126 Boustionendeplog 482 Groceee Be 13, LOGIC PROGRAMMING: PROLOG. 181 Heloy ond Motion as {132 Desig Sructual Orgeriacion 487 133 Dear Dolo sctres 472 134 Deogre Contalsiuctres "604 135 Beaton analog 558 Becker 580 {4._ PRINCIPLES OF LANGUAGE DESIGN 141 Gone Remarks 549 142 bincoles 56 Borkes S48 509 5st PREFACE TO THE SECOND EDITION Artem hick ae hs Ao ieee Me Get “Theres itu in small books. Theresa a daconceting tendeney for books to gt longer with each suceeding ction Ihave stfempled to combat Bat tendency inthe cond etion of Prncple of Prgrmming Langage. Inpatcse {hve rested the tmpiatin fo dacs dao program sing guages The reotn tha he languages are the means rate than te end, Every language fe induded. addon bing well noun o important nts nights intended ota rambo inpertan langwge design princpe. Inthe interests of economy Ive atemptd ee the mia ty Ser of inguages tht cove the leant topes Any more would be specu ‘On the ole hand. Ihave expended the dsason on several toi Incuded nthe fit edition, specially Fantinal programming Salt ad Prolog to ref the increasing importance of thse ith generon proven ring linguages Mii PREFACE TO NESECCND EON ‘Another way in which he txt ha en expanded bythe inion of ‘re 140 new execses expec ones tat sre not open-ended thou suc Won” Although peer cay thought qustons I ele ta hey may Be \topproprte in an atnetnt chanted by huge dase, fr which short answer and mathe exrces are mote appropiate Elly ave attrmpted o mak apparent it Ye books rate sere of assisting the ive pic progranming language genes ions, To this end have added to the capes for each generation a suey of lesan characteris, Tam gotta to shot of reviewer, colleagues, and sents who aug sted many ofthe change incorporated in hi second dion. Such eater Feeback very vauable Tam expel grat to my we Ga who spent many long events prooeding andindexing, She ss conte othe om Pletion of his end ction those nd many other ways PREFACE PURPOSE ‘The purpose ofthis books to teach the sis requied to design and implerent Progremming languages. Dignan inportat topic fr allonpates ee studers regu of wither o ot they wl eer have o seat peer ring lnguags. The usr who undentands the motivation for waa he facies wil be able to use them mare tligenty. "The comps mee ake ssnerstands the motivation for these faite wil be able to iglenent to, ‘more reasonaly. implementation sao an ingrialtpi inet lowwaee ‘designer mst be avare ofthe costs af the facies provided Both tone oe ‘goto oll computer sents bens allem scents ws Igoags td bose thee i an increasing numberof lngungeive human ine ‘word proceso, command languages. ec) Int require thee les thee ‘evelopment. Ths this ook treats the design ad implementation of pron tng langage anaes that al computer sete saad eo x ed SCOPE dearer ie es armadillo ers and 29 on Teguise caren nos or omen ‘Sting he es to the cents footer designers nd fo ingles. The {Bity of descptve loos to aatst portant huratersir of 3 dean nd ‘it lover tate mes tere too able or emporing Sd eben ‘Shige Thos, ts bok ams fo tech the despive tol important or ‘ing lnguge deg rid mpenetation ior Wan important spect sf sny design dicplie. Oe he designs odin thet canny be usd nthe ior cone. importa Ht the det be ate of he dein tre nth pas nd hy hey Sitreed o aed Thu, ths book presets anguge fis and yes Bosra cote ln a aiy moving fed such computer science, there ia danger tat any ook wil be ou of date i few yeas. Worse, thas the danger ta» com fuer sdeats kao wll soon be out of date te Thereore imperative that we leah nee of endorse rather an tc tae that se ron abel. Arsen he erplementtion tehiqusdacussed ints book $e sens: ha Tom the buss f techniques that ae ly tobe use fr 3 lenge to come ad that canbe ved To schive a wide range of gol, Pri. sore phased mor than des However hr lor rot mie to prevent the explosion of nowladge Rather than yg to preset allo the impertan!lnguage styles language fc "ex desaptive el, and inlameaation techniques ths book acta thet ‘den ip the ceton of there hinge the Tong ren i il be mach owe ‘lable since most ofthe specie tecniqur we feck wil Deore abscete “The tecnigies come bsclen pat because of the aly of hase who an crete mer echrguen, Metal are hase thon rel Expeienewith programmnrg languages far sown at altoogh he yn tactic form of «lange ls impart. the rel efectveness of 3 anguage i ‘detemied by is semantics nother word what we ss mare portal han ‘ray the way we say Ht Forts reson ths Bock compares and vats [Shpuners on the bas of wha can be si nthe ngage rater th he deta taint By the ame token, thc eplementtion of eomante hea ‘Se organist stressed atthe expense ofthe inplenertaton of sya he pasing) Smarts empl mre ha sya reece a ORGANIZATION “There are te base ways a rograriinglngange test can pee the haa Aerts ofa mer of lengangeorcntly a ety. Ina verte or ‘ation, various langunge topics ae tested Gre by one, racing each hgh Several languages or example, one chpte may teat procedures, acing tho characteris in FORTRAN. Algal snd Pea. “Anstherchoptr may di fuss open FORTRAN Algol and LISP aes forth, for all the ius fh Wes ‘One darger fs verti organization hat it pt to degenerate into = caalg of fear 2 horizontal onanzation tet languages 2s wholes. For example one shupter would dats FORTRAN. covering procedures scope, rd ther npr tart crates Another cpr woul dares Algol another Psa and 0 ‘ot Ahorortal rgeustin i sein thir bok bears lates dng the intrelstionsips baleen the prt of» programming language ‘This oon ‘veooked aspect of guage dein the cust of many anoressen camps ‘ona The harzntlaproah rao necoary langues ae tobe co ‘red in thei telcos. “he importance of historical contest ads o arate orgaiing principle, sumed ae onloeny mepulespyogany. The pipe ean tha fhe [Reming proces the tent repeats in mrmay fom the Nt xing o> ess Inthe computer scence fl horse wl ave 3 Fe grip ofthe sob Fe, Ths dos ol mean tha the tent mas be exposed fo every mistake sod rplore every dead end nth el of programing ngaages ont 2gey rap ite phylogeny, doer aot duplate Therefore ths book i organized ound 2 stepped down ar pane, htory of programming ngunge st “lews thes! to see ue inher itoreal contest an to appreciate the ray lngunges eve Exch fecha is own st of peur concepts an vemncogy, progranering ingunge devign no exception Se of thes concpt a of ‘imost mpotance: ther ar deal of rasent ole. ser hate an {guage designer undestand the mporant concept ily. nal of hr ica ‘on. Forth tobe the ce, each concept out be seen and investigated sve rms in a ramber of ferent contents, When students fal sce ald sono concept int ll generality they wil understand te patios ‘nil not seem abaya dfntone 9 often do, Thus an ndtv or bolt Up specu is used or presenting concep ad absctons Convery a topwn approach sae for preening the trates and facies that ae fourd in progmmning bngunges. The reason is that a Pro ramming language fly ot atize & bt understood in content ht i ferme ft linn with nguet i h ea the angnge ond Ye gr of i mesnce language. Thus, structures and fait are presented in the functional context ‘Thi wil ip the de to understand ths ngage aa wified wee “Te rel ofthese considerations is that the book at a whole onaniaed horonaly and each chapters orga verti Tht iy each language tale ino ts aor stata sete. ‘nal eases the goal as been to give the staat 3 comprehensive inde. standing ofthe most important supe of programming langage des and inplemwataon, “This book is intended for a one tester cours for shoe couse some af theater pte: ach as Chapters 12 1) can be onted ines. Is Suggested tat no matter what ee ip ine be reserve st he nd of oe ‘ata fr dsciasing the content of Chapter 1, "Prnpes of Langage Design "Mast ofthe problems sre praca exerczer ngage design. They ld frm the bas fora separate guage design sbrtery or fr csstoom ‘Becanon Ins ow css they at polenta the topice Inaccord withthe bok gol of emphasing brood pnp ater tn tals no nngge i presented nfl. ‘The ster wl ot fin sy chars for FORTRAN, Pascal or Ada Furth intl ht sn wl be sl fo program in any ofthese ngage ely onthe bast ofthe desiption hte, [rated waders wil an the fundamental cones of programming anges, sehich wl simplify he esing the dt of whvtr lgragrs they my Reto use “Tote hs book noe veri concept directory has been included in sddton fo the more contention indo snd table of contents. Thi vet cally ongnied outline of topics in guage design. Wh i stders ean nd fer eample sl ofthe sections describing paueterpasing moses ACKNOWLEDGMENTS Several generations of students in my introductory programming languages ‘ure the Neal Postgraduate Schoo have Ive trough ely dei of thie ‘ook. Their comments rine, and toerance se gate acknowledged. 1. We amen has contbted substan fo the completion of this book hough hs encouragement. igh reves of sly df ad many . cs >) 1 inden Trane of control + Inptoupet What syntax should be we for ths pedo code Since many ely com puter dot hve fies for lphbeti int outa we wl hve Io we 3 ‘ome code forte tren ofthe lngingearthermore soe the mos “Common int device were card readers we wil adopt he convention oF wit ing one nares presenting an operon) on each card New fe suppose tha enc operation wil be rprseted by one word we wl have 1 igi mth ttc fo epreset ech oparatin. How age wl the adress bel Two digs {re deste they woud ony allow 100 location to be sides our ‘igs ar too mach since they would port adaresing 10.00 locaton sad ‘hee are en 3000 nthe acne. So thee dig seams the ight choice emits drsing 100 locations hich adequate (let was conse _icjate a ht time and eaves the other 1000 ostins forthe and ‘roram. IF the fst 100 locaton are sed fr data, thon tee digit il nt “low adeeting out f the dat aren Ths a example of say in this case ‘re have mae inposible fr the we o commit» patties of enor ‘erwin the program othe errr. Ths san example ofthe Seay France which was rt propored by CA. Hoare DeseNOFARSEDOCODE 7 The Security Principle [No program tht vies the deiition of the langue, or its own intended strc should ecpe detection Instruction Format Let conder the form ofthe atmetic operon since ey wil be the most ‘common, The nstructons cul have te thre, o furs Twoaddeses xt y+ + Thee adéreses 4 y + Fowaddrenes Ft 2—+w Each ofthese adress must be represen in an nacon. Therefor, four ‘res intuction equte 12 dps forthe operand aeeaes foo mux to 8 {na todig word. Two adres iterations wll work Snes fey only reo igs forthe operand adresses, lhough this leaves four eg forte opera. on, which exesive, This would alow 10,000 operations and we ony ave Binourlst, Thveeaddes natction wl conser ine digs fore ope. ands leaving one fo the aperations. Ths one dg ogee mth the sgl allow the encoding of 20 operations, which adequate for mur purposes Thi leads tothe flowing forma or or ihn rtrcons: 5 op opm sped dat hee isthe sign. ps he operation, op and pm are the operand and and dat the destination. Fontan "+1 means aden then wuld add the contents of lction 010 othe contents of ation 150 and tore the cen location 200 (we ave added blk to the code to make # more readable) Cormegenal Design Since we ae coding operations by numbers, we can expec tt wil be dil for programmers to remembe tem, aed 10 a help we cx give them wl be valable. To pti another wa. He in mich pont om prudo-code ‘St spl an muvee an the rea eo, Sige Ste of he athe 8 Weaccneye: PELDO CODERS ome in pin (eg. + and ~, % and +). we cane the sig to ‘Eitgeth the pals A peliinary encoding of operations a= Note that we fave aed the square ton iti uf an se we aendy faite vere the gure rook. ts synth to ce sure! "This an example of oko! ngage desig that there ae two sxthogenl or independent, mechan (1 te dig 1 23) which sects the Seo efapction dave malileni, qin) and) he Sgr wick ‘cts the direct operon oi invene: Hare wehhave appli the Orthogonal: iy Prince The Orthoponaliy Principe | Inept ton sho be cooled by dependent mechani, | “Ts pine ew corllry of the Regula Peo ‘The Regularity Principe Regular re, witout exceptions, are exer to Fear. desc, ard npr In this case the regulary wil blp the programmer to remember the operon codes ‘why doe orthogonality simply a language IF we asigned an arbitrary ruber lo each peudo code cperation ® would be recs forthe program Inet to remember 20 independent facts forthe 20 pseudocode operations Ine we reflect nthe cog the dtinction betwetn the diets verse 1 You my he ret at sr et ot om hth patn thay ryt yy none opan Then pean prin | it DESGNOFARSEDOCODE 9 perton, Thrfore structure in the operations is fected in sacar in he ‘coding. The rev s that the progamer only has (remember 12 independent factsthe ps an mins sige asocted with he ect ad verse ome of he operations and the group that asocitd with ath fhe dips Another wy 10 espres ths ithe welAown seetral pip om les freon ‘Grthogonal means ight angled. What do ight anges have to do wth language desig "Tf we hve two independent meaning sew one with pestions and tnother with n poston thn me can deseibe me deent ou bites even though we ony have to memorice m minspendet fate ‘As mand mines grows much ter than m+n, Ths, othogena design becomes nore npr more poss mas be dente. Wen arr ‘many pone may be advantages fo have mare than to atop Tao much ethogoalty can ham a laguage since the languge may become ctered wit cin tat have rend fo symone boo ete. “That bs some ofthe ma postr may be so dial to iolenet. Sm of thon may ve be lege ne te poorest ‘rember then a exception hu iting te Replay Pen) eis the ‘umber of exeptions then hopes & sniagees yim re {EXERCISE 1-1. Explain in deta the usieaton forthe formu m-t ate < EXERCISE 1-2, Code an operation oad the contents of location 125 to the Contents of 206 and store the eu in 803. EXERCISE 1. Code an opention to divide the conten of location 401 by ‘he cones of location 623 andre the quoi in oeton 102 [EXERCISE 14 Let the contents of location 402 and 760 be x andy Code intone comput Fn ction 100. Assume tha Bt 10 ace tons of da remory are ealabe fr feporary storage, “EXERCISE 1-5: How cn the +3 and 3 operations be ald to be more 40 nemcnnencireebo Cope ERRRERSS regular (ie. me ike the other operations whe sil axomplshing the squne ‘Su aqure oo undion? ‘Comparisons We have si tht we want our vil computer o be repr so ths wl be tasers than he cea compuerAiving reply ibe eae we use the sume Formal or our lher pean ha weve sed fr the ane opr tons Lets ec how ti spp fo the compton epratons In ome sre tml athe vee fa ea and grt anor alba invere of Ls ‘Srnec at ngs tadistngalch Between ech operon and is verse. We ‘tend the operon able a flows | ee | Tse S| epg | 2S pw For example, the instruction reas f the contents ft ation 200 eu the kes fsa) ction or then goto the ination i progea action 035, Note Hit nok necessary finde he reer and les thao eal corgarions see they ean SS toded by revesing ther operands leg, #29 8 sed a8 ye operation 5. We ave looted pov, negative and nara ets since these en be coded sing the comparzon.Foristane if we adopt the convertion tht loc tian 00 alvays conan the muri ao, then wean amp Yolen HO Tocton 702 negative by 15 702 000 100 (course any location that we Kno to be zero coud be wed but ti alays vane to apt standard cng comets EXERCISE 14: Cade an intution to jump to program locton 103 if the tale of data oeton 732 greater than or ep to at of loeton SOD mo UESGNCFAFSEIDO-CODE 14 EXERCISE 17: Suppose data location O10 contin eo, Code an intron to jump to program lation £03 dss eration 465 ero EXERCISE 1-8 Code stations to compe the abc vale ofthe con lens of location 231 an store therein laon $03. Asin that the intrucions you write wl go nto rogram lotion 1 andthe sucrecing pes ‘am locations. Sate any other sumptions tat yo make. EXERCISE 1.9 This pseudocode does not include an uncoctonl ump. How could you do an unandiionl ap wing the ite provided? Wihet other operations do we need for programing? Certainly, oof he ost emmmon operon i simply to move the conten of one lcaton toate vthou doing any operation, Seicyspening not ney fa he» sp ste operation fortis It could be accomplaed by sdding wero. For exmele, +1 180 c¢0 280 fective moves the contents of aaton 150 olan 29. Sacra proms of ths dasgn i that Boating point arithmetic ie qate slow, you cr ace tat ta would bea very ineficent way to move vale tween cations, Tore We till us the #0 operation fo move ne location fo seater ‘Wihy dd we chose +0rathe han #6 By pking +0 forthe move the sere of odes 1,2. 3,4 stand Foran ey to-rememb sare ofeperstons of Inceasing compet rove. multi, ice This application ofthe Repuanty Paine will make the codes easier to remember. EXERCISE 110+ Code anzstruction to move the cote of action 100 Into dt loation 10 [EXERCISE 1-1" What shuld be the frction of he ~9 operation? Our symmetric design ads us to expe to be relted oa simple moe. Tt shoud 2 Eas maby a ml ee re hgh dt at mh necro wibtwo ate mr ee 42 wexcremcirsano-conenrneners Indexing hea wef pation that net ely o icenty acomplited wth the other operons (One ofthe jetteton frou pea code was a it provided binder Ings we il um to the desig ofthis cy net. To pfom indexing we tra pend te adie of the ary andthe adres ofthe dex vob, has Consuming to ofthe Ue sdren dein the ntton, There, the oly ‘operation we can perform ely on ay clemens at 1 move them to oF fom ote leone We can ee he coder +6 and ~6 to move fom orto a8 tray et and pny, The fomat fee perio ae tomes ome it for example # thee i 2 100.lament aray begining at lcation 250 data ‘erry, an location 050 coins 17, then +0 200 060 608 sil move he contents of location 267(= 250 + 17) to lotion 803, Sil, sl more thy content of leaton 722 t location 247, “Of couse one of the main reasons or ing aay i that we can wrt 2 loop to pero the sane operation on esc lament ofthe aay. Todo is regres oe able to ita, ncerent sd et index vrs. We nay ‘pect that we can te the atm and cmporon facies alendy defied i tar paced code forthe Ba hs no becuse thexe ae oating pt oper. ‘Sion and wes oe represented by integers Even this werent 0 would ‘be wsfl to batt out the cade common tal loops By buding th ito 3 freuo-code operation we emia sather source of er. This isan example ‘tthe Autoation Penge ard te cooly the Absration Pail ‘The Abstraction Pringle Acid requing someting to be sated more than onc; factor ot the securing pater tescnorarsunocone 43 She we can we the move insrction (+0 oie indies the nee operon (47) wl ony have to increment snd tenders To peor hie peti we nent now the oto ofthe sex the neon f the pet ‘bund fer the loop sd the loation wher the loop begins The flowing fo ral analogous to be anna ofthe compart +7 dd eres the adessf the inde, isthe des ofthe oper bound and di 'Sthe lotion ofthe beginning ofthe loop. The operon nents octon i ‘el ops te ten i tte ea he the cnet oft ha the mearing of the ~7 operon! There ar ever porsbiies—forbstance, dca ad est eprionso we wil lave # undefined For the ine Bing [EXERCISE 1.12 Seppore ht ther ian aay sored in data menocy begin nga location 40. Code an train tat moves the contents of 207 fat the ray element indexed by locaton 950 [EXERCISE 1-8: Sappose that an ary begins t action 190 n data memory, Code astro the 2d to lction 029 the anay element indexed by location 0. EXERCISE 1-44 Cade a nstraction tht increment locsion O10, el oop to code location 005 the content f 00 are ls than the content F030, EXERCISE 1-181 Suppose tat sn ay begins at lection 100 in data memory. ad that locaton 050 sears the number of elements inthe aay. Code nstue ‘Sons that sm the elements ofthe aray inf location OO.” Sae any atonal ‘Stumptions that yuma, Input-Output “he only furtions in Ui ht we havent yet addressed ace the input sc cout operations. A program eno ual wo can't read dts pit» felt. Therefore we mls the +8 operon to rexd aad cofalning one 1 Aig number toa pciied meray lation andthe ~B operation opt he ‘ontents of memory locaton. Ona el pseudocode» punch operon would betore common tha a prt operation since his woud allow he oa fone program to be wed a the input to another] The compete Ist of opens unmarzed in gure Notice that webave added op incon ofr ‘ie progam excl EKERCISE 1-16 Code an incr ord rhe in Ieton O88 1d wesscrencirei9o coneNTEREERS [EXERCISE 1.17: Suppose tat an ara begins a cation 680n ata memory ‘nd thst cron 97 contains the nome of lems in he ary. Coe in Hons eprint out al the elements fhe aay. Slate ny asumptins you make. EXERCISE 118 Suppote an aray begins st Jeatin 100 in data menexy ‘Cade nstrlon ofead uber ito consecutive ary cement unt 9 card ‘lang #9 999 999 959s read. Sate any asumelions you make We now kc how to wns india inetrctons, but weave nt designed = rears of ong the program a3 whole. For example, how do we ange to gel the program landed into merry? How do we itz loans in he dhs mary? How do we provide apt dt forthe prea. The silo tolton fo th problem to hve the interpreter red inhsation cards ad ore thle otet in conective memory lostons. Thun, the siatre of 3 ‘Ne have wed a card cntsinng the fig vee” +9999909009 to spas the tal vale from the program andthe program rom the input data. The oder ‘eas in the nal dats vale and ores hem kn conecuvelecatons (tating ‘ith 000) the dats mamery. Then the lade reads inthe program stron ted stores them in consctve ostions (tating wh 00) the program men Gry. The loader dos rt read the input dt: ths read by the srs propane whence exeste 8 insction, “Terfoe the general ctr of program (1) edrton 2} xen Ble satments, nds) inpt data Th ie nol uke the stereo Pace oF FORTRAN program, been oFAREUCO.CooE 15. 5 san = hatin 2 = op. ty = operand = deiton 7 Ta 5] ste | apaeroot a| * s| 3 é + | india | ut oan | ee) Fgwe 12. Panu Code Options EXAMPLE: Aloe Meon ofan Amy _ Ax an example of two tis pseudo ade we show a program lo compute th nem of he boi alors of maa) That i Ais the aay and haem elements we compute AL im Theft problem to determine the warble that wl be eee nd to yout te dita emery. We have used loeation 00 fora conta sero." The aay to ‘be merged eccupiesloctons O06 trough he end of he data meney The complete program appear in Figure 1 annastons on he vight explain fhe ope [EXERCISE 1-18 Wot a complete peu code programto readin dla ads (unis +9999 999999 fg cand ald up the mambers the cad pit out the sun EXERCISE 120 Wrte » complete preudo-cade program to print cut the separ ofthe numbers ren 1 109. EXERCISE 12% Wete «complete peudo-ode program pit cu the is 100 Fiboacs mumbers 16 emonnanraswo-coce eniPneERs +0 000 000 coo $0 000 000 000 “1660 000 000 ‘F8 000 000 008 8 cos 000 008 1060 Gos 008 6 008 008 001 +0 e00 000 ODL “V6 006 001 005 17 001 004 007 $9 990 999 000 ‘$0 000 000 o10 ‘apes coolant 0 ‘eae ‘rags tery ferns ate ‘poative kip ese nagate {aor tet wt oop 2 fn amber = prmtavornse (tet program ‘number ene vais Figwe 13. Pano Cade Progam Example EXERCISE 12: on ofthe istctins ‘ete + peo code program to readin the concent of ‘Dace uation and pn bath roots ey on ong this exer, Sel pray Gd ht ii vlsble to make a ihe map that shows the Tate whch vious vorbles ae word. 1 wil also be vf to use ym Hee AR eugh a the prog wton to detemine the ata oe wewwoeo 47 413 IMPLEMENTATION -Aulomaiie Eeecullon ie attemed ater Manus Execution Jn this seton we wl se howto contact an interpreter for our pseudocode. This willbe an example fa ele inter, on othe fo Important Lins (he others reste inter which dues Chapter, How we about designing an terete We cn feueny gel the sgh necessary to design an interpreter by lestigating ow we wold execute he language by and. we ae fo exeue peed code prograns ty band me wl ned some ‘nay to recod the sa ofthe computation, at the cote he dle mere 264, We wil abo ned sing of the program manery withthe merci a seh can oper nth ac ok ace hth ron he a also pat of the te). The major dts sacs rege by our erp’ thew shown n Figure 1 Note tte seg 0 ays sek mared from 0 to 999) to represent the areas of mery ted for dato an program storage. The data and program anys sre cll Dat’ and ropa! an the ‘nation pointer which veers our loeton the program) ied For ‘example, Program presents the station inh: Progra aay designed © ef— ra 14 itp ia Sets 1 Doptbtibttwe ean gan roping ean ‘pawl wd al puso mane dh psi la Neos wed aad dd pages 48 neeccnnuic reno CoDENEERRTRS by IP We may find ht we eed some ater minor dts rare a6 we con Sue with he de ‘he Rood-Execule Cycle she Hear ofan erlve Inlorpreer ‘Wie can now camsidr how a program scully interpreted. Roughly wha we veld ered the ee isrction tobe eect as iaated by theinsecion Foner stein the operation encoded by the Inrtion, ad hen perform Fiat opention han exci fhe operation romped te wil ben his roca again with he nest action tb enocated Tis rose coed the ad eae el ad ean be sueraed alos 2 Decade the stron, 4 Exec the open, 4 Conaue om step 1 withthe next instration Have you noticed that we have omit ssl bt crcl deta? When she instracion pointer aranced? "Thema place odo ths woul see tobe sep ‘since ts jut pie to eadig the nest nstruction. Wl hs wv fe 5 longa the program continues o execute sequently wil be del to hn «de umpranc hey mut alr the intracton pointer ep 3). A beter sl tion andthe one hat adopted in mow omer Toth lad vial to ‘dre the instruction pointer st he and of sep 1. Typ code a sep 1 sastration = Progra( i we pek, The IP here ead forthe net cycle f sequent exection so conti, oF ‘tan beaeed i step 9 i the eat of hun [Nati that we hve wt the coe for sep 1 Ina asa desripve oation pram din lngm Why would we wan towke a sudo code interpreter we hive Pesca nalsbe for programming? We woul. i we waned to be rest, we would we the pared code interpreterin machine Tanga. The res would ook ike iar 1, which actly snl part of udo-code interpreter This would be canying things too fr or gos to Snderstond erative nterpreter nat to relive the 1950s, Therefore we wil se tore conenon, Pel the nition for decrbing the interpreter Tht wl ‘low us Yo vse the algorther without geting bogged down in he doa of rrecelansuaseprosanenn. wreenoon 19 Insructions Are Decoded by Extracting Tel Fors We will discuss each ofthe hoe steps inthe renders eye Since our pasuo-