course files

40
COURSE FILES:2008-2009 BRANCH:CSE COURSE: III/IV B.TECH-II SEM SUBJECT: COMPILER DESIGN FACULITY:G.ANILKUMAR HOD PRINCIPAL TABLE OF CONTENTS 1. TITLE 2. COURSE OBJECTIVE 3. APPLICATION 4. PRE-REQISITE 5. SYALLABUS 6. REFERENCES i). BOOKS ii).JOURNALS 7. ACADEMIC CALENDAR 8. TIME TABLE 9. LESSON/TEACHING SCHEDULE 10. TOPICS COVERED BEYOND THE SYALLABUS 11. WEB LINKS 12. LECTURE NOTES 13. ASSIGNMENTS 14. Data BANK OF QUESTIONS i). PREVIOUS YEAR QUESTION PAPERS ii). RELATED QUESTIONS IN GATE&IES iii). INTERNAL QUESTION PAPERS iv). EXTERNAL QUESTION PAPERS 15. EXPERT LEACTURES/SEMINARS 16. LATEST FINDINGS 17. LAB JOURNALS AND MANUALS 18. RESULT ANALYSIS ON INTERNAL EXAMINATIONS(GRADING OF STUDENTS INTO A/B/C CATAGORIES) 19. COUNSELLING OF B/C CATEGORY STUDENTS)

Upload: softanilg

Post on 18-Nov-2014

922 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Course Files

COURSE FILES:2008-2009BRANCH:CSECOURSE: III/IV B.TECH-II SEM

SUBJECT: COMPILER DESIGN

FACULITY:G.ANILKUMAR

HOD PRINCIPAL

TABLE OF CONTENTS

1. TITLE2. COURSE OBJECTIVE3. APPLICATION4. PRE-REQISITE5. SYALLABUS6. REFERENCESi). BOOKSii).JOURNALS7. ACADEMIC CALENDAR8. TIME TABLE9. LESSON/TEACHING SCHEDULE10. TOPICS COVERED BEYOND THE SYALLABUS11. WEB LINKS12. LECTURE NOTES13. ASSIGNMENTS14. Data BANK OF QUESTIONSi). PREVIOUS YEAR QUESTION PAPERSii). RELATED QUESTIONS IN GATE&IESiii). INTERNAL QUESTION PAPERSiv). EXTERNAL QUESTION PAPERS15. EXPERT LEACTURES/SEMINARS16. LATEST FINDINGS17. LAB JOURNALS AND MANUALS18. RESULT ANALYSIS ON INTERNAL EXAMINATIONS(GRADING OF STUDENTS INTO A/B/C CATAGORIES)19. COUNSELLING OF B/C CATEGORY STUDENTS)

Page 2: Course Files

1. TITLE : COMPILER DESIGN

2.COURSE OBJECTIVE :This course introduces the basics of building a compiler using a multiphase translation process. It covers lexical analysis, parsing and translation to abstract syntax using modern parser generator technology. It discusses binding of identifiers and symbol table organization, and a variety of intermediate representations that are suitable for back-end analysis. It investigates back-end transformations and optimizations for a number of languages. Other topics include type checking, static analysis and basic run time support. Compiling is essentially a process of symbolically manipulating program representations represented by tree and graph-like data structures. Because of this, we will use tools that facilitate symbolic manipulation and definition of such structures as parser and lexical generators, and tools for generating code from pattern-based descriptions.

i. to introduce the major concept areas of language translation and compiler design.ii. to develop an awareness of the function and complexity of modern compilers.iii. to provide practical, hands-on experience in compiler design, writing and modification.Topics: Lexical Analysis, regular grammars, scanners. Syntactic Analysis, BNF notation, parsing theory. LL(k) and LR(k) parsers. Grammar transformations for parser compliance. Parser generators, translator writing systems. Semantic Analysis, symbol tables, intermediate text forms. Runtime machine models. Native code. Virtual machines. P-Code. Overview of Code Generation techniques, non-optimized. Register management, storage allocation.

APPLICATION :

Page 3: Course Files

Aims and Objectives of the Course- Describe the organization of a modern compiler.- Create efficient and correct compilers for simple procedural languages.- Understand and apply a variety of optimizations to improve the code generated by compilers.- Develop good programming skills by writing, organizing, and documenting a significant programming project.

4. Pre-Requisite:

Formal Languages and Automata Comparative Languages

5. Syllabus

COMPILER DESIGN

Page 4: Course Files

UNIT – IOverview of Compilation: Phases of Compilation – Lexical Analysis, Regular Grammar and regularexpression for common programming language features, pass and Phases of translation, interpretation,bootstrapping, data structures in compilation – LEX lexical analyzer generator.UNIT – IITop down Parsing : Context free grammars, Top down parsing – Backtracking, LL (1), recursive descentparsing, Predictive parsing, Preprocessing steps required for predictive parsing.UNIT – IIIBottom up parsing : Shift Reduce parsing, LR and LALR parsing, Error recovery in parsing , handling ambiguous grammar, YACC – automatic parser generator.UNIT – IVSemantic analysis : Intermediate forms of source Programs – abstract syntax tree, polish notation and three address codes. Attributed grammars, Syntax directed translation, Conversion of popularProgramming languages language Constructs into Intermediate code forms, Type checker.UNIT – VSymbol Tables : Symbol table format, organization for block structures languages, hashing, treestructures representation of scope information. Block structures and non block structure storageallocation: static, Runtime stack and heap storage allocation, storage allocation for arrays, strings and records.UNIT – VICode optimization : Consideration for Optimization, Scope of Optimization, local optimization, loopoptimization, frequency reduction, folding, DAG representation.UNIT – VIIData flow analysis : Flow graph, data flow equation, global optimization, redundant sub expressionelimination, Induction variable elements, Live variable analysis, Copy propagation.UNIT – VIIIObject code generation : Object code forms, machine dependent code optimization, register allocation and assignment generic code generation algorithms, DAG for register allocation.

6.REFERENCES:

I. TEXT BOOKS :1. Principles of compiler design -A.V. Aho . J.D.Ullman; Pearson Education.2. Modern Compiler Implementation in C- Andrew N. Appel, CambridgeUniversity Press.REFERENCES :1. lex &yacc – John R. Levine, Tony Mason, Doug Brown, O’reilly2. Modern Compiler Design- Dick Grune, Henry E. Bal, Cariel T. H. Jacobs,Wiley dreamtech.3. Engineering a Compiler-Cooper & Linda, Elsevier.4. Compiler Construction, Louden, Thomson

II. JOURNALS:

7. ACADAMIC CALENDAR

Page 5: Course Files
Page 6: Course Files

CSE DEPARTMENT III-B.TECH (CSE-A) Time Table

Hours 10.00am To

10.50am

10.50amTo

11.40am

11.40amTo

12.40pm

LUNCH

BREAK

1.30pmTo

2.20pm

2.20pmTo

3.10pm

3.20pmTo

4.10pm

4.10pmTo

5.00pmWeek

MON AI&NN OS ISCN

CD OOADLIBRARY/INTERNET

TUES CD OOAD OSCN

IS AI&NNLIBRARY/INTERNET

WED OOAD IS AI&NN OS CN& CT LAB

THUROS IS CD

AI&NN CN SEMINAR

FRI IS OOAD CN CD OS AI&NNLIBRARY/INTERNET

SAT OS&CD LAB CD OOAD CNLIBRARY/INTERNET

9.LESSON/TEACHING SCHEDULE

Dr.SAMUEL GEORGE INSTITUTE OF ENGINEERING & TECHNOLOGY, MARKAPUR-523316.TEACHING PLAN

NAME OF THE FACULTY:G.ANIL KUMAR SUB: COMPILER DESIGNBRANCH:C.S.E(A) YEAR: III SEMISTER:2nd

SNOWEEK TOPICS TO BE COVERED

1 7/12/09

To 12/12/09

Phase of compilation-Lexical Analysis,Regular Grammer and Regular Expression for

common Programing Language Features,pass and phase of Translation

2 14/12/09 to 19/12/09 Interpretation, bootstrapping,Data Stutuctures in compilation-Lex Lexical analyzer

generator.Context Free Grammers, TopDownParsing-Back Tracking

3 21/12/09 to 26/12/09 LL(1),Recursive Desent parsing, Predictive parsing

4 28/12/09 to 1/1/10 Preproccessing steps requied for Predictive parsing Bottem Up Parsing: Shifting Reduce

Parsing, LR

5 4/12/10 to 9/1/10 LALR Parsing, Error Recovery in Parsing, Handling Ambigous Grammer

6 18/1/10 to 23/1/10 YACC-automatic parser generator.Semantic Analysis:-Intermediate forms of source Program-

abstract Syntax tree,

7 25/1/10 to 30/1/10 polish notation and three address codes, Attributed grammers

8 1/2/10 to 6/2/10 syntax directed Translation, convertion of popular programing language

9 8/1/10 to 13/1/10 language constucts into intermediate code forms type Checker

10 15/02/10 to 20/02/10 symbol table format,organization of block structures language,hashing,tree structures

Page 7: Course Files

representation of scope information

11 22/2/10 to 27/2/10 Block structures and non block structures storage allocation: static,runtime stack and heap

storage allocation

12 1/3/10

to6/3/10

Storage allocation for arrays,strings and records,

Consideration for optimazation, scope of optimization

13 8/3/10

to13/3/10

Local optimization, loop optimization, frequency reduction,folding,DAG Representation

14 15/3/10 to 20/3/10 Data flow analysis:- Fluro graph,data flow equation, global optimization,redundant sub

expression elimination

15 22/3/10 to

27/3/10

Induction variable elements, Live variable analysis,copy propogation

Object code generation:- Object code forms,machine dependent code

optimization,register allocation and assignment

16 29/3/2010 to

3/04/2010

Register allocation and assignment generic code operation algorithms,DAG for register

allocation

FACULTY: HOD: PRINCIPAL:

10. TOPICS COVERED BEYOND THE SYALLABUS

Page 8: Course Files

11. WEB LINKS

ONLINE HELPo GNU Manualshttp://www.delorie.com/gnu/docs/

PROGRAMMING LANGUAGES AND COMPILERS ON THE WEB

The Compiler Connection http://www.compilerconnection.com/

12.LECTURE NOTES

Page 9: Course Files

13.ASSIGNMENTS

ASSIGNMENT-1

1. Explain the input buffer scheme for scanning the source program.How the use of sentinels can improve its performance?Describe in detail2. a) Explain the different phases of a compiler,showing the output of each phase, using the example of the following statement: position:=initial+rate*60.b) Compare compiler and interpreter with suitable diagrams?3. a) Explain in detail, lexical analyzer generator?b) Describe the lexical errors and various error recovery strategies with suitable examples?4. a) Consider the following fragment of 'c' code:float i,j;i=i*70+j+2;write the output at all phases of the compiler for the above 'c' codeb) Write short notes on: input buffering?5. a) Explain the boot strapping process with suitable diagrams?b) Explain how input buffering helps lexical analyzer in compilation process?6 Explain with an example, how LEX program performs lexical analysis for the following patterns in c:identifiers,comments,constants,and arthmetic operators.

ASSIGNMENT-2

1.construct the predictive parsing table for the following grammarE ->TE'E' ->+TE'/eT -> FT'T' ->*FT'/eF ->(E)/id

2. what is recursive decent parser?construct recursive desecnt parser for the following grammarE ->E+T/TT ->TF/FF ->F*/a/b3. What is ambiguous grammar?Eliminate ambiguties for the grammar:E->E+E/E*E/(E)/id.4. consider the following grammars ->0A|1B|0|1A ->0S|1B|1B ->0A|1Sconstruct the left most derivations and parse trees for the following sentencesi)0101

ii)11001015. Consider the following grammarE ->T+E|TT ->V*T|VV ->idWrite down the procedures for the nonterminals of the grammar to make a recursive decent parser.

6. Give the rules for computation of FIRST(X) and FOLLOW(X). Construct FRIST and FOLLOW sets for the following grammar.E ->TE'E' ->+TE'|eT -> FT'T' ->*FT'|eF ->(E)/id7.write an algorithm for construction of predictive parsing table?

ASSIGNMENT-3

1. What is an operator grammar? Give an example?2. Write an operator precedence parsing algorithm?3. Construct SLR parsing table for the following grammar.S ->AS|bA ->SA|a4. Define LR(k) parser.Draw and explain model of LR parser?5. Write LR parsing algorithm?6. Define precedence function.Construct precedence table and directed graph representing precedence function for operators +,*,id,$;7. Explain the stack implementation of shift reduce parsing method with an example?8. Define handle.Give suitable example?

ASSIGNMENT-4

1. write a short note on the specification of a simple type checker?2. what is a type expression?Explain the equivalence of the type expression with an appropriate examples?3. write the quadruple,triple,indirect triple for the statment a:=b*-c+b*-c.

Page 10: Course Files

4. Explain the role of intermediate code generator in compilation process?5. Write short notes on the followinga) S-attribute definations.b) L-attribute definations.c) Dependency graph.6.Describe the overloading of functions and operators with suitable examples?7.write a note on polymorphic functions?

ASSIGNMENT-5

1.compare three different storage allocation strategies?2.consider the following array declaration in c; float a[100][100];Assume that the main memory in byte addressable and that the array is stored starting form the memory address 100.what is the address of a[40][50]?3. Write an algorithm to perform lookup and insertion operation for hashed symbol table?4. what is an ordered and unordered symbol table?what is the function of symbol table in the compilation process?explain?5. What are the various attributes of a symbol table?6. What are the various operations performed on the symbol table?Explain each of them in detail?7. only one accurance of each object is allowable at a given moment during program execution justify four answer with respect to static allocation?8.Explain the hash table with temporary and permanent storage?9.Reusing the storage space for names?

ASSIGNMENT-6

1. Explain different principle source of optimization technique with suitable examples?2. what is a code optimization?what are its advantages?3. Explain briefly about folding?4.what are the problems in optimizing compiler design?5. What is DAG?Construct the DAG for the following basic blockD:=B*CE:=A+BB:=B+CA:=E-D6. what are the legal evaluation order and names for the values at the nodes for the DAG of problem(a).i) Assuming A,B, and C are alive at the end of the basic block?ii)Assuming only A is live at the end?

ASSIGNMENT-7

1. write and explain live variables analysis algorithm?2. Explain the use of algebric transformations with an example?3. Explain reducible and non-reducible flow graphs with an example?4.Explain natural loops and inner loops of a flow graphs with an example?5. Explain about data flow analysis of structural programs?6. A flow graph is useful for understanding code generation algorithm?Justify your answer with an example?7. Consider the following matrix multiplication program

ASSIGNMENT-8

1). Explain the different issuse in the design of a code generator? 2). Generate code for the following 'c' statement: 1.X=f(a)+f(a)+f(a) 2.X=f(a)/g(b,c) 3.X=f(f(a)) 4.X=++f(a);

3). Explain the concept of object code forms. 4) Generate optional machine code for the following 'c' program main() { int i,a[10]; while(i<=10)a[i]=0 }

5. Discribe various Register allocation optimization techniques with an example?

6 . Describe,how addressing modes can be used for reducing the memory access time. 7.Generate the code sequence using code generation algorithm for the following expression w:=(A-B)+(A-C)+(A-C);

Page 11: Course Files
Page 12: Course Files

Set No. 2Code No: R05320502

III B.Tech Supplimentary Examinations, Aug/Sep 2008COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. Explain with an example, how LEX program performs lexical analysis for the fol-lowing patterns in C :

identifier, comments, constants, and arithmetic operators.[16]

2. (a) Consider the following grammar.S 0A|1 B|0| 1A 0S|1 B| 1

B 0 A|1 SConstruct leftmost derivations and parse trees for the following sentences

i. 0101

ii. 1100101

(b) Consider the following grammarE T + E|T

T V T|V*

V idWrite down the procedures for the nonterminals of the grammar to make arecursive descent parser. [8+8]

3. Define precedence functions. Construct precedence table and directed graph rep-

resenting precedence functions for operators +, *, id, $. [16]

4. (a) Describe the overloading of functions and operators with suitable examples.

(b) Write a note on polymorphic functions. [8+8]

5. (a) What is an ordered and unordered symbol table? What is the function of

symbol table in the compliation process? Explain.

(b) What are the various attributes of a Symbol Table? [10+6]

6. (a) What is code optimization? What are its advantages?

(b) Explain brie y about folding.

(c) What are the problems in optimizing compiler design? [5+5+6]

7. Consider the following matrix multiplication Programbegin

for i := 1 to n dofor j:=1 to n do

1 of 2

Page 13: Course Files
Page 14: Course Files

Set No. 2Code No: R05320502

c[i, j] :=0;

for i := 1 to n dofor j:=1 to n do

for k :=1 to n doc[i, j] :=c[i , j] +a[i ,k] *b [k ,j]

end

(a) Assuming a, b, and c are allocated static storage and there are four bytes perword in a byte-addressed memory, produce three-address statements for the

above program.

(b) Find the induction variables of each loop and eliminate them wherever possible

[8+8]

8. (a) Explain the di erent issues in the design of a co de generator.

(b) Generate co de for the following C statements:

i. x= f(a) + f(a) + f(a)

ii. x= f(a) /g(b,c)

iii. x= f(f(a))

iv. x= ++f(a) [8+8]

2 of 2

Page 15: Course Files

Set No. 3Code No: R05320502

III B.Tech Supplimentary Examinations, Aug/Sep 2008COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. Explain with an example, how LEX program performs lexical analysis for the fol-lowing patterns in C :

identifier, comments, constants, and arithmetic operators.[16]

2. Construct predictive parsing table for the following grammar.E T EE +T E |

T F T [16]T F T |F (E)|id

3. (a) Explain the stack implementation of shift reduce parsing method with an

example.

(b) Define handle. Give suitable example. [10+6]

4. Write short notes on the following:

(a) S-attributed definitions.

(b) L-attributed definitions.

(c) Dependency graph. [6+6+4]

5. Only one occurrence of each ob ject is allowable at a given moment during programexecution. Justify your answer with respect to static allocation. [16]

6. Explain di erent principal sources of optimization technique with suitable exam-

ples. [16]

7. Describe, how redundant expression elimination can be done in loop optimizationtechnique, during global optimization. [16]

8. (a) Explain the di erent issues in the design of a co de generator.

(b) Generate co de for the following C statements:

i. x= f(a) + f(a) + f(a)

ii. x= f(a) /g(b,c)

iii. x= f(f(a))

iv. x= ++f(a) [8+8]

1 of 1

Page 16: Course Files

Set No. 4Code No: R05320502

III B.Tech Supplimentary Examinations, Aug/Sep 2008COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) Explain the di erent phases of a compiler, showing the output of each phase,

using the example of the following statement:position : = initial + rate * 60

(b) Compare compiler and interpreter with suitable diagrams. [10+6]

2. (a) Give the rules for computation of FIRST(X) and FOLLOW(X). Construct

FIRST and FOLLOW sets for the following grammar.E T E

E +T E |T F T

T F T |F (E)|id

(b) Write an algorithm for construction of predictive parsing table. [10+6]

3. (a) What is an operator grammar? Give an example.

(b) Write an operator precedence parsing algorithm. [6+10]

4. (a) Write a note on the specification of a simple type checker.

(b) What is a type expression? Explain the equivalence of type expressions with

an appropriate examples. [8+8]

5. (a) Explain the hash table with temporary and permanent storage.

(b) Reusing the storage space for names. [8+8]

6. (a) What is DAG? Construct the DAG for the following basic block

D := B CE :=A+B

B := B+CA := E-D

(b) What are the legal evaluation orders and names for the values at the nodes

for the DAG of problem (a).

i. Assuming A, B and C are alive at the end of the basic block?

ii. Assuming only A is live at the end? [6+10]

7. (a) What is an Induction variable? Explain with an example.

(b) Discuss how induction variables can be detected and how transformation can

be applied. [8+8]

1 of 2

Page 17: Course Files

Set No. 4Code No: R05320502

time

(b) Generate the co de sequence using Code generation algorithm for the followingexpression [8+8]

W:=(A-B)+(A-C)+(A-C)

Page 18: Course Files

Set No. 1Code No: R05320502

III B.Tech II Semester Regular Examinations, Apr/May 2008COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. Explain the input bu er scheme for scanning the source program. How the use ofsentinels can improve its performance? Describe in detail. [16]

2. Construct predictive parsing table for the following grammar.E T E

E +T E |T F T [16]

T F T |F (E)|id

3. (a) What is an operator grammar? Give an example.

(b) Write an operator precedence parsing algorithm. [6+10]

4. (a) Write a note on the specification of a simple type checker.

(b) What is a type expression? Explain the equivalence of type expressions withan appropriate examples. [8+8]

5. (a) Compare three di erent storage allocation strategies.

(b) Consider the following array declaration in ‘c’;oat a[100][100];

Assume that the main memory in byte addressable and that the array is storedstarting from the memory address 100. What is the address of a[40][50]?[8+8]

6. Explain di erent principal sources of optimization technique with suitable exam-ples. [16]

7. (a) Write and explain live variable analysis algorithm.

(b) Explain the use of algebraic transformations with an example [8+8]

8. (a) Explain the di erent issues in the design of a co de generator.

(b) Generate co de for the following C statements:

i. x= f(a) + f(a) + f(a)

ii. x= f(a) /g(b,c)

iii. x= f(f(a))

iv. x= ++f(a) [8+8]

1 of 1

8. (a) Describe, how addressing modes can be used for reducing the memory access

Set No. 2Code No: R05320502

III B.Tech II Semester Regular Examinations, Apr/May 2008COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) Explain the di erent phases of a compiler, showing the output of each phase,using the example of the following statement:position : = initial + rate * 60

(b) Compare compiler and interpreter with suitable diagrams. [10+6]

2. (a) What is recursive descent parser? Construct recursive descent parser for thefollowing grammar.

E E + T|TT TF|FF F |a|b*

(b) What is ambiguous grammar? Eliminate ambiguities for the grammar:

E E + E|E E|(E)|id. [8+8]*

3. Construct SLR parsing table for the following grammar.S AS|b

[16]A SA|a

4. (a) Write the quadruple, triple, indirect triple for the statement a := b - c + b - c* *

(b) Explain the role of intermediate code generator in compilation process. [8+8]

5. Write an algorithm to perform the table lookup and insertion operation for hashedsymbol table. [16]

6. (a) What is code optimization? What are its advantages?

(b) Explain brie y about folding.

(c) What are the problems in optimizing compiler design? [5+5+6]

7. (a) Explain reducible and non-reducible ow graphs with an example.

(b) Explain natural loops and inner loops of a ow graph with an example. [8+8]

8. (a) Explain the concept of object code forms.

(b) Generate optimal machine code for the following C program. [6+10]

main(){

int i, a[10];

while (i =10) a[i] =0}

1 of 2

Page 19: Course Files

Set No. 3Code No: R05320502

III B.Tech II Semester Regular Examinations, Apr/May 2008COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) Explain, in detail, lexical analyzer generator.

(b) Describe the lexical errors and various error recovery strategies with suitable

examples.[8+8]

2. (a) Consider the following grammar.S 0A|1 B|0| 1A 0S|1 B| 1

B 0 A|1 SConstruct leftmost derivations and parse trees for the following sentences

i. 0101

ii. 1100101

(b) Consider the following grammarE T + E|T

T V T|V*

V idWrite down the procedures for the nonterminals of the grammar to make arecursive descent parser. [8+8]

3. (a) Define LR(k) parser. Draw and explain model of LR parser.

(b) Write LR parsing algorithm. [8+8]

4. (a) Write the quadruple, triple, indirect triple for the statement a := b - c + b - c* *

(b) Explain the role of intermediate code generator in compilation process. [8+8]

5. (a) What is an ordered and unordered symbol table? What is the function of

symbol table in the compliation process? Explain.

(b) What are the various attributes of a Symbol Table? [10+6]

6. Explain di erent principal sources of optimization technique with suitable exam-

ples. [16]

7. Explain about data ow analysis of structured programs. [16]

8. (a) Explain the concept of object code forms.

1 of 2

Page 20: Course Files

Set No. 3Code No: R05320502

(b) Generate optimal machine code for the following C program. [6+10]main()

{int i, a[10];

while (i =10) a[i] =0}

2 of 2

Page 21: Course Files

Set No. 4

1 of 1

Code No: R05320502

III B.Tech Supplimentary Examinations, Aug/Sep 2008COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) Explain the di erent phases of a compiler, showing the output of each phase,

using the example of the following statement:position : = initial + rate * 60

(b) Compare compiler and interpreter with suitable diagrams. [10+6]

2. (a) Give the rules for computation of FIRST(X) and FOLLOW(X). Construct

FIRST and FOLLOW sets for the following grammar.E T E

E +T E |T F T

T F T |F (E)|id

(b) Write an algorithm for construction of predictive parsing table. [10+6]

3. (a) What is an operator grammar? Give an example.

(b) Write an operator precedence parsing algorithm. [6+10]

4. (a) Write a note on the specification of a simple type checker.

(b) What is a type expression? Explain the equivalence of type expressions with

an appropriate examples. [8+8]

5. (a) Explain the hash table with temporary and permanent storage.

(b) Reusing the storage space for names. [8+8]

6. (a) What is DAG? Construct the DAG for the following basic block

D := B CE :=A+B

B := B+CA := E-D

(b) What are the legal evaluation orders and names for the values at the nodes

for the DAG of problem (a).

i. Assuming A, B and C are alive at the end of the basic block?

ii. Assuming only A is live at the end? [6+10]

7. (a) What is an Induction variable? Explain with an example.

(b) Discuss how induction variables can be detected and how transformation can

be applied. [8+8]

1 of 2

Page 22: Course Files

II). Related Questions in GATE & IES

Set No. 4Code No: R05320502

8. (a) Describe, how addressing modes can be used for reducing the memory accesstime

(b) Generate the co de sequence using Code generation algorithm for the followingexpression [8+8]

W:=(A-B)+(A-C)+(A-C)

2 of 2

Page 23: Course Files

III).INTERNAL QUESTION PAPERS :

IV). EXTERNAL QUESTION PAPERS :

Page 24: Course Files

Set No. 1Code No: R05320502

III B.Tech II Semester Regular Examinations, Apr/May 2009COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) Explain the di erent phases of a compiler, showing the output of each phase,

using the example of the following statement:position : = initial + rate * 60

(b) Compare compiler and interpreter with suitable diagrams. [10+6]

2. (a) Consider the grammar given below.E E+E | E-E | E*E | E/E | a | bobtain left most and right most derivation for the string a+b * a+b.

(b) Explain back tracking with example. [8+8]

3. Construct SLR parsing table for the following grammar.S AS|b

[16]A SA|a

4. Write type expressions for the following types.

(a) An array of pointers to reals, where array index ranages from 1 to 100.

(b) A two dimensional array of integers (i.e. an array of array) whose rows areindexed from 0 to 9 and whose columns are indexed from -10 to 10.

(c) Functions whose domains are functions from integers to pointers to integersand whose ranges are records consisting of an integer and a character. [5+5+6]

5. Explain the following with an example.

(a) Indirection in symbol table entries

(b) Self organizing symbol tables. [8+8]

6. (a) What is DAG? Construct the DAG for the following basic blockD := B C*

E :=A+BB := B+C

A := E-D

(b) What are the legal evaluation orders and names for the values at the nodesfor the DAG of problem (a).

i. Assuming A, B and C are alive at the end of the basic block?

ii. Assuming only A is live at the end? [6+10]

7. (a) Explain in detail the procedure that eliminate global common sub - expression.

1 of 2

Set No. 1Code No: R05320502

(b) What are the applications of du and ud chains. [8+8]

8. (a) What are the various addressing modes available? GIve some example machine

instructions which reduces memory access time.

(b) Explain the concept of label tree of code generation. [8+8]

2 of 2

Page 25: Course Files

Set No. 2Code No: R05320502

III B.Tech II Semester Regular Examinations, Apr/May 2009COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) Write a short notes on token specification.

(b) Draw a NFA for a * | b *. [8+8]

2. (a) What is recursive descent parser? Construct recursive descent parser for thefollowing grammar.

E E + T|TT TF|FF F |a|b*

(b) What is ambiguous grammar? Eliminate ambiguities for the grammar:E E + E|E E|(E)|id. [8+8]*

3. Construct LALR parsing table for the following grammarS CC

[16]C cC|d

4. (a) Which of the following recursive type expressions are equivalent? Justify youranswer?

e =integer e ; e =integer ( integer e ); e =integer ( integer1 1 2 2 3

e ).1

(b) Suppose that the type of each identifier is a sub range of integers for expressionswith the operators +,-,*,div and mod as in pascal. Write type-checking rules

that assign to each sub expression, the subrange its value must lie in.[8+8]

5. Draw and explain the symbol table organization for C language with a program

block. [16]

6. Explain di erent principal sources of optimization technique with suitable exam-

ples. [16]

7. Consider the following program which counts the primes form 2 to n using the sieve

method on a suitably large arraybegin

read nfor i : = 2 to n do

a[i] : = true / * initialize */count: = 0;

1 of 2

Page 26: Course Files

Set No. 2Code No: R05320502

for i : 2 to n ** .5 doif a [i] then /* i is a prime */

begincount := count +1

for j : = 2 * i to n by i doa[j] : =false/ * j is divisible by i */

end ;print count

end

(a) Propagate out copy statements wherever possible.

(b) Is loop jumping possible? If so, do it.

(c) Eliminate the induction variables wherever possible. [5+5+6]

8. (a) What are the various addressing modes available? GIve some example machine

instructions which reduces memory access time.

(b) Explain the concept of label tree of code generation. [8+8]

2 of 2

Page 27: Course Files

Set No. 3Code No: R05320502

III B.Tech II Semester Regular Examinations, Apr/May 2009COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) Construct a DFA for (a * + b *) abb.

(b) Write a lex program to identify comments in the program. [8+8]

2. (a) Construct predictive parse table for the following grammar.+ |

* |* | |

(b) What are the limitations of recursive descent porser. [8+8]

3. (a) What are the common con icts that can be encountered in shift - reduce

parser.

(b) Construct SLR parsing table for the following grammar.| | | |( ) | | [8+8]

4. (a) What is a syntax tree? Write syntax directed definition for constructing asyntax tree for an expression. The grammar for an expression is given below.

+ | - |( ) | |

(b) Write a detail notes on type conversion. [8+8]

5. Explain the importance of the following attributes of a symbol table.

(a) Variable name

(b) Object time address

(c) Type of a symbol table

(d) Link field. [16]

6. (a) Write the three-address code for the following code.

beginPROD: = 0;

I: =1;do

beginPROD:=PROD + A[I] B[I];I:=I+1;

Endwhile I =20

end

1 of 2

Page 28: Course Files

Set No. 3Code No: R05320502

(b) Write an algorithm for partition of basic blocks and apply it on the abovederived three-address code. [8+8]

7. (a) Generate the ow-graphs for the following expressions:S- id: = E |S; S| if E then S else S | do S while E

E- id + id |id

(b) Mention data- ow equations for reaching definitions for the above expressions.[8+8]

8. State and explain di erent machine dependent co de optimization techniques. [16]

2 of 2

Page 29: Course Files

Set No. 4Code No: R05320502

III B.Tech II Semester Regular Examinations, Apr/May 2009COMPILER DESIGN

(Computer Science & Engineering)Time: 3 hours Max Marks: 80

Answer any FIVE QuestionsAll Questions carry equal marks

1. (a) What is LEX? Explain, in detail, di erent sections of LEX program.

(b) Write regular expressions for the following patterns. Use auxiliary definitions

wherever convenient.

i. the set of words having a,e,i,o,u appearing in that order, although not

necessarily consecutively.

ii. comments in C. [8+8]

2. (a) What are the di culties in top down parsing? Explain in detail.

(b) Consider the following grammar

( ) ||

Construct leftmost derivations and parse trees for the following sentences:

i. (a,(a,a))

ii. (a,((a,a),(a,a))). [8+8]

3. (a) Explain canonical LR parsing.

(b) Explain brie y, precedence functions. construct the precedence graph usingthe following prededence table. [8+8]

+ * ( ) id $

f 2 3 0 4 4 0

g 1 3 5 0 5 0

4. (a) Write a S - attributed grammar to connect the fopllowing grammar with prefixrotator

L EE E+T | E-T | TT T*F | T/F | F

F P F | PP (E)

P id.

(b) Construct triples of an expression: * - ( + ). [8+8]

5. (a) What is heap storage allo cation? Explain in detail.

(b) Explain about implicit and explicit storage requests. [8+8]

6. (a) Explain in detail the Optimization technique “strength reduction”.

1 of 2

Page 30: Course Files

Set No. 4Code No: R05320502

(b) What is a DAG. Explain its applications. [8+8]

7. (a) What is an Induction variable? Explain with an example.

(b) Discuss how induction variables can be detected and how transformation canbe applied. [8+8]

8. Generate code for the following ’C’ statements

(a) x = f(a) + f(a) + f(a)

(b) x = f(a) / g(b,c)

(c) x = f(f(a))

(d) x = ++f(a) [16]

2 of 2

Page 31: Course Files

15. EXPERT LEATURES/ SEMINARS

Page 32: Course Files

16. LATEST FINDINGS :

Page 33: Course Files

17. LAB JOUNALS AND MANUALS

Page 34: Course Files

18. RESULT ANALYSIS ON INTERNAL EXAMINATIONS(GRADING OF STUDENTS INTO A/B/C CATEGORIES)

Page 35: Course Files
Page 36: Course Files