Download Compiler Design power point presentations and more Exams Compiler Design in PDF only on Docsity!
TULSIRAMJI GAIKWAD-PATIL
College of Engineering & Technology
Department of Computer Science and Engineering Session 2016- Subjects Undertaken
1. Language processor (LP) -----
th
sem (CSE)
Prof.Rajesh Babu.G
Asst. Professor
LP^ Dept. of Computer Science & Engineering Prof.G.Rajesh Babu^ 1
Language Processors (LP)
(^) UNIT I ------------ Introduction of compilers (^) UNIT II ------------ Syntax analysis (^) UNIT III ------------ syntax directed translation (^) UNIT IV------------ Table Management & Error detection and recovery (^) UNIT V------------- code optimization (^) UNIT VI------------ code generation
UNIT Topics No. of Questions covered in University Exam Marks covered in University Exam III Syntax directed definitions, implementation of SDTS, Intermediate code representations (postfix, syntax tree, TAC), Intermediate code generation using syntax directed translation schemes for translation of controls structures, declarations, procedure calls, and Array reference.
IV
Table Management: Storage allocation and run time storage administration, symbol table management. Error detection and recovery: Error recovery in LR parsing, Error recovery in LL parsing, automatic error recovery in YACC.
V
Code optimization: Sources of optimization, loop optimization, control flow analysis, data flow analysis, setting up data flow equations to compute reaching definitions, available expressions, Live variables, Induction Variable, Common sub expression elimination.
VI
Code generation: Problems in code generation, Simple code generator, Register allocation and assignment, Code generation from DAG, Peephole optimization.
List of Books available in Library:
Sr. No. Title Author Publisher Edition
Compilers: principles techniques and tools Ullman , Setgi , A.V.Aho Pearson education 2 rd^ ,3rd
- Principles of compiler design Alfred V.Aho & Jeffery D.Ullman Narosa pub House 3 rd
- Principles of compiler design A. M. Tenenbaum PHI Publications 4 th,^5 th
- Compiler Design O. G. Kakde Laxmi Publications 2009
- (^) What is a compiler?
- (^) A program that reads a program written in one language (source language) and translates it into an equivalent program in another language (target language). - (^) Two components - (^) Understand the program (make sure it is correct) - (^) Rewrite the program in the target language.
- (^) Traditionally, the source language is a high level language and the target language is a low level language (machine code).
- (^) Example: C, C++, C#, Java compiler Source program Target program Error message
Features of Compiler
• After executing program, the first task of
compiler is to create .obj file and then .exe
file.
• Compiler manages the storage of code and
variable.
• Compiler is responsible for correctness of
code and highlights the errors.
• Compiler is more intelligent
Assembler The Assembler is used to translate the program written in Assembly language into machine code. The source program is a input of assembler that contains assembly language instructions. The output generated by assembler is the object code or machine code understandable by the computer. Interpreter The translation of single statement of source program into machine code is done by language processor and executes it immediately before moving on to the next line is called an interpreter.
- (^) If there is an error in the statement, the interpreter terminates its translating process at that statement and displays an error message.
- (^) The interpreter moves on to the next line for execution only after removal of the error.
- (^) An Interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code. Example: Perl, Python and Matlab.
Scanner: Lexical Analysis
- (^) Lexical analysis breaks up a program into tokens
- (^) Grouping characters into non-separatable units (tokens)
- (^) Changing a stream to characters to a stream of tokens program gcd (input, output); var i, j : integer ; begin read (i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln (i) end. program gcd ( input , output ) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i - j else j := i - i ; writeln ( i ) end.
- (^) What kind of errors can be reported by lexical analyzer? A = b + @3; Syntax Analysis
- (^) Checks whether the token stream meets the grammatical specification of the language and generates the syntax tree. - A syntax error is produced by the compiler when the program does not meet the grammatical specification. - For grammatically correct program, this phase generates an internal representation that is easy to manipulate in later phases - (^) Typically a syntax tree (also called a parse tree).
- (^) A grammar of a programming language is typically described by a context free grammer, which also defines the structure of the parse tree is
Code Generation and Intermediate
Code Forms
- (^) A typical intermediate form of code produced by the semantic analyzer is an abstract syntax tree (AST)
- (^) The AST is annotated with useful information such as pointers to the symbol table entry of identifiers Example AST for the gcd program in Pascal
Code Generation and Intermediate
Code Forms
- (^) Other intermediate code forms
- (^) intermediate code is something that is both close to the final machine code and easy to manipulate (for optimization). One example is the three-address code: dst = op1 op op
- (^) The three-address code for the assignment statement: temp1 = 60 temp2 = id3 + temp temp3 = id2 + temp id1 = temp
- (^) Machine-independent Intermediate code improvement temp1 = id3 * 60. id1 = id2 + temp
Summary
• Compiler front-end: lexical analysis, syntax
analysis, semantic analysis
– Tasks: understanding the source code, making
sure the source code is written correctly
• Compiler back-end: Intermediate code
generation/improvement, and Machine code
generation/improvement
– Tasks: translating the program to a semantically
the same program (in a different language).
UNIT II Syntax analysis