0% found this document useful (0 votes)
74 views13 pages

Compiler Designing Assignment

Uploaded by

kumkumsharma2716
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
74 views13 pages

Compiler Designing Assignment

Uploaded by

kumkumsharma2716
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 13
fas Compan high ~ level . gousice Vhe C, Java code that con be Several phases; F Whot fe a comp A Compiler is a software paegaam that tronslates 70 Python into machine code on Question No: | 2 Explain code Wsiitten in progotar 4 languages ermedia executed by a compifer. lt consists of Esotosr handling ‘Scanned with CamScanner * Punses Or Compuer > @ ‘i tg > is phase baieaks the source code i identtfiews, keywords » operators sand HHerals, Fost example, Congider the expuessfon “2 =10 ty”. Lexical. analysis would tokenize Has [“x", &) In this phase, the compiler checks Whether the assangement 0} Aokens follows the cyninx sivles of the poregnamming language - Ht typteally uses @ Josmal gsammer ,such as contest - face grommets te generate & parise- tuee om absteact gyntox tee CAST).Fosr. instances passing. the expse- ssfon “x™= loty3” would vesult tn a parse tee where the soot fs the assignment stalement and the childoien axe the vartable 2 ,the addfdfonal operation, and the variable ye ic) Germantic An¢ phase ensues that the prcguam's syntax fe Semen Heatly. voll. It checks for type compalibl''y, ondectavedl Voxitables and other semantic Gvtors Fos example, H would vortty that bath x and y ase declared. veoriables before they nto tokens such as ax Analyst ing) = ane veed. @)Intewnedtate_Code_Gunesatfon 3 tntenmediale stepesentation of “The compiler generates an. fntewn: a 3 4hat te inglopendent of the target machine. the source code 40. optinize and can be. trans! sthis intermediate code fe easier ‘Scanned with CamScanner ated Into machine code pr different platforms. Fox instance, the expression “x=lo+y3” might be 4oranslated into hyee- addsess code Ike 44 = loty,rcetd. © Optintzalfon > “Thi phase fmproves the intermediate code 4o make the sesulting program easter ost Use less memory. Optimization techniques include constant plding sloop optimization, and magister allo cation. 4) Code generation > Finally, the comptlex generates tosget machine code ox assembly code: fusdm the, optinized. inlowmediate cee This code ts Spectfie “to the target aichitectane and. can be cect excated by the psiocesson Scanned with CamScanner at) tance ase Question Nord 4h Differentiate belween compiler and toranslato- Ans 9 Compiler © A compiler 9s & prog» oa — code writen ina specific prggsammin: language inte me code om Inleimediate code va es Ge plod-form. elt handles entine programs, typically dakfng sovarce code Ailes as input and producing executable files om intermediate nepresentatons that can be -fusther processed 031 executed. 0 The ovlpet of 4 compiler 7s usually. optimized Jor-perfos-| mance and mo clude exeurlable binafes o> imermed~ te code suiidble fos: interpretation om -fustther compilat- fon. om thal Itanslales hight ee baoader term ‘that encompasses Vorfous| doom of faput- Into another sand assemblers © A dota fools oot psragsiams lens, interpae pectfic Loianstates high- level Sovarce carte le code 4 {anslatos can osmals , cuch os {sanslatiog 64 file Josmats, 091 Communication convey Fog one nto rnachine code o>. jrandle different impel and ov gpaervning large can porate on Sm sfiles, data Streams 4 0% messaged. ‘Scanned with CamScanner vie vd 2 The ovtpul of @ 4tanslaios can very wide) depending on Hs pusipose, sranging. orem exewlable code 4o 4uanclated documen|s ox Asansformed data. How taanslaou oe wortks, Poiogaiom tin Ancien longuage Torandetoor \n Summary 4 a compiler fs a type of deionslatos spedfic. ally 4 ilosed fox conventiog high-level sounce code fnto exctutable code, while a ttanslater fs a mone general dexm encompassing vaxtous tyols fox Converting between different siepuesentations on languages ‘Scanned with CamScanner Question No: AF Discuss the difference between ‘Top- dovsn Poser and Bottom-up Parser. Ex fn example fost each, is type of parser Staris Jorem the soot of the parse Loree ond stecunsively epands nodes to match the lnput shing. An example is the Recunsive Desent parser. Consider pesing the afi hmetic expaession 2% (atu), E+E x €1CE) | num The passer begins with the start symbol £ and expands 1 according to the grammer sles unl H mabthes 4he input stsiing | 3% Bottom-up Parisen'> In condncel, ce bottom= up parser Steorls qotom ths tnput stig: and constructs the posse tscet fn a bottom -up mann a oreducing- substsings to non-texmingl Symbols until the short ‘Scanned with CamScanner Symbol: fs seached. An example is the Shift -Reduce poser Posi the same expression 94 3+4),the parser would shift jokensonty: a stack ancl seduce them according to the gotammen srvles ay (3+4) hum » (344) num & Chum +4) um * Cnum + num) E > (aum+ num) €% (£4 nvm) Gx (E+E). Scanned with CamScanner 7 2-20 ew Question No#4 AP Wortle a lextcal analyzer Cscannen) don 0 sienple pragromnits langvoge using siegulan. exparession. Aasr Here's an example of a lexical analyror (scanner) written in Python using s1egulan expressions jose simple language with variables, inkegers, addition, and sublwaction. PeRython code > Fmposit me tokens =C CONT 5 Nd 4D, CévAR?, 9? Ca-28-ZILa-ZN~Z0 -FI-4"); C&ADD?, 9 NF), Césuar,'\?), = deq lex Cinpet ~ hing): tokentzed_tnpul = CJ. chile fnput— shin rote None fon token {ype > pattern tn tokens: stegorc= sie, compile (patio) match = sieger- match Gi 1 Shing) i match: value= match. gooup (0). Jokenized- input. append (oken. -lype valuc)). per eliing= inpul shing len (valued), letip C) . boteak. nel match ytatse ValveFsuio (Invalid input stelum Jokenized~ input pul. shoing) Scanned with CamScanner FE Example usage! codes “x=l0+y-5” paint Clex (coded). Scanned with CamScanner 1 Question Nor 5 FF Expat lexfcal onelyzor generaton- LEX. Also explain Hs capabilities, Ast LEX is a tool “for generating lexical ondyzers (scanner). based on segulos expression. H: Dcos a. desoriptfon of, tokens fn the. denm of mreguians expsessions and comes ponding, actions, and generates ef ficient code C fypfcally. #0 C) fox Fokentzing fnpel. UEx's copabilities include? ° Defining token patteins using stegulan expyessions 6 Generating deleiminisHe fintte automata CDRAS) foo ettcient “tokenizahion © Supporting achons asscdated with token potteis, allowing ee custom postocessing. of tokens, a Scanned with CamScanner gee see eee ey Question No & a ‘Gitve_@ show note on Ce) Ove expressions = Txansibon diagwams Poogpiam unit @ Operations ©) Postfix translation Aus’ 07 Regslan _exparessians + abbreviated os regex o fs o A. siegulan expression, offen Sequence of chaacters Used 4o define a search patton within descl. H's a powerful ool fos pattein matching and text manipulation tasks, consisting of literal chanacters and meta- chonacters with special: meanings. Metachooracters fnclude. chonacter classes like \d fos: ae Zero oH MoHe ocwsvIences, and anchons Gost of a Hine. Regulon expressions ane widely. supported. for pmogptorming. Fanguegess text editors, are! command foals, making them essential fo laske such ae dota. valida Hon. text Search and steplace,and pattein exhauction. While - puovide flexibi tg and elficien of tn teack potocessing sregplen exparessions can be challenging. to stead and writfe| pcspecially- ‘fost complex patterns. However, masteriog oregulae expaessien, ts invaluable fos effective lect processing. tn yootious dom (0) Taaesition A cotancition dfagsam, also known a6 & Aioile-at aviomation, | 1S, quanti hey, fo o grapni on of a slate machine, | 14 conetsts {0 sel of shales, daansition behwcen states , and tae symbol That Astiqger, to Scanned with CamScanner and NS & condition om configusation of the sysk™? = Stansifens frdieate how the gyslem moves qiom OFF I Ke Jo another based on input gyrmbels. Tarangiion shams @x1e commonly used In lexical anolysis ore Poe spate Jo model processes with discrete States and inp’ vol €e Povide a vieual: way to Undatstond. and analyze the behaw' of Jools. io compulo Fite State mad eb, wncking Ahern valvable (ene OwT_] Sdence and engines a A paogptam anil ts a sel{- comlained sectfon ©f code. within a lagen Pega » such as a function, subsovtine om module, Ve encapeviates a sped fic task or nctionaltly. » poromoting Modulan dosign and code -seuse, Pb geen units “help oxganice code, improve s100 1 a = 7 = le maintenance 7 Software development ° © Operations’ Hes a specific dask os action 1), compilation phases 5 Sech as kexfeal analyas » Po py and code. genesiatten, , 7 of, emwIe Code Foto executable 2 pom ohenizing. fopt and '99 iolowmadiole code andl Qenerating | ensuring acc paregnamts, The checking syples to. ¢ jomget machine sue (d) Poslfin 4 'PesHts notoion oa ‘Scanned with CamScanner *everse polish notation (RPN), stepsesends mathematical - Expstessions. where each opercton ellows He operands.For Instance 5 “3+4"? becomes 34 +”, 4 simplifies expression- oe the nod fr parantheces and lent evaluation. algositihms tke: stack- based Scanned with CamScanner

You might also like