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

Compiler Design Last Min

computer science notes
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)
319 views

Compiler Design Last Min

computer science notes
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/ 8
sinsi2024 Last Minute Notes - Compiler Design -GeeksforGeeks ADS BY ADRECOVER. Last Minute Notes - Compiler Design Last Updated : 28 Jun, 2021 See Last Minute Notes on all subjects here Phases of Compiler hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! ve sinsi2024 Last Minute Notes - Compiler Design -GeeksforGeeks Hah ort ‘Symbol Table : It is a data structure being used and maintained by the compiler, consists all the identifier's name along with their types. It helps the compiler to function smoothly by finding the iden- tifiers quickly. 1, Lexical Analysis : Lexical analyzer reads a source program character by character to produce tokens. Tokens can be identifiers, keywords, operators, separators etc. 2. Syntax Analysis : Syntax analyzer is also known as parser. It constructs the parse tree. It takes all the tokens one by one and uses Context Free Grammar to construct the parse tree. 3. Semantic Analyzer : It verifies the parse tree, whether it’s meaningful or not. It furthermore produces a verified parse tree. 4, Intermediate Code Generator : It generates intermediate code, that is a form which can be readily executed by machine We have many popular intermediate codes. Data Structures Algorithms Interview Preparation Topic-wise Practice C++ Java Python C Error handling The tasks of the Error Handling process are to detect each error, reportit to the user, and then make some recover strategy and implement them to handle error. An Errors the blank entries in the symbol table. There are two types of error Run-Time Error : A run-time error is an error which takes place during the execution of a program, and usually happens because of adverse system parameters or invalid input data apile-Time Error: Compile-time errors rises at compile time, before execution of the program 1, Lexical :This includes misspellings of identifiers, keywords or operators 2. Syntactical :missing semicolon or unbalan| 4 brenthesis. hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! 28 1162021 Last Minute Notes ~ Compr Design - GeekstorGeeks 3. Semantical :incompatible value assignment or type mismatches between operator and ‘operand 4. Logical :code not reachable, infinite loop Left Recursion: The grammar: A-> Aa | ais left recursive. Top down parsing techniques cannot han- dle left recursive grammar so we convert left recursion into right recursion. Left recursion elimination : A-> Aa | a> A-> aA’ A->aN' la Left Factoring : If a grammar has common prefixes in r.h.s of nonterminal then suh grammar needs to be left factored by eliminating common prefixes as follows A->abl | ac2=A->A-> al’ A->A->b1 | c2 FIRST(A) is a set of the terminal symbols which occur as first symbols in string derived from A FOLLOW(A) is the set of terminals which occur immediately after the nonterminalA in the strings de- rived from the starting symbol. hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! sinsi2024 Last Minute Notes - Compiler Design -GeeksforGeeks LL(1) Parser: LL(1) grammar is unambiguous, left factored and non left recursive. To check whether a grammar is LL(1) or not 1.1fA-> B1 | C2 = ( FIRST(B1) M FIRST(C2)=@) 2.1FA->B | €= { FIRST(B) 1 FOLLOW(A) = 9} LR(0) Parser : Closure() and goto() functions are used to create canonical collection of LR items. Conflicts in LR(0) parser 1. Shift Reduce (SR) conflict : when the same state in DFA contains both shift and reduce items. A-> B xC (shifting) B -> a. (reduced) 2. Reduced Reduced (RR) conflict : two reductions in same state of DFAA -> a. (reduced) B->b (reduced) Parser : Itis powerful than LR(0) Ever LR(0) is SLR but every SLR need nat be LR(t* a hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! 40 sinsi2024 Last Minute Notes - Compiler Design -GeeksforGeeks Conflicts in SLR 1. SR conflict : A -> B .xC (shifting) B -> a. (reduced) if FOLLOW(B) N {x} #@ 2. RR conflict: A -> a. (reduced) B ->b. (reduced) if FOLLOW(A) M FOLLOW(B) #@ CLR Parser: It is same as SLR parser except that the reduced entries in CLR parsing table go only in the FOLLOW of the L_h.s nonterminal. LALR Parser :Itis constructed from CLR parser, if two states having same productions but may contain different lookaheads, those two states of CLR are combined into single state in LALR. Every LALR grammaris CLR but every CLR grammar need not be LALR Parsers Compariso LR(0) CSLRCLALRCCLR LL(1) CLALRE CLR Ifnumber of states LR(0) = n1, number of states SLR =n2, number of states LALR = n3, number of = nd then, nl =n2=n3 <= nd states CLI hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! sinsi2024 Last Minute Notes - Compiler Design -GeeksforGeeks ‘Syntax Directed Translation: Syntax Directed Translation are augmented rules to the grammar that facilitate semantic analysis Eg - S->AB {print (*)} A->a{print (1)} B->b (print (2)} Synthesized Attribute : attribute whose value is evaluated in terms of attribute values of its children. Inherited Attribute : attribute whose value is evaluated in terms of attribute values of siblings or parents. S-attributed SDT: If an SDT uses only synthesized attributes, it is called as S-attributed SDT. S-attrib- uted SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the val- ues of the child nodes. L-attributed SDT: If an SDT uses either synthesized attributes or inherited attributes with a restriction that it can inherit values from left siblings only, itis called as L-attributed SDT, Attributes in L-attrib- uted SDTs are evaluated by depth-first and left-to-right parsing manner. Activation Record : Information needed by a single execution of a procedure is managed using a con tiguous block of storage called activation record. An activation record is allocated when a procedure is entered and it is deallocated when that procedure is exited. Interme te Code : They are machine independent codes. Syntax trees, postfix notation, 3-address codes can be used to represent intermediate code. Three address code: uadruples (4 fields : operator, operand1, operand2, result) -riplets (3 fields : operator, operand1, operand2) 3. Indirect triples a hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! sinsi2024 Last Minute Notes - Compiler Design -GeeksforGeeks Code Optimization : Types of machine independent optimizations - 1. Loop optimizations * Code motion : reduce the evaluation frequency of expression. * Loop unroiling : to execute less number of iterations + Loop jamming : combine body of two loops whenever they are sharing same index. 2. Constant folding : replacing the value of constants during compilation 3. Constant propagation : replacing the value of an expression during compile time. 4, Strength reduction : replacing costly operators by simple operators. Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here. ADVERTISEMENT BY ADRECOVER OG Sth Floor, A-118) Sector-136, Noi) 4 Jar Pradesh - 201305 hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! 718 sinsi2024 Last Minute Notes - Compiler Design -GeeksforGeeks [email protected] Company About Us Careers Privacy Policy Contact Us Copyright Policy Practice Courses Company-wise Topic-wise How to begin? Learn Algorithms Data Structures Languages CS Subjects Video Tutorials Contribute Write an Article Write Interview Experience Internships Videos @geeksforgeeks , Some rights reserved hitpsswww.geckstorgoeks.orglast- minute notes-compllr-dosign-9q! oy

You might also like