VALLIAMMAI ENGINEERING COLLEGE

Similar documents
VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

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

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

VALLIAMMAI ENGINEERING COLLEGE

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

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

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

Question Bank. 10CS63:Compiler Design

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

Compiler Design Aug 1996

INSTITUTE OF AERONAUTICAL ENGINEERING

GUJARAT TECHNOLOGICAL UNIVERSITY

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

2068 (I) Attempt all questions.

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

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

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

VIVA QUESTIONS WITH ANSWERS

QUESTIONS RELATED TO UNIT I, II And III

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

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

LECTURE NOTES ON COMPILER DESIGN P a g e 2

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

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

VALLIAMMAI ENGINEERING COLLEGE

CST-402(T): Language Processors

CS606- compiler instruction Solved MCQS From Midterm Papers

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

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

CS6660-COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS PART A

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK VII SEMESTER

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

VALLIAMMAI ENGINEERING COLLEGE

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

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

PRINCIPLES OF COMPILER DESIGN

List of Figures. About the Authors. Acknowledgments

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

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY

General Overview of Compiler

Principles of Programming Languages [PLP-2015] Detailed Syllabus

COMPILER DESIGN UNIT I LEXICAL ANALYSIS. Translator: It is a program that translates one language to another Language.

1. INTRODUCTION TO LANGUAGE PROCESSING The Language Processing System can be represented as shown figure below.

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

Compiler Construction Using

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

Formal Languages and Compilers Lecture VI: Lexical Analysis

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

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

VALLIAMMAI ENGINEERING COLLEGE

CS5363 Final Review. cs5363 1

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

UNIT III & IV. Bottom up parsing

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

ECE251 Midterm practice questions, Fall 2010

Compiler Construction: Parsing

VALLIAMMAI ENGINEERING COLLEGE

SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A

Syntax Analysis Part I

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur

Appendix Set Notation and Concepts

GUJARAT TECHNOLOGICAL UNIVERSITY

4. Lexical and Syntax Analysis

Life Cycle of Source Program - Compiler Design

VALLIAMMAI ENGINEERING COLLEGE

QUESTION BANK CHAPTER 1 : OVERVIEW OF SYSTEM SOFTWARE. CHAPTER 2: Overview of Language Processors. CHAPTER 3: Assemblers

Downloaded from Page 1. LR Parsing

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

4. Lexical and Syntax Analysis

Context-free grammars

Bottom-Up Parsing. Lecture 11-12

Wednesday, September 9, 15. Parsers

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

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

Final Term Papers 2013

Bottom-Up Parsing. Lecture 11-12

CS 406/534 Compiler Construction Putting It All Together

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

Conflicts in LR Parsing and More LR Parsing Types

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

Lecture 7: Deterministic Bottom-Up Parsing

Monday, September 13, Parsers

VALLIAMMAI ENGINEERING COLLEGE

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

Lecture 8: Deterministic Bottom-Up Parsing

UNIT I INTRODUCTION TO COMPILING

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

University of Technology Department of Computer Sciences. Final Examination st Term. Subject:Compilers Design

4. An interpreter is a program that

Chapter 3: Lexing and Parsing

NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY Page 1

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points.

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

Time : 1 Hour Max Marks : 30

CJT^jL rafting Cm ompiler


Midterm I - Solution CS164, Spring 2014

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

Transcription:

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 20 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK VI SEMESTER CS6660 COMPILER DESIGN Regulation 20 Academic Year 207 8 Prepared by Ms. S. Jeyalakshmi, Assistant Professor / IT Ms. R. Saranya, Assistant Professor / IT

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur-6020. Department of Information Technology Question Bank SUBJECT : CS6660 COMPILER DESIGN SEM / YEAR: VI Sem / III Year UNIT I - INTRODUCTION TO COMPILERS Translators-Compilation and Interpretation-Language processors -The Phases of Compiler-Errors Encountered in Different Phases-The Grouping of Phases-Compiler Construction Tools - Programming Language basics PART-A Q.No Question BTL Competence State any two reasons to why phases of compiler should be grouped. 2 How will you group the phases of compiler? Illustrate diagrammatically how a language is processed. Mention few cousins of compiler. 5 What is a compiler? 6 Differentiate compiler and interpreter. 7 Explain the working of compiler. Analysing 8 Draw the block diagram of compiler. 9 What are the aspects of high level languages which make them preferable over machine language? Analysing 0 Discuss a compiler writing tools. Compare single pass compiler and multi pass compiler Analysing 2 What do you mean by Cross-Compiler? List the various compiler construction tools. Define compiler-compiler. 5 Mention the back-end phases of a compiler.

6 List the phases that constitute the front-end of a compiler. BTL-5 Evaluating 7 What are the classifications of compiler? BTL-5 Evaluating 8 What is an interpreter? 9 What are the two parts of a compilation? 20 What is a symbol table? 2 5 6 7 8 PART-B (i)mention any four compiler construction tools with their benefits and drawbacks.(7) (ii)explain the need for grouping of phases of compiler. (6) (i)define the following terms : Compiler, Interpreter, Translator and difference between them. (8) (ii)describe in detail about Cousins of compiler. (5) Explain in detail the process of compilation. Illustrate the output of each phase of compilation for the input : a = ( b + c ) * ( b + c ) * 2. (i)explain the different phases of a compiler in detail. (0) (ii)discuss the cousins of compiler. () What are the phases of compiler? Explain the phases in detail. Write down the output of each phase for the expression a : = b + c * 50 For the given block structured code, indicate the values assigned to w, x, y and z. int i = ; int j = ; { int i = 5; w = i + j ; } x = i + j ; { int j = 6 ; { i = 7 ; y = i + j ; } z = i + j ; } Explain in detail about the phases of compiler and translate the statement pos := init + rate * 60 (i)explain the various errors encountered in different phases of a compiler in detail. (9) (ii)write notes on Symbol Table. () BTL-5 Evaluating 9 Briefly explain the compiler construction tools

0 Explain in detail the front end and back end of the compiler with the help of examples Describe the basics of programming language in brief. 2 For the given block structured code, indicate the values assigned to w, x, y and z. int w, x, y, z; int i = ; j = 5 ; { int j = 7; i = 6 ; w = i + j ; } x = i + j ; { int i = 8 ; y = i + j ; } z = i + j ; Explain in detail the fundamental language processing activities. State the necessity for the compiler in conventional programming language PART - C 2 For the given block structured code, assuming the usual static scoping of declarations, give the scope for each of the twelve declarations. { int w, x, y, z ; /* Block B */ { int x, z ; /* Block B2 */ { int w, x ; /* Block B */ } } { int w, x ; /* Block B */ { int y, z ; /* Block B5 */ } } } For the given block structured code, assuming the usual static scoping of declarations, give the scope for each of the declarations. main() { int a = ; /* Block B */ int b = ; { int b = 2; /* Block B2 */ { int a = ; /* Block B */ cout << a << b ; } { int b = ; /* Block B */ cout << a << b ; } cout << a << b ; } cout << a << b; }

i.what advantages are there to a language-processing system in which the compiler produces assembly language rather than machine language? ( 7 ) ii. Describe the types of errors occurring in different phases of compiler? ( 8 ) Explain in detail the issues in the design of compilers. UNIT II - LEXICAL ANALYSIS Need and Role of Lexical Analyzer-Lexical Errors-Expressing Tokens by Regular Expressions-Converting Regular Expression to DFA- Minimization of DFA-Language for Specifying Lexical Analyzers-LEX-Design of Lexical Analyzer for a sample Language. PART-A Q.No Question BTL Competence What is the role of lexical analyser? 2 Define Lexeme 5 Write a regular definition to represent date in the following format : JAN-5 th 20. Write regular expression to describe a language consists of strings made of even numbers a and b. Why is buffering used in lexical analysis? What are the commonly used buffering methods? 6 What are the various parts in LEX program? 7 Differentiate NFA and DFA. Analysing 8 Write regular expression for the following language (i) set of statements over {a,b,c} that contain no two consecutive b's (ii) set of statements over {a,b,c} that contain an even no. of a's 9 Write a grammar for branching statements. 0 Write regular expression for number and identifier. Give the transition diagram for an identifier. 2 List the operations on languages. Construct NFA for the regular expression ( a a * ) / ( b b * ). How can NFA be generated from regular expression. Analysing 5 Write short notes on LEX. BTL-5 Evaluating 6 List the various error recovery strategies for a lexical analysis. BTL-5 Evaluating

7 Mention the various notational shorthands for representing regular expressions. 8 Define kleene closure and positive closure. Analysing 9 Describe the language denoted by the regular expression: (i) ( 0 / ) * 0 ( 0 / ) ( 0 / ) (ii) 0 ( 0 / ) * 0 20 What are the models of LEX compiler? PART-B Prove that the following two regular expressions are equivalent by showing that the minimum state DFA's are same : (i) ( a / b ) * (ii) ( a * / b * ) * BTL-5 Evaluating 2 Describe the error recovery schemes in the lexical phase of a compiler. 5 6 7 8 9 0 2 (i)explain a language for specifying the lexical analyzer. (7) (ii)explain specification and recognition of tokens. (6) (i)draw the DFA for the augmented regular expression directly using syntax tree ( a / b ) * a b b ( a / b ) * #. (9) (ii)discuss input buffering in detail. () (i)explain in detail about the Lexical analyzer with the possible error recovery actions. (7) (ii)elaborate specification of tokens. (6) Compare NFA and DFA. Construct a DFA directly from an augmented regular expression ( ( ε / a ) b * ) * (i)what are the issues in Lexical analysis. () (ii)differentiate between lexeme, token and pattern. () (iii)draw the transition diagram for relational operators and unsigned numbers. (6) (i)explain briefly about input buffering in reading the source program for finding the tokens. (6) (ii)construct the minimized DFA for the regular expression: (7) ( 0 + ) * ( 0 + ) 0 Construct DFA from an augmented regular expression ( a / b ) * a ( a / b ) ( a / b ). Write down the algorithm wherever necessary. For the regular expression ( a / b ) * a b b ( a / b ) * draw the DFA from NFA. Minimize DFA using Πnew construction. Write down the algorithm wherever necessary (i)describe in detail the tool for generating lexical analyzer. (7) (ii)draw NFA for the regular expression a b * / a b. (6) Convert the Regular Expression a b b ( a / b ) * to DFA using direct method and minimize it. (i)conversion of regular expression ( a / b ) * a b b to NFA. (7) (ii)write an algorithm for minimizing the number of states of a DFA. ( 6 )

(i)write notes on regular expression to NFA. Construct Regular expression to NFA for the sentence ( a b ) * a b. (5) (ii)construct DFA to recognize the language ( a / b ) * a b. ( 8 ) PART - C i.discuss the role of lexical analyzer in detail with necessary examples. ( 8 ) ii.discuss how finite automata is used to represent tokens and perform lexical analysis with examples. (7) 2 Explain in detail the Lexical-Analyzer Generator Lex with Lex program structure and example Lex program Write the algorithm for converting a Regular Expression directly to a DFA and also explain the computation of four functions involved and construction of syntax tree and Dtrans Write the algorithm for conversion of Regular Expression to NFA, NFA to DFA and minimization of DFA UNIT III - SYNTAX ANALYSIS Need and Role of the Parser-Context Free Grammars -Top Down Parsing -General Strategies-Recursive Descent Parser Predictive Parser-LL() Parser-Shift Reduce Parser-LR Parser-LR (0)Item-Construction of SLR Parsing Table - Introduction to LALR Parser - Error Handling and Recovery in Syntax Analyzer-YACC-Design of a syntax Analyzer for a Sample Language PART-A Q.No Question BTL Competence What is the role of a parser? 2 Write a CF grammar to represent palindrome. Eliminate the left recursion for the grammar S A a b A A c S d ϵ Eliminate the left recursion from the following grammar A A c A a d b d ϵ 5 What are the various conflicts that occur during Shift Reduce parsing. BTL-5 Evaluating 6 Write the rule to eliminate the left recursion in a grammar. 7 Define an ambiguous grammar. 8 Construct a parse tree for - ( id + id ). 9 Define handle pruning.

0 Construct a parse tree of ( a + b ) * c for the grammar E E + E E * E ( E ) id. Eliminate immediate left recursion from the following grammar E E + T T, T T * F F, F ( E ) id. BTL-5 Evaluating 2 What is LR parser? How LR parser is different from SLR? How error recovery is done in LR parsing? Analysing 5 Write algorithm to compute FIRST of a non-terminal. 6 Write algorithm to compute FOLLOW of a non-terminal. 7 How parsing techniques are classified? 8 Define regular grammar. 9 Define context free grammar. 20 How YACC handles different types of conflicts in parser? PART-B 2 5 Generate SLR parsing table for the following grammar S Aa bac Bc bba A d B d And parse the sentence "bdc" and "dd" (i)write down the algorithm to eliminate left-recursion and left-factoring and apply both to the following grammar. (6) E E + T E - T T T a b ( E ) (ii)construct predictive parsing table for the above grammar and parse (a+b)-a (7) Find the LALR for the given grammar and parse the sentence ( a + b ) * c E E + T T, T T * F F, F ( E ) / id. Consider the following grammar S AS b A SA a Construct the SLR parse table for the grammar. Show the actions of the parser for the input string "abab" What is an ambiguous grammar? Is the following grammar ambiguous? Prove. E E + E E * E ( E ) id BTL-5 Evaluating

6 7 8 9 0 Design an LALR parser for the following grammar and parse the input id = id. S L = R R L * R id R L Construct a predictive parser for the following grammar S ( L ) a L L,S S and show whether the following string will be accepted or not. ( a, ( a, ( a, a ) ) ) (i)construct a non recursive predictive parsing table for the following grammar : E E or E E and E not E ( E ) 0 (9) (ii)construct parse tree for the input string w = c a d using top down parser. S -> c A d, A -> a b a. () Construct SLR parsing table for the following grammar E E + T T T T F F F F * a b Construct a canonical parsing table for the grammar given below. Also explain the algorithm used. E E + T E T T T * F T F F ( E ) F id. (i)construct Stack implementation of shift reduce parsing for the grammar E E + E E * E ( E ) id and the input string is id + id2 * id (6) (ii)explain LL() grammar for the sentence : (7) S -> iets ietses a, E -> b. 2 Explain LR parsing algorithm with an example Construct parsing table for the grammar and find moves made by predictive parser on input id + id * id and find FIRST and FOLLOW. E -> E + T E -> T T -> T * F T -> F F -> ( E ) / id (i)explain ambiguous grammar G : E -> E + E E * E ( E ) - E id for the sentence : id + id * id (5) (ii)construct SLR parsing table for the following grammar G : E -> E + T T, T -> T * F F, F -> ( E ) id. (8)

PART - C 2 i.write an algorithm for Non recursive predictive parsing. ( 8 ) ii.explain Context free grammar with examples. ( 7 ) State how to resolve the parsing action conflicts in Shift Reduce parser with an example i.list all LR(0) items for the following grammar ( 8 ) S AS b A SA a ii.write the algorithm for FIRST and FOLLOW computation. ( 7 ) Explain in detail the Parser Generator YACC and YACC specification of a simple desk calculator UNIT IV - SYNTAX DIRECTED TRANSLATION & RUN TIME ENVIRONMENT Syntax directed Definitions-Construction of Syntax Tree-Bottom-up Evaluation of S-Attribute Definitions- Design of predictive translator - Type Systems-Specification of a simple type checker-equivalence of Type Expressions-Type Conversions PART-A Q.No Question BTL Competence Construct a parse tree according to the syntax directed definition, for the following input statement : ( + 7.5 * ) / 2 2 Write the -address code for : x = *y; a = &x. Place the above generated -address code for x = *y; a = &x, in Triplets and indirect Triplets List out the various storage allocation strategies 5 What are the types of intermediate languages? 6 Compare syntax tree and parse tree. 7 What is the significance of intermediate code? 8 When does Dangling references occur? Analysing 9 What is DAG? BTL-5 Evaluating 0 Translate the arithmetic expression a * - ( b + c ) into syntax tree and postfix notation. What do you mean by binding of names? 2 Give examples for static check. List Dynamic Storage allocation techniques. BTL-5 Evaluating

Mention the role of semantic analysis. 5 Draw syntax tree for the expression a = b * -c + b * -c 6 Write down syntax directed definition of a simple desk calculator. 7 List out the motivations for backpatching. 8 What are the types of three address statements? Analysing 9 Mention the two rules for type checking. Analysing 20 What are the limitations of static allocation? PART-B 2 5 6 (i)give a syntax-directed definition to differentiate expressions formed by applying the arithmetic operators + and * to the variable x and constants ; expression : x * ( * x + x * x ). (7) (ii)how names can be looked up in the symbol table? Discuss. (6) For the given program fragment A[i,j] = B[i,k] do the following : (i)draw the annotated parse tree with the translation scheme to convert to three address code. (5) (ii)write the -address code. (5) (iii) Determine the address of A[,5] where all are integer arrays with size of A as 0 x 0 and B as 0 x 0 with k=2 and the start index position of all arrays is at. ( Assume the base addresses ) () Generate intermediate code for the following code segment along with the required syntax directed translation scheme. while ( i < 0 ) if ( i % 2 == 0 ) evensum = evensum + i else oddsum = oddsum + i Generate intermediate code for the following code segment along with the required syntax directed translation scheme. s = s + a[i][j]; How would you convert the following into intermediate code? Give suitable example (i)assignment statements and use the scheme for generating three address code for g := a + b - c * d. (7) (ii)case statements. (6) (i)explain the sequence of stack allocation processes for a function call. (7) (ii)explain about various parameter passing methods in procedure calls. (6)

7 8 9 0 2 (i)write the translation scheme for flow of control statement. (7) (ii)explain and compare in detail the various implementation forms of three address code. (6) (i)write the grammar and translation scheme for procedure call statements.(7) (ii)discuss runtime storage management in detail. (6) (i)specify a type checker which can handle expressions, statements and functions. (7) (ii)write down the translation scheme to generate three address for the assignment statements. (6) (i)translate the following switch statement into intermediate code. (7) switch E begin case V : S case V2 : S2 case Vn- : Sn- default : Sn end (ii)generate three address code for the boolean expression. (6) a < b or c < d and e < f (i)a Syntax-Directed Translation scheme that takes strings of a's, b's and c's as input and produces as output the number of substrings in the input string that correspond to the pattern a ( a b ) * c + ( a b ) * b. For example the translation of the input string " a b b c a b c a b a b c " is " ". (7) () Write a context-free grammar that generates all strings of a's, b's and c's (2) Give the semantic attributes for the grammar symbols () For each production of the grammar present a set of rules for evaluation of the semantic attributes (ii)illustrate type checking with necessary diagram. (6) Explain the following with respect to code generation phase. (i) Input to code generator, (ii) Target program, (iii) Memory management, (iv) Instruction Selection, (v) register allocation (vi) Evaluation Order (i)construct a syntax directed definition for constructing a syntax tree for assignment statements. (7) S -> id := E, E -> E + E2, E -> E * E2, E -> -E, E -> ( E ), E -> id (ii)discuss specification of a simple type checker. (6) BTL-5 Evaluating Discuss different storage allocation strategies PART - C Translate the executable statements of the following C program into three address code main( ) {

2 int i, a[0]; i = ; while ( i <= 0 ) { a[i] = 0; i = i + ; } } Generate annotated parse tree for the expression c + a[i][j] and also generate three address instruction State the rules for type checking and explain type conversions BTL-5 Evaluating Compare and contrast Quadruples, triples and indirect triples. Give examples UNIT V - CODE OPTIMIZATION AND CODE GENERATION Principal Sources of Optimization-DAG- Optimization of Basic Blocks-Global Data Flow Analysis-Efficient Data Flow Algorithms-Issues in Design of a Code Generator - A Simple Code Generator Algorithm. PART-A Q.No Question BTL Competence How is Liveness of a variable calculated? 2 Generate code for the following C statement assuming three registers are available : x = a / ( b + c ) - d * ( e + f ). Write the algorithm that orders the DAG nodes for generating optimal target code. Differentiate between basic block and flow graph. 5 Draw DAG to represent a[i] = b[i]; a[i] = & t 6 Represent the following in flow graph: i = ; sum = 0; while ( i <= 0 ) { sum += i; i++; } 7 What is global data flow analysis? 8 Name the techniques in loop optimization. 9 Explain why code optimization is called optional phase. BTL-5 Evaluating 0 Draw DAG for the statement a= ( a * b + c ) ( a * b + c ) Define basic blocks. 2 Give any four applications of DAG.

What are the properties of optimizing compilers? Analysing What is constant folding? Analysing 5 List the advantages of DAG. 6 Identify the constructs for optimization in basic block. Analysing 7 What do you mean by copy propagation? 8 What are the characteristics of peephole optimization? 9 Write three address code sequence for the assignment statement : d := ( a - b ) + ( a - c ) + ( a - c ) BTL-5 Evaluating 20 List out the criteria for code improving transformations. PART-B 2 5 (i)write the Code Generation Algorithm using Dynamic Programming and generate code for the statement x = a / ( b - c ) - g * ( e + f ). [ Assume all instructions to be unit cost ] (0) (ii)what are the advantages of DAG representation? Give example. () (i)write the procedure to perform Register Allocation and Assignment with Graph Coloring. (7) (ii)construct DAG and optimal target code for the expression (6) x = ( ( a + b ) / ( b - c ) ) - ( a + b ) * ( b - c ) + /. Perform analysis of available expressions on the following code by converting into basic blocks and compute global common sub expression elimination (i) i : = 0 (ii) a : = n - (iii) IF i < a THEN loop ELSE end (iv) LABEL loop (v) b : = I - (vi) c : = p + b (vii) d : - M[c] (viii) e : = d - 2 (ix) f : = i (x) g : = p + f (xi) M[g] : = e (xii) i : - i + (xiii) a : = n (xiv) IF i < a THEN loop ELSE end (xv) LABEL end (i)explain in detail about optimization of Basic Blocks. (7) (ii)what are the optimization techniques applied on procedure calls? Explain with example. (6) (i)generate DAG representation of the following code and list out the applications of DAG representation. (7) i = : while ( i <= 0 ) do sum += a[i]; (ii)explain - Generating code from DAG with suitable example. (6) Analysing

6 Explain peephole optimization and various code improving transformations. 7 8 9 Define a DAG. Construct a DAG and write the sequence of instructions for the expression : a + a * ( b - c ) + ( b - c ) * d (i)draw the DAG for the following three address code. (7) d = b * c e = a + b b = b * c a = e - d (ii)write short notes on structure preserving transformation of basic blocks.(6) Construct DAG and three address code for the following C program i = ; s = 0; while ( i <= 0 ) { s = s + a [i][i] i = i + ; } BTL-5 Evaluating 0 Explain global data flow analysis with necessary equations For the flow graph shown below, write the three address statements and construct the DAG. () t : = * i (2) t2 : = a[ t] () t := * i () t := b[t] (5) t5 := t2 * t (6) t6 := prod + t5 (7) prod := t6 (8) t7 := i + (9) i : = t7 (0) if i <= 20 goto () 2 Explain Principal Sources of Optimization with examples Explain various issues in the design of code generator. (i)write an algorithm for constructing natural loop of a back edge. (7) (ii)write note on simple code generator (6) PART - C Explain the data-flow analysis of structured programs. 2 Explain any four issues that crop up when designing a code generator Generate code for the following assignment using the code generator: ( a b ) + ( a c ) + ( a c ) Write global common subexpression elimination algorithm with example

Verified by :. 2. [ ] [ ].. [ ] [ ] Forwarded by Year Coordinator : Approved by HOD :