0% found this document useful (0 votes)
12 views16 pages

1st Unit CD

Compiler design unit 2

Uploaded by

honeysinghjarwal
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)
12 views16 pages

1st Unit CD

Compiler design unit 2

Uploaded by

honeysinghjarwal
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/ 16
a 1 Balering: Basically, there coome ae is useful when look-whe- necessary to identify tokens, Buffer Pairs : For many sour times when the lexical analyzer 1 can be announced. A specin)i re! been developed oredr he = Yoprocess an input hw Transition Diagrams construction of AS an intermediate a lexical analyzer, we fige flowchart, called a “transition diagram,” actions that take place when a lexical analya i" by the parser to get the next token hal st check each time we move not moved off one half then we must reload the other QI Construct NFA to ‘accept a (a/b) SEE pa of code optimization? ea Ans. Code Optimization Thecoae Starting state Final state attempts to ii Tunning-machine code Total No. of state = improve the intermediate code, so tats Will result a + ©+6+.@ Q2 What do you mean by Preprocessor? Ans, Preprocessor tA ‘Source into modules, Stored fice Zi the Structure on th structure, Lea 6" Mustrate the ‘ranslation of the follt® Statement on all phase of compiler 4: =2FCt IRV, 20189 n take place as described below B*C+ DE Freplain the following terms o Tramstators, Compiters aad taterpreters ere. 00, sonny or Differentiate between compiter and interpreter (R 2003, 2008 200m (1) Bootstrapping (RT, 2074, 2002, 2000, 00m ———SEEs Ans(i) Difference Between Tram jetween Translator, © a and Interpreter nee Translator: A translator is « program that takes input as a program written in one programming language and converts it in output program of other programming, language. Compiler : Compilers are the translators whieh translate a program written in high level language likeC*, FORTRAN, COBOL, PASCAL into machine code for ae: architecture. The generated code can be ‘many times against different data each time. t= beam Objet Poem ae so in this sense compiler, compile the whole program: at atime. Interpreter : An interpreter reads an soot tten in high level pro: for this program and against the data to produce some results. Go we can say that interpreter compiles the — program line to Vine and an interpreter is generally Than a compiler because it processes and inert cach, statement in a program as many times as the number the evaluation of this statement, + Difference between ed Tis output 0 form of Beas ves ‘more amount of [Toca i) Bootstrapping + A ful o of software, rather si reat 3 and soon, that Is Sul ASSEMBLER nblor for subset | of ‘de, perhaps on a lond-and jin ASSEMBLER and ther very little other than convert One might then write nary form ‘of ASSEMBLER in subset 1 of a by which a simple mplicated program, more complicated “bootstrapping”, b (eee computing, bootstrapping (from an old expression Jfup by one's bootstraps”) is a technique by Giies Fig. ott en CRORE Sy Ain tree is usually the result dak of propams. inthe Wartup process .| Phase off compiled. cfieet ae oe feconps.s-gstem, @ small program (such as BIOS) | Tepresentation of the program aan ‘etalon andes theta basic requirement of hardware, | the compiler requires, and has a strong ji esieeneralmenoy devi ae comeced) | fal ouput of the compiler t ttielaase rogram from on of them and passes control The following thing i Sento losding of larger programs suchas | designing a tree for iy pee toes a set oem), diferent use of the term (a) Variables types must be oe pee compiler to compile itself, by first location of each di laration is = put of compiler of a new programmin, (b)’ The order of ect Somes sng nguageacompile more pro 1g order of executable aodere onthe 06 language, This usality dilemma, be stored and Ocean @ Identifiers and cee 3 for assignment statemente woes! A, Astate sy that is distin S. Asetofatstes ¢'= aity t sates. owing the edge Inbeted ‘nd 3 vin ede lla ‘MS, an be represented by © seque transitions called moves. The following deat tf the moves made in accepting the input striag aa c 0 9-8) _byy by . se In general, more than one sequence op Constrection of NFA recognizes th a fom Nr Myesetof states | lend to an accepting state. Notice ther 20% Fae need is shown in fig. Several s s may be made on the take are of input buffering: PR" hes back input characters By calling the OW ~ tad ungete, respectively. With ¢ a “tthe pair of statements hase <= getchar() = ungete Costin) Wt he stented input tain In Pascal, the snsneiation deolarat wanes ation; in C, NUM ean npr fr using define-satement, "ae stand foe 286 fHdetine NUM 256 The function texan lexan returns NUM when a sequence of digits is seen in the input sath abe be oe ae lowed imme en assigned the anid iC —— Allowing numbers change nthe granmarin Fig We ele ou a digits by the non-terminal factor and introduce the following productions and semantic actions : factor > ( expr ) | num { print (aum.value) }{ ‘The C code for factor in Fig, isa direct implementation of the productions above. ‘When lookahead equals NUM, the value of attribute num.value is given by the global variable tokenval. The action of printing this value isdone by the standard library function ‘printf. The first argument of printf is a string, ‘between double quotes specifying th= format to be used for printing the remaining ‘Where Yd appears inthe string, the decimal represen of the next argument is printed. Thus, the printf statement jn code given below printsa blank followed by the decal representation of tokenval followed by another blank. The Crrode for factor when operands can be numbers i= factor( ) if (lookahead =="(°) 4 Paw ie Coreen (veer sa } we tse if (lookahead == NUM) (NUM: else if ( id patel printf * 5 else error () + ea | Seo | @eeo | i Ge 0 @ad Ge Gu ead Gu ee D Geo Gee Ww analyzer generator. sack st the Lex Compiler to produce the lexical analyser Sen ssi expression based specification. I this came ame Eenerator provides routines for reading and baterng the input. ‘Write the lexical analyzer in conventions systems: programming language. sing the VO facilites of ta language to read the input Write the lexical analyzer in assembly language sn ‘explicitly manage the reading of mpet The three choices are listed im onder to increasing difficulty for the implementor. Unifornanately the harder to implement approaches often . Since the lexical analyzer shown in Snone disk DICK,

You might also like