SYLLABUS UNIT - I UNIT - II UNIT - III UNIT - IV CHAPTER - 1 : INTRODUCTION CHAPTER - 4 : SYNTAX AX-DIRECTED TRANSLATION TION CHAPTER - 7 : STORA

Similar documents
About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR / EVEN SEMESTER

VIVA QUESTIONS WITH ANSWERS

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

VALLIAMMAI ENGINEERING COLLEGE

Question Bank. 10CS63:Compiler Design

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

PRINCIPLES OF COMPILER DESIGN

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTER SCIENCE AND ENGINEERING COURSE PLAN

DEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING UNIT -1-INTRODUCTION TO COMPILERS 2 MARK QUESTIONS

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY

Roll No. :... Invigilator's Signature :. CS/B.Tech(CSE)/SEM-7/CS-701/ LANGUAGE PROCESSOR. Time Allotted : 3 Hours Full Marks : 70

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

INSTITUTE OF AERONAUTICAL ENGINEERING

Compiler Design Aug 1996

Torben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer

GUJARAT TECHNOLOGICAL UNIVERSITY

LECTURE NOTES ON COMPILER DESIGN P a g e 2

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

Principles of Programming Languages [PLP-2015] Detailed Syllabus

CS606- compiler instruction Solved MCQS From Midterm Papers

Let us construct the LR(1) items for the grammar given below to construct the LALR parsing table.

4. An interpreter is a program that

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

CST-402(T): Language Processors

Life Cycle of Source Program - Compiler Design

CJT^jL rafting Cm ompiler

Appendix Set Notation and Concepts


Time : 1 Hour Max Marks : 30

2068 (I) Attempt all questions.

QUESTIONS RELATED TO UNIT I, II And III

Appendix A The DL Language

1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

COURSE: DATA STRUCTURES USING C & C++ CODE: 05BMCAR17161 CREDITS: 05

COMPILER DESIGN LEXICAL ANALYSIS, PARSING

Syntax Analysis. Chapter 4


List of Figures. About the Authors. Acknowledgments

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Alternatives for semantic processing

CS 406/534 Compiler Construction Putting It All Together

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree.

Compiler Construction Using

Compiler Optimization

CS6660-COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS PART A

GUJARAT TECHNOLOGICAL UNIVERSITY

CS5363 Final Review. cs5363 1

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

VALLIAMMAI ENGINEERING COLLEGE

Context-free grammars

UNIT I INTRODUCTION TO COMPILING

Review. Pat Morin COMP 3002

Contents. Chapter 1 SPECIFYING SYNTAX 1

Compiler Construction: Parsing

DEPARTMENT OF INFORMATION TECHNOLOGY AUTOMATA AND COMPILER DESIGN. B.Tech-IT, III Year -I Sem

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character

SYSTEMS PROGRAMMING. Srimanta Pal. Associate Professor Indian Statistical Institute Kolkata OXFORD UNIVERSITY PRESS

Parsing Wrapup. Roadmap (Where are we?) Last lecture Shift-reduce parser LR(1) parsing. This lecture LR(1) parsing

Compiler Code Generation COMP360

CS 4201 Compilers 2014/2015 Handout: Lab 1

KALASALINGAM UNIVERSITY ANAND NAGAR, KRISHNAN KOIL DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ODD SEMESTER COURSE PLAN

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

Building a Runnable Program and Code Improvement. Dario Marasco, Greg Klepic, Tess DiStefano

A programming language requires two major definitions A simple one pass compiler

The View from 35,000 Feet

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

CS 132 Compiler Construction

LR Parsing LALR Parser Generators

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Programming Language Processor Theory

Chapter 6 Intermediate Code Generation

Wednesday, September 9, 15. Parsers

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

Evaluation Scheme L T P Total Credit Theory Mid Sem Exam

SECTION A. (i) The Boolean function in sum of products form where K-map is given below (figure) is:

4. Lexical and Syntax Analysis

PSD1C SYSTEM SOFTWAE UNIT: I - V PSD1C SYSTEM SOFTWARE

Compilers and Interpreters

Syntax-Directed Translation

4. Lexical and Syntax Analysis

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Understanding and Writing Compilers

Intermediate Code Generation

Overview of a Compiler

UNIT IV INTERMEDIATE CODE GENERATION

Compiling Techniques

Transcription:

Contents i SYLLABUS UNIT - I CHAPTER - 1 : INTRODUCTION Programs Related to Compilers. Translation Process, Major Data Structures, Other Issues in Compiler Structure, Boot Strapping and Porting. CHAPTER - 2 : LEXICAL ANALYSIS The Role of Lexical Analyzer, Input Buffering, Specification of Tokens, Recognition of Tokens, The Lexical-Analyzer Generator Lex. UNIT - II CHAPTER - 3 : SYNTAX ANALYSIS Introduction, Top-Down Parsing, Brute Forcing, Recursive Descent, Predicative LL(1), Bottom-Up Parsing, Introduction to LR Parsing, Powerful LR Parsers SLR, CALR, LALR, Using Ambiguous Grammars, Parser Generators-Yacc. UNIT - III CHAPTER - 4 : SYNTAX AX-DIRECTED TRANSLATION TION Syntax-Directed Definitions, Evaluation Orders for SDDS, Applications of Syntax Directed Translation. CHAPTER - 5 : SYMBOL TABLE ORGANIZATION Structure of Symbol Table, Symbol Table Organization for Block Structured and Non- Block Structure Languages, Data Structures of Symbol Table. UNIT - IV CHAPTER - 6 : INTERMEDIATE CODE GENERATION Variants of Syntax Trees, Three-Address Code, Types and Declarations, Translation of Expressions, Type Checking, Control Flow. CHAPTER - 7 : STORA ORAGE ORGANIZATION Stack Allocation of Space, Access to Non-Local Data on the Stack, Heap Management, Introduction to Garbage Collection.

ii Contents UNIT - V CHAPTER - 8 : CODE GENERATION Issues in the Design of a Code Generator, The Target Language, Addresses in the Target Code Basic Blocks and Flow Graphs, Optimization of Basic Blocks, Peephole Optimization, Register Allocation and Assignment. CHAPTER - 9 : MACHINE CHINE-INDEPENDENT OPTIMIZATIONS TIONS The Principal Sources of Optimizations, Introduction to Data Flow Analysis, Foundation of Data Flow Analysis. CHAPTER - 10 : ERROR RECOVERY Introduction, Error Detecting and Reporting in Various Phases, Lexical Errors, Syntax Errors Handling and Error Recovery in Various Phases.

Contents iii compiler construction FOR b.e. (o.u) Iii year ii semester (COMMON TO CSE AND IT) CONTENTS UNIT - I [CH. H. - 1] ] [INTRODUCTION INTRODUCTION]... 1.1-1.32 1.1 INTRODUCTION... 1.2 1.1.1 Compilation... 1.2 1.1.2 Meaning of Translator... 1.3 1.1.3 Meaning of Compiler... 1.3 1.1.3.1 Why Study Compilers?... 1.4 1.1.3.2 Compiler Design Challenges... 1.4 1.1.3.3 Characteristics of Compiler... 1.5 1.2 PROGRAMS RELATED TO O COMPILERS... 1.5 1.2.1 Interpreters... 1.6 1.2.1.1 Characteristics of Interpreter... 1.6 1.2.1.2 Differences between Compiler and Interpreter... 1.7 1.2.2 Assemblers... 1.8 1.2.3 Linkers... 1.8 1.2.4 Loaders... 1.9 1.2.5 Preprocessors... 1.9 1.2.6 Editors... 1.9 1.2.7 Debuggers... 1.10 1.2.8 Profilers... 1.10 1.2.9 Project Managers... 1.10

iv Contents 1.3 THE TRANSLATION TION PROCESS... 1.10 1.3.1 Scanner (or) Lexial Analysis... 1.12 1.3.2 Parser (or) Syntax Analysis... 1.13 1.3.3 Semantic Analyzer... 1.15 1.3.4 Intermediate Code Generation... 1.16 1.3.5 Code Optimization... 1.17 1.3.6 Code Generation... 1.17 1.4 MAJOR DATA A STRUCTURES IN A COMPILER... 1.18 1.4.1 Tokens... 1.18 1.4.2 The Syntax Tree ree... 1.18 1.4.3 The Symbol Table... 1.18 1.4.4 The Literal Table... 1.19 1.4.5 Intermediate Code... 1.19 1.4.6 Temporary Files iles... 1.19 1.5 OTHER ISSUES IN COMPILER STRUCTURE... 1.20 1.5.1 Analysis and Synthesis... 1.20 1.5.2 Front End and Back End... 1.21 1.5.3 Passes... 1.21 1.5.4 Language Definition and Compilers... 1.21 1.5.5 Compiler Options and Interfaces... 1.22 1.5.6 Error Handling... 1.22 1.6 BOOTSTRAPPING AND PORTING... 1.23 Short Questions and Answers... 1.27-1.31 Expected University Questions with Answers... 1.32

Contents v UNIT - I [CH.. - 2] ] [LEXICAL ANALYSIS YSIS]... 1.33-1.74 2.1 INTRODUCTION TO LEXICAL ANALYSIS... 1.34 2.2 THE ROLE OF LEXICAL ANALYZER... 1.35 2.2.1 Lexical Analysis Versus Parsing... 1.36 2.2.2 Tokens, Patterns, and Lexemes... 1.36 2.2.3 Attributes for Tokens... 1.39 2.2.4 Lexical Errors... 1.40 2.3 INPUT BUFFERING... 1.42 2.3.1 Buffer Pairs... 1.42 2.3.2 Sentinels... 1.44 2.4 SPECIFICATION OF TOKENS... 1.45 2.4.1 Strings and Languages... 1.45 2.4.2 Operations on Languages... 1.46 2.4.3 Regular Expressions... 1.47 2.4.4 Regular Definitions... 1.49 2.4.5 Extensions of Regular Expressions... 1.50 2.4.6 Solved Problems... 1.51 2.5 RECOGNITION OF TOKENS... 1.52 2.5.1 Transition Diagrams... 1.54 2.5.2 Converting Transition Diagrams into Code... 1.57 2.6 THE LEXICAL-ANAL ANALYZER GENERATOR OR LEX... 1.61 2.6.1 Use of Lex... 1.61 2.6.2 Structure of Lex Programs... 1.62 2.6.3 Conflict Resolution in Lex... 1.64 2.6.4 The Lookahead Operator... 1.64 2.6.5 Solved Problems... 1.64 Short Questions and Answers... 1.69-1.71 Expected University Questions with Answers... 1.72-1.74

vi Contents UNIT - II [CH.. - 3] ] [SYNT SYNTAX AX ANALYSIS YSIS]... 2.1-2.162 3.1 INTRODUCTION TO SYNTAX ANALYSIS... 2.2 3.1.1 The Role of The Parser... 2.2 3.1.1.1 The Parsing Process... 2.2 3.1.2 Representative Grammars... 2.4 3.1.3 Syntax Error Handling... 2.5 3.1.4 Error Recovery Strategies... 2.6 3.1.4.1 Panic-Mode Recovery... 2.6 3.1.4.2 Phrase-Level Recovery... 2.7 3.1.4.3 Error Productions... 2.7 3.1.4.4 Global Correction... 2.7 3.2 TOP-DOWN PARSING ARSING... 2.8 3.2.1 Recursive ecursive-descent Parsing... 2.10 3.2.2 FIRST and FOLLOW... 2.13 3.2.3 LL(1) Grammars... 2.17 3.2.3.1 Transition Diagrams for Predictive Parsers... 2.19 3.2.4 Non-Recursive Predictive Parsing... 2.22 3.2.4.1 Construction of Predictive Parsing Table... 2.24 3.2.5 Error Recovery in Predictive Parsing... 2.28 3.2.5.1 Panic-Mode Recovery... 2.29 3.2.5.2 Phrase-Level Recovery... 2.32 3.2.6 Solved Problems... 2.32 3.3 BOTT TTOM-UP PARSING... 2.50 3.3.1 Reductions... 2.53 3.3.2 Handle Pruning... 2.54 3.3.3 Shift-R -Reduce Parsing... 2.55 3.3.4 Conflicts During Shift-R -Reduce Parsing arsing... 2.58

Contents vii 3.4 INTRODUCTION TO LR PARSING : SIMPLE LR... 2.59 3.4.1 Need of LR Parsers arsers... 2.59 3.4.2 Items and the LR(0) Automation... 2.60 3.4.2.1 CLOSURE of Item Sets... 2.60 3.4.2.2 The Function GOTO... 2.61 3.4.2.3 Use of The LR(0) Automation... 2.62 3.4.3 The LR-P -Parsing Algorithm... 2.63 3.4.3.1 Structure of the LR-P -Parsing Table... 2.64 3.4.3.2 LR-P -Parser Configurations... 2.64 3.4.3.3 Behavior of the LR-P -Parser arser... 2.65 3.4.3.4 Implementation of LR Parsing Algorithm... 2.65 3.4.4 Constructing SLR-P -Parsing Tables... 2.67 3.4.5 Viable Prefixes... 2.78 3.4.6 Solved Problems... 2.78 3.5 MORE POWERFUL LR-P -PARSERS ARSERS... 2.90 3.5.1 Canonical LR(1) Items... 2.90 3.5.2 Constructing LR(1) Sets of Items... 2.91 3.5.3 Canonical LR(1) Parsing Tables... 2.92 3.5.3.1 Solved Problems... 2.93 3.5.4 Constructing LALR Parsing Tables... 2.107 3.5.5 Efficient Construction of LALR Parsing Tables... 2.109 3.5.6 Compaction of LR Parsing Tables... 2.116 3.5.7 SLR Versus LALR... 2.120 3.6 USING AMBIGUOUS GRAMMARS... 2.120 3.6.1 Precedence and Associativity to Resolve Conflicts... 2.121 3.6.2 The Dangling-Else Ambiguity... 2.125 3.6.3 Error Recovery in LR Parsing... 2.130 3.6.4 Differences between Top op-down and Bottom-Up Parsers arsers... 2.134

viii Contents 3.7 PARSER GENERATORS ORS... 2.135 3.7.1 The Parser Generator Yacc acc... 2.135 3.7.1.1 The Declarations Part art... 2.136 3.7.1.2 The Translation Rules Part... 2.137 3.7.1.3 The Supporting C-R -Routines Part art... 2.139 3.7.2 Using Yacc with Ambiguous Grammars... 2.141 3.7.3 Creating Yacc Lexical Analyzers with Lex... 2.146 3.7.4 Error Recovery in Yacc... 2.148 3.8 BRUTE FORCING... 2.151 Short Questions and Answers... 2.153-2.158 Expected University Questions with Answers... 2.159-2.162 UNIT - III [CH.. - 4] ] [SYNT SYNTAX AX-DIRECTED TRANSLATION TION]... 3.1-3.36 4.1 INTRODUCTION TO O SYNTAX AX-DIRECTED TRANSLATION TION... 3.2 4.2 SYNTAX AX-DIRECTED DEFINITIONS... 3.3 4.2.1 Synthesized and Inherited Attributes... 3.4 4.2.2 Evaluating an SDD at the Nodes of a Parse Tree ree... 3.7 4.3 EVAL ALUATION ORDERS OF SDD S S... 3.11 4.3.1 Dependency Graphs... 3.11 4.3.2 Ordering the Evaluating of Attributes... 3.14 4.3.3 S-Attributed Definitions... 3.14 4.3.4 L-Attributed Definitions... 3.15 4.3.5 Semantic Rules with Controlled Side Effects... 3.16 4.4 APPLICATIONS OF SYNTAX AX-DIRECTED TRANSLATION TION... 3.16 4.4.1 Construction of Syntax Trees... 3.16 4.4.2 The Structure of a Type... 3.18 4.4.3 Solved Problems... 3.19 Short Questions and Answers... 3.31-3.34 Expected University Questions with Answers... 3.35-3.36

Contents ix UNIT - III [CH. H. - 5] ] [SYMBOL TABLE ORGANIZATION]... 3.37-3.104 5.1 INTRODUCTION TO SYMBOL TABLES... 3.38 5.2 SYMBOL TABLE FORMAT... 3.38 5.2.1 Attributes of a Symbol Table... 3.38 5.2.2 Contents of a Symbol Table... 3.40 5.2.3 Operations Performed on the Symbol Table... 3.43 5.2.4 Indirection in Symbol Table Entries... 3.44 5.2.5 Ordered and Unordered Symbol Table... 3.45 5.2.6 Symbol Table Organization Techniques... 3.48 5.2.6.1 Comparison of Three Basic Data Structures... 3.56 5.2.6.2 Hash Table with Temporary and Permanent Storage... 3.56 5.2.7 Reusing the Storage Space for Names... 3.57 5.2.8 Implementation of Hashed Symbol Table... 3.59 5.3 SYMBOL TABLE ORGANIZATION FOR BLOCK STRUCTURED LANGUAGES... 3.64 5.4 HASHING... 3.66 5.5 TREE STRUCTURE REPRESENTATION TION OF SCOPE INFORMATION... 3.68 5.6 BLOCK OCK-STRUCTURES AND NON-BLOCK OCK STRUCTURE STORA ORAGE GE ALLOCA OCATION... 3.69 5.6.1 Basic Issues... 3.69 5.6.2 Activation Record... 3.70 5.6.3 Local Data... 3.71 5.6.4 Non-Local Data... 3.73 5.6.4.1 Dynamic Scoping... 3.76 5.7 STORA ORAGE ALLOCA OCATION STRATEGIES TEGIES... 3.78 5.7.1 Static Allocation Strategy... 3.79 5.7.2 Stack Allocation Strategy... 3.81

x Contents 5.7.3 Heap Allocation Strategy... 3.87 5.7.4 Dynamic Storage Allocation Techniques... 3.87 5.7.5 Dangling Reference in Storage Allocation... 3.91 5.7.6 Solved Problems... 3.92 5.8 PARAMETER PASSING... 3.94 5.9 DATA A STRUCTURES OF SYMBOL TABLE ABLE... 3.96 Short Questions and Answers... 3.99-3.102 Expected University Questions with Answers... 3.103-3.104 UNIT - IV [CH. H. - 6] ] [INTERMEDIATE CODE GENERATION]... 4.1-4.84 6.1 INTRODUCTION TO O INTERMEDIATE TE-CODE GENERATION TION... 4.2 6.1.1 Intermediate Code Forms... 4.3 6.1.2 Postfix Notation (Polish Notation)... 4.14 6.1.3 Prefix Notation... 4.14 6.2 VARIANTS OF SYNTAX AX TREE... 4.14 6.2.1 Directed Acyclic Graphs for Expressions... 4.16 6.2.2 The Value alue-number Method for Constructing DAG s s... 4.18 6.3 THREE-ADDRESS CODE... 4.19 6.3.1 Addresses and Instructions... 4.20 6.3.2 Quadruples... 4.23 6.3.3 Triples... 4.25 6.3.4 Static Single-Assignment Form... 4.28 6.3.5 Solved Problems... 4.30 6.4 TYPES AND DECLARATIONS TIONS... 4.38 6.4.1 Type Expressions... 4.38 6.4.2 Type Equivalence... 4.42 6.4.3 Declarations... 4.42

Contents xi 6.4.4 Storage Layout for Local Names... 4.43 6.4.5 Sequences of Declarations... 4.44 6.4.6 Fields in Records and Classes... 4.45 6.5 TRANSLATION TION OF EXPRESSIONS... 4.45 6.5.1 Operations within Expressions... 4.46 6.5.2 Incremental Translation ranslation... 4.46 6.5.3 Addressing Array Elements... 4.47 6.5.4 Translation of Array References eferences... 4.48 6.6 TYPE CHECKING... 4.53 6.6.1 Rules for Type Checking... 4.53 6.6.2 Type Conversions... 4.54 6.6.3 Overloading of Functions and Operators... 4.56 6.6.4 Type Inference and Polymorphic Functions... 4.57 6.6.5 An Algorithm for Unification... 4.59 6.7 CONTROL FLOW... 4.63 6.7.1 Boolean Expressions... 4.63 6.7.2 Short-Circuit Code... 4.66 6.7.3 Flow-of-Control Statements... 4.67 6.7.4 Control-Flow Translation of Boolean Expressions... 4.71 6.7.5 Avoiding Redundant Gotos... 4.73 6.7.6 Boolean Values and Jumping Code... 4.73 6.7.7 Solved Problems... 4.74 Short Questions and Answers... 4.77-4.81 Expected University Questions with Answers... 4.82-4.84

xii Contents UNIT - IV [CH. H. - 7] ] [STORAGE ORGANIZATION]... 4.85-4.122 7.1 INTRODUCTION... 4.86 7.2 STORA ORAGE ORGANIZATION TION... 4.86 7.2.1 Static Versus Dynamic Storage Allocation... 4.87 7.3 STACK ALLOCA OCATION OF SPACE... 4.88 7.3.1 Activation Trees... 4.88 7.3.2 Activation Records... 4.93 7.3.2.1 Compile-Time ime Layout of Local Data... 4.94 7.3.2.2 Downward-Growing Stack Allocation of Activation Records... 4.94 7.3.3 Calling Sequences... 4.96 7.3.4 Variable ariable-l -Length Data on the Stack... 4.97 7.4 ACCESS TO O NON-LOCAL OCAL DATA A ON THE STACK CK... 4.99 7.4.1 Data Access without Nested Procedures... 4.99 7.4.2 Issues with Nested Procedures... 4.99 7.4.3 A Language with Nested Procedure Declarations... 4.100 7.4.4 Nesting Depth... 4.100 7.4.5 Access Links... 4.101 7.4.6 Manipulating Access Links... 4.104 7.4.7 Access Links for Procedure Parameters... 4.104 7.4.8 Displays... 4.106 7.5 HEAP MANAGEMENT... 4.107 7.5.1 The Memory Manager... 4.107 7.5.2 The Memory Hierarchy of a Computer... 4.108 7.5.3 Locality in Programs... 4.109 7.5.3.1 Optimization using the Memory Hierarchy... 4.109

Contents xiii 7.5.4 Reducing Fragmentation... 4.109 7.5.4.1 Best-Fit and Next-Fit Object Placement... 4.110 7.5.4.2 Managing and Coalescing Free Space... 4.110 7.5.5 Manual Deallocation Requests... 4.112 7.5.5.1 Problems with Manual Deallocation... 4.112 7.5.5.2 Programming Conventions and Tools... 4.112 7.6 INTRODUCTION TO GARBAGE GE COLLECTION... 4.113 7.6.1 Design Goals for Garbage Collections... 4.113 7.6.1.1 A Basic Requirement Type Safety... 4.113 7.6.1.2 Performance Metrics... 4.114 7.6.2 Reachability... 4.115 7.6.3 Reference Counting Garbage Collectors... 4.116 Short Questions and Answers... 4.119-4.121 Expected University Questions with Answers... 4.122 UNIT - V [CH. - 8] ] [CODE GENERATION]... 5.1-5.46 8.1 CODE GENERATION TION... 5.2 8.2 ISSUES IN THE DESIGN OF A CODE GENERATOR OR... 5.3 8.2.1 Input to the code Generator... 5.3 8.2.2 The Target Program... 5.4 8.2.3 Memory Management... 5.6 8.2.4 Instruction Selection... 5.6 8.2.5 Register Allocation... 5.8 8.2.6 Evaluation Order... 5.9 8.3 THE TARGET LANGUAGE... 5.9 8.3.1 A Simple Target Machine Model... 5.9 8.3.2 Program and Instruction Costs... 5.12

xiv Contents 8.4 ADDRESSES IN THE TARGET CODE... 5.13 8.4.1 Static Allocation... 5.13 8.4.2 Stack Allocation... 5.15 8.4.3 Runun-Time Addresses for Names... 5.18 8.5 BASIC BLOCKS AND FLOW GRAPHS... 5.18 8.5.1 Basic Blocks... 5.19 8.5.2 Next-Use Information... 5.21 8.5.3 Flow Graphs... 5.21 8.5.4 Representation of Flow Graphs... 5.23 8.5.5 Loops... 5.23 8.6 OPTIMIZATION TION OF BASIC BLOCKS... 5.23 8.6.1 The DAG Representation of Basic Blocks... 5.23 8.6.2 Finding Local Common Subexpressions... 5.25 8.6.3 Dead Code Elimination... 5.27 8.6.4 The Use of Algebraic Identities... 5.27 8.6.5 Representation of Array References... 5.28 8.6.6 Pointer Assignments and Procedure Calls... 5.29 8.6.7 Reassembling Basic Blocks from DAG s... 5.30 8.7 PEEPHOLE OPTIMIZATION TION... 5.31 8.7.1 Eliminating Redundant Loads and Stores... 5.32 8.7.2 Eliminating Unreachable Code... 5.32 8.7.3 Flow-of-Control Optimizations... 5.33 8.7.4 Algebraic Simplification and Reduction in Strength... 5.34 8.7.5 Use of Machine Idioms... 5.35

Contents xv 8.8 REGISTER ALLOCA OCATION AND ASSIGNMENT... 5.35 8.8.1 Global Register Allocation... 5.35 8.8.2 Usage Counts... 5.36 8.8.3 Register Assignement for Outer Loops... 5.39 8.8.4 Register Allocation by Graph Coloring... 5.39 Short Questions and Answers... 5.41-5.44 Expected University Questions with Answers... 5.45-5.46 UNIT - V [CH. H. - 9] ] [MACHINE-INDEPENDENT OPTIMIZATIONS]... 5.47-5.88 9.1 MACHINE CHINE-INDEPENDENT OPTIMIZATIONS TIONS... 5.48 9.2 THE PRINCIPAL SOURCES OF OPTIMIZATION TION... 5.49 9.2.1 Causes of Redundancy... 5.49 9.2.2 A Running Example Quicksort... 5.49 9.2.3 Semantics-P -Preserving Transformations... 5.53 9.2.4 Global Common Subexpressions... 5.54 9.2.5 Copy Propagation... 5.55 9.2.6 Dead-Code Elimination... 5.56 9.2.7 Code Motion... 5.57 9.2.8 Induction Variables and Reduction in Strength... 5.58 9.3 INTRODUCTION TO O DATA-FL -FLOW ANALYSIS... 5.59 9.3.1 The Data-Flow Abstraction... 5.60 9.3.2 The Data-Flow Analysis Schema... 5.61 9.3.2.1 Transfer Functions... 5.62 9.3.2.2 Control-Flow Constraints... 5.62 9.3.3 Data-Flow Schemas on Basic Blocks... 5.63 9.3.4 Reaching Definitions... 5.63 9.3.4.1 Transfer Equations for Reaching Definitions... 5.64 9.3.4.2 Control-Flow Equations... 5.66 9.3.4.3 Iterative Algorithm for Reaching Definitions... 5.66 9.3.5 Live-Variable Analysis... 5.69 9.3.6 Available Expressions... 5.71

xvi Contents 9.4 FOUNDATIONS OF DATA-FL -FLOW ANALYSIS... 5.73 9.4.1 Semilattices... 5.73 9.4.1.1 Partial Orders... 5.74 9.4.1.2 The Partial Order for a Semilattice... 5.74 9.4.1.3 Greatest Lower Bounds... 5.75 9.4.1.4 Lattice Diagrams... 5.76 9.4.1.5 Product Lattices... 5.76 9.4.1.6 Height of a Semilattice... 5.77 9.4.2 Transfer Functions... 5.78 9.4.2.1 Monotone Frameworks... 5.78 9.4.2.2 Distributive Frameworks rameworks... 5.79 9.4.3 The Iterative Algorithm for General Frameworks... 5.79 9.4.4 Meaning of a Data-Flow Solution... 5.81 9.4.4.1 The Ideal Solution... 5.81 9.4.4.2 The Meet-Over Over-P -Paths Solution... 5.82 9.4.4.3 The Maximum Fixed Point Versus the MOP Solution... 5.83 Short Questions and Answers... 5.85-5.87 Expected University Questions with Answers... 5.88 UNIT - V [CH. - 10] ] [ERROR RECOVERY]... 5.89-5.114 10.1 INTRODUCTION... 5.90 10.2 SOURCES OF ERRORS... 5.90 10.3 GOALS OF ERRORS... 5.91 10.4 SYNTAX ERRORS... 5.91 10.4.1 Recovery from Syntax Errors... 5.94 10.4.2 Recovery in Top op-down Parsing... 5.95 10.4.3 Recovery in Bottom-Up Parsing arsing... 5.96 10.4.4 Error-R -Recovery in YACC... 5.96

Contents xvii 10.5 SYNTAX ERRORS HANDLING... 5.98 10.6 ERROR DETECTING... 5.99 10.6.1 Error Detection in Top op-down Parsers arsers... 5.99 10.6.2 Error Detection in Bottom-Up Parsers... 5.100 10.7 ERROR REPORTING... 5.100 10.8 ERROR DETECTING IN VARIOUS PHASES... 5.100 10.8.1 Lexical Errors... 5.100 10.8.2 Syntax Errors... 5.101 10.8.3 Semantic Error... 5.101 10.9 ERROR REPORTING IN VARIOUS PHASES... 5.102 10.10 LEXICAL ERRORS... 5.103 10.10.1 Lexical Error Handling... 5.105 10.11 ERROR RECOVERY... 5.105 10.11.1 Error Recovery in Various Phases... 5.105 10.11.2 Error-R -Recovery in Top op-down Parsing arsing... 5.107 10.11.3 Recovery in Bottom-Up Parsing arsing... 5.108 Short Questions and Answers... 5.109-5.112 Expected University Questions with Answers... 5.113-5.114 UNIT - VI [CH.. - 11] ] [OPTIMIZING FOR PARALLELISM AND LOCALITY OCALITY]... 6.1-6.42 11.1 OPTIMIZING FOR PARALLELISM AND LOCALITY... 6.2 11.2 BASIC CONCEPTS... 6.3 11.2.1 Multiprocessors... 6.3 11.2.2 Parallelism in Applications... 6.5 11.2.2.1 Amdahl s Law... 6.8 11.2.2.2 Granularity of Parallelism... 6.8 11.2.3 Loop oop-l -Level Parallelism... 6.9 11.2.4 Data Locality... 6.10 11.2.5 Introduction to Affine Transform Theory... 6.12

xviii Contents 11.3 MATRIX MULTIPL TIPLY : AN IN-DEPTH EXAMPLES... 6.13 11.3.1 The Matrix-Multiplication Algorithm... 6.13 11.3.1.1 Serial Execution of the Matrix Multiplication... 6.14 11.3.1.2 Row ow-by -by-r -Row Parallelization... 6.16 11.3.2 Optimizations... 6.17 11.3.2.1 Changing Data Layout... 6.17 11.3.2.2 Blocking... 6.18 11.3.3 Cache Interface... 6.21 11.4 DATA-REUSE... 6.22 11.4.1 Types of Reuse euse... 6.24 11.4.2 Self Reuse... 6.24 11.4.2.1 Rank of a Matrix... 6.24 11.4.2.2 Null Space of a Matrix... 6.25 11.4.3 Self-Spatial Reuse... 6.27 11.4.4 Group Reuse... 6.28 11.5 SYNCHRONIZATION BETWEEN PARALLEL LOOPS... 6.28 11.5.1 A Constant Number of Synchronizations... 6.29 11.5.2 Program-Dependence Graphs... 6.30 11.5.3 Hierarchical Time... 6.33 11.5.4 The Parallelization Algorithm... 6.35 Short Questions and Answers... 6.37-6.40 Expected University Questions with Answers... 6.41-6.42 UNIT - VI [CH. - 12] ] [LINKERS AND LOADERS]... 6.43-6.78 12.1 INTRODUCTION TO LINKERS AND LOADERS... 6.44 12.2 BASIC LOADERS FUNCTIONS... 6.44 12.2.1 Design of an Absolute Loader... 6.45 12.2.2 A Simple Bootstrap Loader... 6.47

Contents xix 12.3 MACHINE DEPENDENT LOADER FEATURES... 6.50 12.3.1 Relocation... 6.50 12.3.2 Program Linking... 6.53 12.3.3 Algorithm and Data Structures for a Linking Loader... 6.61 12.4 MACHINE INDEPENDENT LOADER FEATURES TURES... 6.69 12.4.1 Automatic Library Search... 6.69 12.4.2 Loader Options... 6.69 12.5 LOADER DESIGN OPTIONS... 6.70 12.5.1 Linkage Editors... 6.70 12.5.2 Dynamic Linking... 6.72 Short Questions and Answers... 6.75-6.76 Expected University Questions with Answers... 6.77-6.78 LATEST UNIVERSITY QUESTION PAPERS [April/May - 2013] [Main] [CSE CSE]... QP.1 - QP.2 [April/May - 2013] [Main] [IT IT]... QP.3 - QP.4

xx Contents STUDENT NOTES