Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization
|
|
- Osborne King
- 5 years ago
- Views:
Transcription
1 Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization Prof. Jonita Roman Date: 30/06/2018 Time: 9:45 to 10:45 Venue: MCA Ground Floor Class Room
2 Presentation Outline Introduction From Definition to Code Need for Code Optimization Schematic diagram Code Optimization at Compiler Level Code Optimization from Developer s end Few optimization techniques Examples Other references
3 Introduction Code optimization aims at improving the execution efficiency of a program. This can be achieved by: Eliminating redundancies from the code Rearranging or rewriting the computations in a program to make it execute efficiently.
4 What is an Algorithm? An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem, based on conducting a sequence of specified actions. A computer program is nothing by an elaborate algorithm. In computer science, an algorithm usually means a small procedure that solves a problem.
5 Properties of Algorithm (Donald Knuth) An algorithm must possess the following properties: 1. Finiteness: The algorithm must always terminate after a finite number of steps. 2. Definiteness: Each step must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case. 3. Input: An algorithm has zero or more inputs, taken from a specified set of objects. 4. Output: An algorithm has one or more outputs, which have a specified relation to the inputs. 5. Effectiveness: All operations to be performed must be sufficiently basic that they can be done exactly and in finite length.
6 Parameters Measuring Performance How can we talk precisely about the "cost" of running an algorithm? What do you understand by the term "cost"? Time? (Execution speed) Space? (Memory usage and its management) Both? (Speed and Space) Something else? (Other than this! Parallelism using Multi process/thread)
7 Program??? A computer program is a list of instructions that tell a computer what to do. Everything a computer does is done by using a computer program. A computer program is written in a programming language [Wikipedia]. Some examples are: Finding factorial of a given number Sorting a given array of elements Operating system Web Browsers Office suite (documents/spreadsheets etc) Video games Malwares...
8 Preprocessor Compiler Assembler Source Program Target Assembly Program Relocatable Machine Code Loader/Linker Library, Relocatable object files Absolute Machine Code A journey of an HLL to executable
9 THE PHASES OF A COMPILER Source Program Lexical Analyzer Syntax Analyzer Symbol-table manager Semantic Analyzer IC Generator Error handler Code Optimizer Code Generator Target Program
10 EXECUTION OF SOURCE PROGRAM The execution of a program is divided into two main phases: Analysis phase and Synthesis phase: Analysis phase 1. Linear analysis (Lexical analysis) 2. Hierarchical analysis (Syntax Analysis) 3. Semantic analysis Synthesis phase 1. Creation of Data Structures (Table of contents) 2. Code Generation For eg: position := initial + rate * 60 Would be grouped into the following tokens :
11 Expression tree generation for position := initial + rate * 60.0 assignment statement identifier : = expression position expression + expression identifier expression * expression initial identifier number rate 60
12 In the expression initial + rate * 60, the phrase rate * 60 is a logical unit because the usual conventions of arithmetic expressions tell us that multiplication is performed before addition. Because the expression initial + rate is followed by a *, it is not grouped into a single phrase by itself in the above parse tree. The hierarchical structure of a program is usually expressed by recursive rules. For example, we might have the following rules as part of the definition of expressions : 1. Any identifier is an expression. 2. Any number is an expression. 3. If expression 1 and expression 2 are expressions, then so are expression 1 + expression 2 expression 1 * expression 2 ( expression 1 )
13 Rules (1) and (2) are (non recursive) basic rules, while (3) defines expressions in terms of operators applied to other expressions. Thus, by rule (1), initial and rate are expressions. By rule 2, 60 is an expression, while by rule 3, rate * 60 is an expression and finally that initial + rate * 60 is an expression. Many languages define statements recursively by rules such as: If identifier 1 is an identifier, and expression 2 is an expression, then identifier 1 := expression 2 is a statement. If expression1 is an expression and statement2 is a statement, then while ( expression 1 ) do statement 2 if ( expression 1 ) then statement 2 are statements.
14 Lexical constructs do not require recursion, while syntactic constructs do. Context free grammars are a formalization of recursive rules that can be used to guide syntactic analysis. On the other hand, this kind of linear scan is not powerful enough to analyze expressions or statements. For example, we cannot properly match parenthesis in expressions, or begin and end statements, without putting some kind of hierarchical or nesting structure on the input. For example, recursion is not required to identify identifiers, which are typically strings of letters and digits beginning with a letter. We would normally recognize identifiers by a simple scan of the input stream, waiting until a character that was neither a letter nor a digit was found, and then grouping all the letters and digits found up to that point into an identifier token. The characters so grouped are recorded in a table, called a symbol table, and removed from the input so that processing of next token can begin.
15 The parse tree of the figure 1.3 describes the syntactic structure of the input. A more common internal representation of this syntactic structure is given by the syntax tree in the figure 1.4(A). A syntax tree is a compressed representation of the parse tree in which the operators appear as the interior nodes, and the operands of an operator are the children of the node for that operator. := position + initial * rate 60
16 position := + initial * rate inttoreal 60 Semantic analysis: The semantic analysis phase checks the source program for semantic errors and gathers the type information for the subsequent code-generation phase. It uses the hierarchical structure determined by the syntax-analysis phase to identify the operators and operands of expressions and statements.
17 An important component of semantic analysis is type checking. Here the compiler checks that each operator has operands that are permitted by the source language specification. For example, when a binary arithmetic operator is applied to an integer and real. In this case, the compiler may need to convert the integer to real. Suppose, for example, that all identifiers in the above figure have been declared to be real and that 60 by itself is assumed to be an integer. Type checking of above figure reveals that * is applied to real, rate, and an integer, 60. This has been achieved in the next figure by creating an extra node for the operator inttoreal that explicitly converts an integer into a real.
18 Symbol Table Management An essential function of a compiler is to record the identifiers used in the source program and collect information about various attributes of each identifier. These attributes may provide information about the storage allocated for an identifier, its type, its scope (where in the program it is valid), and, in the case of procedure names, such things as the number and types of its arguments, the method of passing each argument (e.g., by reference), and the type returned, if any. A symbol table is a data structure containing a record for each identifier, with fields for the attributes of the identifier. The data structure allows us to find the record for each identifier quickly and to store or retrieve data from that record quickly.
19 Error Detection and Reporting Each phase can encounter errors. However after detecting error, a phase must somehow deal with that error, so that compilation can proceed, allowing further errors in the source program to be detected. The syntax and semantic analysis phases usually handle a large fraction of the errors detectable by the compiler. The lexical phase can detect errors where the characters remaining in the input do not form any token of the language. Errors where the token stream violates the structure rules (syntax) of the language are determined by the syntax analysis phase. During semantic analysis the compiler tries to detect constructs that have the right syntactic structure but no meaning to the operation involved.
20 The Analysis Phases As translation progresses, the compiler s internal representation of the source program changes. We illustrate these representations by considering the translation of the statement position := initial + rate * 60 The lexical analysis phase reads the characters in the source program and groups them into a stream of tokens in which each token represents a logically cohesive sequence of characters, such as an identifier, a keyword ( if, while ), a punctuation character, or a multi-character operator like :=. The character sequence forming a token is called the lexeme for the token. When an identifier like rate is found, the lexical analyzer not only generates a token, say id, but also enters the lexeme rate into the symbol table, if it is not already there. Here, we will use id 1, id 2, id 3 for position, initial and rate to emphasize that internal representation of an identifier is different from the character sequence forming the identifier. The representation of above statement after lexical analysis is therefore
21 suggested by: id 1 := id 2 + id 3 *60 We would also make up tokens for the multi-character operator := and the number 60 to reflect their internal representation. The second and third phases, syntax and semantic analysis, have also been introduced in the previous section.
22 Intermediate Code Generation After syntax and semantic analysis, some compilers generate an explicit intermediate representation of the source program. We can think of this intermediate representation as a program for an abstract machine. This intermediate representation should have two important properties. It should be easy to produce, and easy to translate into the target program. We consider an intermediate form called three-address code which is like the assembly language for a machine in which every memory location can act like a register. Three-address code consists of a sequence of instructions, each of which has at most three operands. The source program position := initial + rate * 60 might appear in three-address code as
23 temp1 := inttoreal(60) temp2 := id3 * temp1 temp3 := id2 + temp2 id1 := temp3 Code optimization The code optimization phase attempts to improve the intermediate code, so that faster-running machine code will result. For example, the above code, after optimization, may be as temp1 := id3 * 60.0 id1 := id2 + temp1
24 CODE OPTIMIZATION: (Revisited) Code optimization aims at improving the execution efficiency of a program. This is achieved in two ways: 1.Redundancies in a program are eliminated. 2.Computations in a program are rearranged or rewritten to make it execute efficiently. Unoptimized Code Code Optimization Through optimization techniques Optimized Code
25 Two points concern the scope of optimization. The optimization techniques are thus independent of both the PL and the target machine. 1. Optimization seeks to improve a program rather than the algorithm used in a program. Thus replacement of an algorithm by a more efficient algorithm us beyond the scope of optimization. 2. Efficient code generation for a specific target machine is also beyond its scope; it belongs in the back end of a compiler.
26 Optimizing Transformations: An optimizing transformation is a rule for rewriting a segment of a program to improve its execution efficiency without affecting its meaning. Optimizing transformations are classified into local and global transformations depending on whether they are applied over small segments of a program consisting of a few source statements, or over larger segments consisting of loops or function bodies. 1.Compile time evaluation: Execution efficiency can be improved by performing certain actions specified in a program during compilation itself. For ex: a := / 2 can be replaced by a := thereby eliminating a division operation.
27 Elimination of common sub expression: Common sub expressions are occurrences of expressions yielding the same value. They are also called equivalent expressions. For ex: t := b * c; a := b * c a := t; x := b * c + 5.2; a := t + 5.2; Here CS contains the two occurrences of b * c. The second occurrence of b * c can be eliminated because the first occurrence of b * c is always evaluated before the second occurrence is reached during execution of the program. The value computed at the first occurrence is saved in t. This value is used in the assignment of x.
28 Dead code elimination: Code which can be omitted from a program without affecting its results is called dead code. Dead code is detected by checking whether the value assigned in an assignment statement is used anywhere in the program. For ex: An assignment x := <expr> constitutes dead code if the value assigned to x is not used in the program. Frequency reduction: Execution time of a program can be reduced by moving code from a part of a program which is executed very frequently to another part of the program which is executed fewer times. For example, the transformation of loop optimization moves loop invariant code out of a loop and places it prior to loop entry.
29 For example: x := 25 * a; for i := 1 to 100 do for i := 1 to 100 do begin begin z := i; z := i; x := 25 * a; y := x + z; y := x + z; end; end; Here x := 25 * a; is loop invariant. Hence in the optimized program it is computed only once before entering the for loop. y := x + z; is not loop invariant. Hence it cannot be subjected to frequency reduction.
30 Strength reduction: The strength reduction optimization replaces the occurrence of a time consuming operation (a high strength operation) be an occurrence of a faster operation (a low strength operation), e g. replacement of a multiplication by an addition. itemp := 5; for i := 1 to 10 do for i := 1 to 10 do begin begin k := i * 5; k := itemp; itemp := itemp + 5; end; end;
31 Local and global optimization: Optimization of a program is structured into the following two phases: 1. Local optimization: The optimizing transformations are applied over small segments of a program consisting of a few statements. 2. Global optimization: The optimizing transformations are applied over a program unit, i.e. over a function or a procedure.
32 Local Optimization Basic block: A basic block is a sequence of program statements (s 1, s 2,, s n ) such that only s n can be a transfer of control statement and only s 1 can be the destination of a transfer of control statement. A basic block b is a program segment with a single entry point. If control reaches statement s 1 during program execution, then all the statements s 1, s 2,. s n will be executed. The essentially sequential nature of a basic block simplifies optimization.
33 Example: t := x*y; a := x*y; a := t; b := x*y; b := t; lab i : c := x*y; lab i : c := x*y; Local optimization is done for the statement x*y. This is done for the first two statements in the block and not for the last statement since it belongs to other block. If the label lab i : did not exist then we could replace the value of c := x*y, because then it would constitute the same block.
34 Value numbers Value numbers provide a simple means to determine if two occurrences of an expression in a basic block are equivalent. The value numbering technique is applied on the fly while identifying basic blocks in a source program. A value number vn alpha is associated with variable alpha. It identifies the last assignment to alpha processed so far. stmt no. Statement 14 g := 25.2; 15 x := z+2; 16 h := x*y+d; 34 w := x*y;
35 Local optimization using value numbering: Symbol table Symbol.. Value number y 0 x 15 g 14 z 0 d 5 w 0
36 Quadruples table Operator Operand1 Operand 2 Oper and Value no. Opera nd Valu e no. Result name 20 := g t 20 f 21 + z t 21 f 22 := x 0 t21 - t 22 f 23 * x 15 y 0 T 23 f t 24 + t 23 - d 5 T 24 f.. 57 := w 0 t 23 - t 57 f Use flag
37 Global Optimization Compared to local optimization, global optimizations requires more analysis effort to establish the feasibility of an optimization. Consider global common subexpression elimination. If some expression x*y occurs in set of basic blocks SB of program P, its occurrence in a block b j SB can be eliminated if the following two conditions are satisfied for every execution of P: 1. Basic block b j is executed only after some block b k SB has been executed one or more times. 2. No assignments to x or y have been executed after the last (or only) evaluation of x*y in block b k. (**)
38 Program Representation: A program is represented in the form of a program flow graph. Definition: A program flow graph for a program P is a directed graph Gp = (N, E, n o ) where N: set of basic blocks in P E: set of directed edges (b i,b j ) indicating the possibility of control flow from the last statement of b i (the source node) to the first statement of b j (the destination node) n o : start node of P.
39 Control and Data flow analysis Control flow analysis analyses a program to collect information concerning its structure, e.g. presence and nesting of loops in the program. Information concerning program structure is used to answer specific questions of interest (**). The control flow concepts of interest are: 1. Predecessors and successors: If (b i,b j ) E, b i is a predecessor of b j and b j is a successor of b i. 2. Paths: A path is a sequence of edges such that the destination node of one edge is the source node of the following edge. 3. Ancestors and descendants: If a path exists from b i to b j, b i is an ancestor of b j and b j is a descendant of b i. 4. Dominators and post-dominators: Block b i is a dominator of block b j if every path from n o to b j passes through b i. b i is a post-dominator of b j if every path from b j to an exit node passes through b i.
40 Global Optimization Program Representation: Control and Data flow analysis Control flow analysis Data flow analysis Data flow concept Available expression Live variable Reaching definition Optimization in which used Common sub-expression elimination Dead code elimination Constant and variable propagation
41 Build a program flow graph for the following program z := 5; w := z; for i := 1 to 100 do x := a*b; y := c+d; if y < 0 then a := 25; f := c+d; else g := w; h := a*b+f; d := z+10; end; g: := c+d; print g,h,d,x,y;
42 Thank You
PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING
PRINCIPLES OF COMPILER DESIGN 2 MARKS UNIT I INTRODUCTION TO COMPILING 1. Define compiler? A compiler is a program that reads a program written in one language (source language) and translates it into
More informationPRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS
Objective PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS Explain what is meant by compiler. Explain how the compiler works. Describe various analysis of the source program. Describe the
More informationCOMPILER DESIGN. For COMPUTER SCIENCE
COMPILER DESIGN For COMPUTER SCIENCE . COMPILER DESIGN SYLLABUS Lexical analysis, parsing, syntax-directed translation. Runtime environments. Intermediate code generation. ANALYSIS OF GATE PAPERS Exam
More informationA Simple Syntax-Directed Translator
Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called
More informationUNIT I INTRODUCTION TO COMPILER 1. What is a Complier? A Complier is a program that reads a program written in one language-the source language-and translates it in to an equivalent program in another
More informationCOMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]
More information2.2 Syntax Definition
42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions
More informationCompiler Design. Computer Science & Information Technology (CS) Rank under AIR 100
GATE- 2016-17 Postal Correspondence 1 Compiler Design Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,
More informationCOMPILER DESIGN LECTURE NOTES
COMPILER DESIGN LECTURE NOTES UNIT -1 1.1 OVERVIEW OF LANGUAGE PROCESSING SYSTEM 1.2 Preprocessor A preprocessor produce input to compilers. They may perform the following functions. 1. Macro processing:
More informationCompiler Design (40-414)
Compiler Design (40-414) Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007 Evaluation: Midterm Exam 35% Final Exam 35% Assignments and Quizzes 10% Project
More informationFormal Languages and Compilers Lecture I: Introduction to Compilers
Formal Languages and Compilers Lecture I: Introduction to Compilers Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/
More informationThe analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.
COMPILER DESIGN 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the target
More informationCompiler Code Generation COMP360
Compiler Code Generation COMP360 Students who acquire large debts putting themselves through school are unlikely to think about changing society. When you trap people in a system of debt, they can t afford
More informationfor (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }
Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas
More informationStructure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.
More detailed overview of compiler front end Structure of a compiler Today we ll take a quick look at typical parts of a compiler. This is to give a feeling for the overall structure. source program lexical
More informationVIVA QUESTIONS WITH ANSWERS
VIVA QUESTIONS WITH ANSWERS 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the
More informationCOMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Next time reading assignment [ALSU07] Chapters 1,2 [ALSU07] Sections 1.1-1.5 (cover in class) [ALSU07] Section 1.6 (read on your
More informationAbout the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design
i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target
More informationCompiler, Assembler, and Linker
Compiler, Assembler, and Linker Minsoo Ryu Department of Computer Science and Engineering Hanyang University msryu@hanyang.ac.kr What is a Compilation? Preprocessor Compiler Assembler Linker Loader Contents
More informationLANGUAGE PROCESSORS. Presented By: Prof. S.J. Soni, SPCE Visnagar.
LANGUAGE PROCESSORS Presented By: Prof. S.J. Soni, SPCE Visnagar. Introduction Language Processing activities arise due to the differences between the manner in which a software designer describes the
More informationSEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A
SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A 1. What is a compiler? (A.U Nov/Dec 2007) A compiler is a program that reads a program written in one language
More informationCD Assignment I. 1. Explain the various phases of the compiler with a simple example.
CD Assignment I 1. Explain the various phases of the compiler with a simple example. The compilation process is a sequence of various phases. Each phase takes input from the previous, and passes the output
More informationCompiler Design Overview. Compiler Design 1
Compiler Design Overview Compiler Design 1 Preliminaries Required Basic knowledge of programming languages. Basic knowledge of FSA and CFG. Knowledge of a high programming language for the programming
More informationLECTURE NOTES ON COMPILER DESIGN P a g e 2
LECTURE NOTES ON COMPILER DESIGN P a g e 1 (PCCS4305) COMPILER DESIGN KISHORE KUMAR SAHU SR. LECTURER, DEPARTMENT OF INFORMATION TECHNOLOGY ROLAND INSTITUTE OF TECHNOLOGY, BERHAMPUR LECTURE NOTES ON COMPILER
More informationfor (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }
Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas
More informationUNIT -1 1.1 OVERVIEW OF LANGUAGE PROCESSING SYSTEM 1.2 Preprocessor A preprocessor produce input to compilers. They may perform the following functions. 1. Macro processing: A preprocessor may allow a
More informationCompilers. Prerequisites
Compilers Prerequisites Data structures & algorithms Linked lists, dictionaries, trees, hash tables Formal languages & automata Regular expressions, finite automata, context-free grammars Machine organization
More informationReverse Engineering Techniques
VISVESVARAYA TECHNOLOGICAL UNIVERSITY S.D.M COLLEGE OF ENGINEERING AND TECHNOLOGY A seminar report on Reverse Engineering Techniques Submitted by SACHIN SABOJI 2sd06cs079 8 th semester DEPARTMENT OF COMPUTER
More informationCOMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table
COMPILER CONSTRUCTION Lab 2 Symbol table LABS Lab 3 LR parsing and abstract syntax tree construction using ''bison' Lab 4 Semantic analysis (type checking) PHASES OF A COMPILER Source Program Lab 2 Symtab
More informationPRINCIPLES OF COMPILER DESIGN
PRINCIPLES OF COMPILER DESIGN 2 MARK QUESTIONS WITH ANSWERS UNIT I 1. What is a Complier? A Complier is a program that reads a program written in one language-the source language-and translates it in to
More informationThis book is licensed under a Creative Commons Attribution 3.0 License
6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars
More information4. An interpreter is a program that
1. In an aboslute loading scheme, which loader function is accomplished by programmer? A. Allocation B. LInking C. Reallocation D. both (A) and (B) 2. A compiler program written in a high level language
More informationPrinciple of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore
Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments
More informationQUESTION BANK CHAPTER 1 : OVERVIEW OF SYSTEM SOFTWARE. CHAPTER 2: Overview of Language Processors. CHAPTER 3: Assemblers
QUESTION BANK CHAPTER 1 : OVERVIEW OF SYSTEM SOFTWARE 1) Explain Analysis-synthesis model/fron end backend model of compiler 2) Explain various phases of compiler and symbol table. Consider the statement
More informationBuilding Compilers with Phoenix
Building Compilers with Phoenix Syntax-Directed Translation Structure of a Compiler Character Stream Intermediate Representation Lexical Analyzer Machine-Independent Optimizer token stream Intermediate
More informationLexical Scanning COMP360
Lexical Scanning COMP360 Captain, we re being scanned. Spock Reading Read sections 2.1 3.2 in the textbook Regular Expression and FSA Assignment A new assignment has been posted on Blackboard It is due
More informationCOMP455: COMPILER AND LANGUAGE DESIGN. Dr. Alaa Aljanaby University of Nizwa Spring 2013
COMP455: COMPILER AND LANGUAGE DESIGN Dr. Alaa Aljanaby University of Nizwa Spring 2013 Chapter 1: Introduction Compilers draw together all of the theory and techniques that you ve learned about in most
More informationPrinciples of Compiler Design
Principles of Compiler Design Code Generation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Intermediate Code Code Generation Target Program
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering
TEST 1 Date : 24 02 2015 Marks : 50 Subject & Code : Compiler Design ( 10CS63) Class : VI CSE A & B Name of faculty : Mrs. Shanthala P.T/ Mrs. Swati Gambhire Time : 8:30 10:00 AM SOLUTION MANUAL 1. a.
More informationCompiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler
Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis Synthesis of output program (back-end) Intermediate Code Generation Optimization Before and after generating machine
More informationIntermediate representation
Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing HIR semantic analysis HIR intermediate code gen.
More informationLanguage Processors Chapter 1. By: Bhargavi H Goswami Assistant Professor Sunshine Group of Institutes Rajkot, Gujarat, India
Language Processors Chapter 1. By: Bhargavi H Goswami Assistant Professor Sunshine Group of Institutes Rajkot, Gujarat, India Is it ok if Analysis of Source Statement is followed by synthesis of equivalent
More informationLife Cycle of Source Program - Compiler Design
Life Cycle of Source Program - Compiler Design Vishal Trivedi * Gandhinagar Institute of Technology, Gandhinagar, Gujarat, India E-mail: raja.vishaltrivedi@gmail.com Abstract: This Research paper gives
More informationLanguages and Compiler Design II IR Code Optimization
Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring 2010 rev.: 4/16/2010 PSU CS322 HM 1 Agenda IR Optimization
More information1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character
1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character 2. The symbol table implementation is based on the property of locality of reference is a) Linear
More informationA simple syntax-directed
Syntax-directed is a grammaroriented compiling technique Programming languages: Syntax: what its programs look like? Semantic: what its programs mean? 1 A simple syntax-directed Lexical Syntax Character
More informationCOMPILERS BASIC COMPILER FUNCTIONS
COMPILERS BASIC COMPILER FUNCTIONS A compiler accepts a program written in a high level language as input and produces its machine language equivalent as output. For the purpose of compiler construction,
More informationProgramming Languages Third Edition
Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand
More informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationCS131: Programming Languages and Compilers. Spring 2017
CS131: Programming Languages and Compilers Spring 2017 Course Information Instructor: Fu Song Office: Room 1A-504C, SIST Building Email: songfu@shanghaitech.edu.cn Class Hours : Tuesday and Thursday, 8:15--9:55
More informationProgramming Language Processor Theory
Programming Language Processor Theory Munehiro Takimoto Course Descriptions Method of Evaluation: made through your technical reports Purposes: understanding various theories and implementations of modern
More informationCST-402(T): Language Processors
CST-402(T): Language Processors Course Outcomes: On successful completion of the course, students will be able to: 1. Exhibit role of various phases of compilation, with understanding of types of grammars
More informationGroup A Assignment 3(2)
Group A Assignment 3(2) Att (2) Perm(3) Oral(5) Total(10) Sign Title of Assignment: Lexical analyzer using LEX. 3.1.1 Problem Definition: Lexical analyzer for sample language using LEX. 3.1.2 Perquisite:
More informationCompiler Design. Subject Code: 6CS63/06IS662. Part A UNIT 1. Chapter Introduction. 1.1 Language Processors
Compiler Design Subject Code: 6CS63/06IS662 Part A UNIT 1 Chapter 1 1. Introduction 1.1 Language Processors A compiler is a program that can read a program in one language (source language) and translate
More informationPioneering Compiler Design
Pioneering Compiler Design NikhitaUpreti;Divya Bali&Aabha Sharma CSE,Dronacharya College of Engineering, Gurgaon, Haryana, India nikhita.upreti@gmail.comdivyabali16@gmail.com aabha6@gmail.com Abstract
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationCOMPILER DESIGN UNIT I LEXICAL ANALYSIS. Translator: It is a program that translates one language to another Language.
UNIT I LEXICAL ANALYSIS Translator: It is a program that translates one language to another Language. Source Code Translator Target Code 1. INTRODUCTION TO LANGUAGE PROCESSING The Language Processing System
More informationCS606- compiler instruction Solved MCQS From Midterm Papers
CS606- compiler instruction Solved MCQS From Midterm Papers March 06,2014 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 Final Term MCQ s and Quizzes CS606- compiler instruction If X is a
More informationComputer Hardware and System Software Concepts
Computer Hardware and System Software Concepts Introduction to concepts of System Software/Operating System Welcome to this course on Computer Hardware and System Software Concepts 1 RoadMap Introduction
More informationCS 4201 Compilers 2014/2015 Handout: Lab 1
CS 4201 Compilers 2014/2015 Handout: Lab 1 Lab Content: - What is compiler? - What is compilation? - Features of compiler - Compiler structure - Phases of compiler - Programs related to compilers - Some
More informationCS 415 Midterm Exam Spring SOLUTION
CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you
More informationMidTerm Papers Solved MCQS with Reference (1 to 22 lectures)
CS606- Compiler Construction MidTerm Papers Solved MCQS with Reference (1 to 22 lectures) by Arslan Arshad (Zain) FEB 21,2016 0300-2462284 http://lmshelp.blogspot.com/ Arslan.arshad01@gmail.com AKMP01
More informationChapter 3. Describing Syntax and Semantics
Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings of Programs:
More informationIntroduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1
Introduction to Automata Theory BİL405 - Automata Theory and Formal Languages 1 Automata, Computability and Complexity Automata, Computability and Complexity are linked by the question: What are the fundamental
More informationIR Optimization. May 15th, Tuesday, May 14, 13
IR Optimization May 15th, 2013 Tuesday, May 14, 13 But before we talk about IR optimization... Wrapping up IR generation Tuesday, May 14, 13 Three-Address Code Or TAC The IR that you will be using for
More informationafewadminnotes CSC324 Formal Language Theory Dealing with Ambiguity: Precedence Example Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm
afewadminnotes CSC324 Formal Language Theory Afsaneh Fazly 1 Office Hours: (in BA 4237) Monday 3 4pm Wednesdays 1 2pm January 16, 2013 There will be a lecture Friday January 18, 2013 @2pm. 1 Thanks to
More informationAbout the Authors... iii Introduction... xvii. Chapter 1: System Software... 1
Table of Contents About the Authors... iii Introduction... xvii Chapter 1: System Software... 1 1.1 Concept of System Software... 2 Types of Software Programs... 2 Software Programs and the Computing Machine...
More informationStating the obvious, people and computers do not speak the same language.
3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what
More informationCPS 506 Comparative Programming Languages. Syntax Specification
CPS 506 Comparative Programming Languages Syntax Specification Compiling Process Steps Program Lexical Analysis Convert characters into a stream of tokens Lexical Analysis Syntactic Analysis Send tokens
More informationflex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.
flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. More often than not, though, you ll want to use flex to generate a scanner that divides
More informationCS5363 Final Review. cs5363 1
CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers
More informationSYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram
CS6660 COMPILER DESIGN Question Bank UNIT I-INTRODUCTION TO COMPILERS 1. Define compiler. 2. Differentiate compiler and interpreter. 3. What is a language processing system? 4. List four software tools
More informationCS Lecture 2. The Front End. Lecture 2 Lexical Analysis
CS 1622 Lecture 2 Lexical Analysis CS 1622 Lecture 2 1 Lecture 2 Review of last lecture and finish up overview The first compiler phase: lexical analysis Reading: Chapter 2 in text (by 1/18) CS 1622 Lecture
More informationTypes and Static Type Checking (Introducing Micro-Haskell)
Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 13 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 16 October, 2012 1 / 21 1 Types 2 3 4 2 / 21 Thus far
More informationPrinciples of Compiler Design
Principles of Compiler Design Intermediate Representation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Unambiguous Program representation
More informationOptimizing Finite Automata
Optimizing Finite Automata We can improve the DFA created by MakeDeterministic. Sometimes a DFA will have more states than necessary. For every DFA there is a unique smallest equivalent DFA (fewest states
More informationCompiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore
Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Module No. # 10 Lecture No. # 16 Machine-Independent Optimizations Welcome to the
More informationΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών
ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών Lecture 5a Syntax Analysis lias Athanasopoulos eliasathan@cs.ucy.ac.cy Syntax Analysis Συντακτική Ανάλυση Context-free Grammars (CFGs) Derivations Parse trees
More informationCS 360 Programming Languages Interpreters
CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like
More informationBasic concepts. Chapter Toplevel loop
Chapter 3 Basic concepts We examine in this chapter some fundamental concepts which we will use and study in the following chapters. Some of them are specific to the interface with the Caml language (toplevel,
More informationChapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)
Chapter 3: Describing Syntax and Semantics Introduction Formal methods of describing syntax (BNF) We can analyze syntax of a computer program on two levels: 1. Lexical level 2. Syntactic level Lexical
More informationCompiling Regular Expressions COMP360
Compiling Regular Expressions COMP360 Logic is the beginning of wisdom, not the end. Leonard Nimoy Compiler s Purpose The compiler converts the program source code into a form that can be executed by the
More informationCOMPILER CONSTRUCTION Seminar 02 TDDB44
COMPILER CONSTRUCTION Seminar 02 TDDB44 Martin Sjölund (martin.sjolund@liu.se) Adrian Horga (adrian.horga@liu.se) Department of Computer and Information Science Linköping University LABS Lab 3 LR parsing
More informationA programming language requires two major definitions A simple one pass compiler
A programming language requires two major definitions A simple one pass compiler [Syntax: what the language looks like A context-free grammar written in BNF (Backus-Naur Form) usually suffices. [Semantics:
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationCA Compiler Construction
CA4003 - Compiler Construction David Sinclair Overview This module will cover the compilation process, reading and parsing a structured language, storing it in an appropriate data structure, analysing
More informationAC59/AT59 OPERATING SYSTEMS & SYSTEMS SOFTWARE DECEMBER 2012
Q2a. What are the various actions an operating system performs when a new process is created? Explain four fundamental states for a process using a state transition diagram. Ans 2a. As a process executes,
More informationIntroduction to Lexical Analysis
Introduction to Lexical Analysis Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples
More informationII. Language Processing ystem skeletal source program preprocessor source program compiler target object assembly program assembler relocatable machin
CP 140 - Mathematical Foundations of C Dr.. Rodger ection: The tructure of a Compiler 1.1 What is a Compiler I. Translator Deænition: program in translator program in language! for! language X X Y Examples:
More informationCS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation
CS 91.406/534 Compiler Construction University of Massachusetts Lowell Professor Li Xu Fall 2004 NOTHING: A Language for Practice Implementation 1 Introduction NOTHING is a programming language designed
More information11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e
CS-3160 Concepts of Programming Languages Spring 2015 EXAM #1 (Chapters 1-6) Name: SCORES MC: /75 PROB #1: /15 PROB #2: /10 TOTAL: /100 Multiple Choice Responses Each multiple choice question in the separate
More informationIntroduction to Compiler Design
Introduction to Compiler Design Lecture 1 Chapters 1 and 2 Robb T. Koether Hampden-Sydney College Wed, Jan 14, 2015 Robb T. Koether (Hampden-Sydney College) Introduction to Compiler Design Wed, Jan 14,
More informationThe syntax and semantics of Beginning Student
The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come
More informationThe syntax and semantics of Beginning Student
The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come
More informationCS52 - Assignment 8. Due Friday 4/15 at 5:00pm.
CS52 - Assignment 8 Due Friday 4/15 at 5:00pm https://xkcd.com/859/ This assignment is about scanning, parsing, and evaluating. It is a sneak peak into how programming languages are designed, compiled,
More informationPSD1C SYSTEM SOFTWAE UNIT: I - V PSD1C SYSTEM SOFTWARE
PSD1C SYSTEM SOFTWAE UNIT: I - V 1 Syllabus Unit-I Language Processors Types of Language Processors Language Processing Activities Fundamentals of Language Processing Language Specification Data Structures
More informationCompilers and computer architecture From strings to ASTs (2): context free grammars
1 / 1 Compilers and computer architecture From strings to ASTs (2): context free grammars Martin Berger October 2018 Recall the function of compilers 2 / 1 3 / 1 Recall we are discussing parsing Source
More informationMATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards
MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards Language Reference Manual Introduction The purpose of
More informationContext-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation
Concepts Introduced in Chapter 2 A more detailed overview of the compilation process. Parsing Scanning Semantic Analysis Syntax-Directed Translation Intermediate Code Generation Context-Free Grammar A
More informationGBIL: Generic Binary Instrumentation Language. Language Reference Manual. By: Andrew Calvano. COMS W4115 Fall 2015 CVN
GBIL: Generic Binary Instrumentation Language Language Reference Manual By: Andrew Calvano COMS W4115 Fall 2015 CVN Table of Contents 1) Introduction 2) Lexical Conventions 1. Tokens 2. Whitespace 3. Comments
More information