0% found this document useful (0 votes)
103 views

Compiler Gold

utu gold compiler

Uploaded by

harsh shivam
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)
103 views

Compiler Gold

utu gold compiler

Uploaded by

harsh shivam
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/ 46
Fe INTRODUCTION TO COMPILING AND LEXICAL ANALYSIS, ‘SYNTAXANALYSISAND SYNTAX DIRECTED TRANSLATION TYPE CHECKING AND RUN TIME ENVIRONMENT CODE GENERATION CODE OPTIMIZATION PREVIOUS YEAR QUESTION PAPERS ‘Q4. Define eompil (UTU 2012, 20 age (target language) and the compiler reports to its user the presence of errors in the source yas of compiler? Debugging or Q3. What are the phases of compiler? (UTU 2012, 2013, 2014, 2015, 2016) Lexical analyzer Fig, Phases of a compiler INTRODUCTION TO COMPILING AND LEXICAL ANALYSIS Symbol table manager. Error Handler. Q.4. Define preprocessor and what are the functions of preprocessor? ‘Ans. Preprocessor produc (Ge) the program wi “They may perform the following functions: (D Macro processing inclusion I preprocessor Language extension’ the analysts-synthesis model of input tothe compilers Ans. ‘program into intermediate representation ofthe source program. ‘The synthesis part constructs the desired target program from the intermediate representation. Q.6. What is front-end and back-end of the compiler? ‘Ans, Often the phases of a compiler are collected {nto a front-end and back-end. Front-end consists ‘of those phases that depend prim program and largely independent of the target machine. Back-end consists of those phases that depend on the target machi generally those port source language, just the intermedi part breaks up the source tuent pieces and creates an symbal table operations. Scanned with CamScanner HET] copter Desen 7. Dene Passes San plementation of compiles, portion creee ne rasesare combined nos module cer pass eas he source pogem oF SUSLEnS ante previous pass, makes the 1 oration pele ty ts phases and writes cure ito ate es whichis read by subsequent pass. ‘source program is read from I ‘grouped into tokens thatare sequence of characters having a collective meaning. Q9. Name minimum 4 compiler construction toa? (Nov/Dee-16) + LEX ~ Scanner generator + YACC-Parser generator ed translation scheme. + Automatic code generator + Dataflow engines the two parts of a compilation? up the source nt pieces and representation of (0.12. Whats meant by lexis ana Ans. It reads the characters in the = (i) Compiler efficiency is improve specialized buffering techniges input chaste and pee tokens and sipicanly specs performance of a cor item 4. Define patternviexeme/tokens? ‘Ans. set of strings inthe input for which the same token is produced as output. This set of strings described by a rule called pattern associated with the token. A lexemeis a sequence of characters ismatched bythe pattern fo ‘Token isa sequence of character that can be treated asa single logical er QS. What are the implem analyzer? Ans. (2) Usea lexical analyzer generator, such 8 Lex compiler, to produce the lexical analyzer from a regular expression based specification, (b) Write the lexical analyzer in onventional systems: language using the UO language to read the input (©) Write the lexical analyzer in assembly language and ex manage the reading of input. tations of lexical tnsyoduction to Compiling and Lenial Ars ive the error recovery strategies in fanguage tran’ interpreter, where sourcecode isassoci foits declaration orappearance inthe souree, such ‘ype scope level and sometimes is leation. xe the models of LEX compiler? dlstanee, forward pointer mi more than the length of buffer. 0.21. What do you mean by Input buffering in i ffering technique is the input scanned, hence buffering tecnigue& ae se ock of datas first read into abuses and then scanned by lenial analyze ‘you mean by analysis and jon of the source structs the desired represen the analysis of source program is analysis consists of three the stream of g upthe source program ight and grouped into re sequences of characters jive meaning. checks ae pet components of @ program fit together ‘meaningfully. sn iyzer scans the input fom eft = fim Iusestwo pointers begin and forward to keep track ofthe pointer of Fig. Alanguage processing system Scanned with CamScanner BET conte dein RSs the process of ut. Explain fn smote = (UTU 2012, 201 M14, 2015, 2016) : out au he onion proses 2 tei (hare ah pes pt om ee steers of Te Hee feds ineuprtote cepa of Sova er Lt unded he pin o ome ‘The first phase of scanner ‘works asa textseanner. This phase sans the source code asa stream of characters and convert it into ‘meaningful lexemes. Lexical analyzer represents these lexemes in the form of tokens a: kena, spn peas tiene (gnats ais pa en cone wechecheagunt tes ‘grammar, Le. ck = Senunirassc eter spatescontned alone tlt Fr uae asigaenreh ee Setvin conalda pet an adi se HA, Soman wae Identifiers, their types and exp ‘whether identifies are declared before we Use ong BAM, mediate Code Gene! analysis the compile removes unnevessary code lines, and arranges hg sequence of statements in order to speed up te program execution without wasting resource, (CPU, mem tuctions of machine code performs the ask =x mediate code would do. input from It uses fwo pointers begin ptitop) and forward ptr fp) to keep track of the pointer ofthe input scanned. nal conigurson troduction o Comping and Lexis Analysis (Ea ‘The forward pir moves 1d of lexeme. As soon as the blank space is bes of lexeme. In above ‘The input cheracter secondary st secondary technique buffer, and then second by lexical analyzer. There are two methods used inthis Scheme, and Two Buffer explained as under: is costly hence buffering ad, A block of data is firs read into rest ofthe lexeme the bufferhaso be refilled, that makes overvriting the first of lexeme. Caer nned buffer and second buffer are sc3 When end of current buffer is reached th isthatif length of the lexeme is lon ofthe buffer then scanning input eannot be seam are pointing the then the fp moves sly end of second buff recognized by the end of buffer mark pre the end of second buffer. When fp encounters fone can recognize end of first 1g up second buffers started. “wo bur scheme storing ‘puting Q.3. Explain how we can create or design Lexical analyzer. (UTU 2018) ‘Ans. There are two ways for designing a lexical Scanned with CamScanner BD] conpiter Design (@ Recognize the tokens by a constructed Finite Automata. Whereas Lexical analyzer programmer will do steps, remaining Bre done by lexical analyzer ge ‘which allows one to specify @ specifying regular expressions to describe patter for tokens. “The input forthe lex program which is written in lex language will lex language. A Compile through lex compiler and produce Code called ley always, Lexsrecteaton te lexyre = texcompier Tiiesealanataer program Now, Ccodeis compiled by C compiler end, produce a file called a.out as always i, aout Tenuate rgram) ‘The C compiler output is a working lexical ‘analyzer that can take a stream of input character and produce a stream of token i.e. Sint Ga} ar ceempier exyye—e} — SS ‘aa ‘The declaration seetion includ lesen st constant (LT, ‘and regular definitions. . bLechg ‘The genera form of transition rte ig patiern{Aetion} where pattem is a regular expression {defines what action should take when with pattern. my ftom no fe can be compiled separately and loaded wi exical analyzer. ‘ie (Q44 State any two reasons a5 to why phase, compiler should be grouped? < ing reduces the complexity process and also when te progans for testing, the tester can easily under 1e phases of compilation through a sagt “The lexical analyzer breaks syns ies of tokens, by removing any while ‘or comments in the source code. 2. Ifthe lexical analyzer finds token inva itgenerates ag error, Itreads character streacrs [tt the source code, checks for legal tokens, ann pas the data othe syntax analyzer when it emsols aye —+[ Came St ~(a7} see ser Fig, Generation of lexical analyzer using lex of Lex Program: A Lex program ir me keywords language, key rs, strings, numbers, P= mum contains the tokens: int (Keyword), value (ide (operator), 100 (constant) and ; (symbol). Lexeme [armel Symbols [Pancication| = Equal_OP ‘Mult oP ‘Comma ¢ Left area Specifications of Tokens: Let us understand ‘now the language theory undertakes the following tems: 1. Alphabets 2. Strings 5. Special symbols 4, Language ‘5, Longest match role valid tokens of a language 9. Finite automata 1. Alphabets: Any finite set of symbols isa set of binary alphabets, ADBCD.EF} isastt language te sequence of alphabets yypical high-level ying symbols ‘A language fs considered a5 ‘over some finite set of analyze jeter by leterand when itencounters a whitespace, operator symbol or special symbols itdecides that ‘a word is completed. 6. Operations: The various operations om languages are 1. Union of so Tanguages Land M is written as, LUM= (s/sisinLorsisin of language L. 4. Notations: [frand sare regular expressions and Ls), then 8. Representing val ofa language in regular expression: If is regular expression then: ‘xt means zero of mre occurrence ofS + xt means one oF more occurtence of X Scanned with CamScanner

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy