Sunteți pe pagina 1din 33

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)
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 :
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
UNIT – I
Overview of Compilation: Phases of Compilation – Lexical Analysis, Regular Grammar and regular
expression for common programming language features, pass and Phases of translation, interpretation,bootstrapping,
data structures in compilation – LEX lexical analyzer generator.
UNIT – II
Top down Parsing : Context free grammars, Top down parsing – Backtracking, LL (1), recursive descentparsing, Predictive
parsing, Preprocessing steps required for predictive parsing.
UNIT – III
Bottom up parsing : Shift Reduce parsing, LR and LALR parsing, Error recovery in parsing , handling ambiguous grammar,
YACC – automatic parser generator.
UNIT – IV
Semantic analysis : Intermediate forms of source Programs – abstract syntax tree, polish notation and three address
codes. Attributed grammars, Syntax directed translation, Conversion of popular
Programming languages language Constructs into Intermediate code forms, Type checker.
UNIT – V
Symbol Tables : Symbol table format, organization for block structures languages, hashing, tree
structures representation of scope information. Block structures and non block structure storage
allocation: static, Runtime stack and heap storage allocation, storage allocation for arrays, strings and records.
UNIT – VI
Code optimization : Consideration for Optimization, Scope of Optimization, local optimization, loop
optimization, frequency reduction, folding, DAG representation.
UNIT – VII
Data flow analysis : Flow graph, data flow equation, global optimization, redundant sub expression
elimination, Induction variable elements, Live variable analysis, Copy propagation.
UNIT – VIII
Object 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, Cambridge
University Press.
REFERENCES :
1. lex &yacc – John R. Levine, Tony Mason, Doug Brown, O’reilly
2. 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
CSE DEPARTMENT
III-B.TECH (CSE-A) Time Table
Hours 10.00am 10.50am 11.40am L 1.30pm 2.20pm 3.20pm 4.10pm
To To To U To To To To
Week
10.50am 11.40am 12.40pm N 2.20pm 3.10pm 4.10pm 5.00pm
C CN LIBRARY/
MON AI&NN OS IS CD OOAD
H INTERNET
CN LIBRARY/
TUES CD OOAD OS B IS AI&NN
INTERNET
R
WED OOAD IS AI&NN E OS CN& CT LAB
A
OS IS CD K
THUR CN SEMINAR
AI&NN

LIBRARY/
FRI IS OOAD CN CD OS AI&NN
INTERNET

LIBRARY/
SAT OS&CD LAB CD OOAD CN
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 DESIGN BRANCH:C.S.E(A) YEAR: III SEMISTER:2nd

SNO
WEEK TOPICS TO BE COVERED

1 7/12/09 Phase of compilation-Lexical Analysis,Regular Grammer and Regular Expression for

To 12/12/09 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 Redu

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 P

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

representation of scope information


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

storage allocation
12 1/3/10 Storage allocation for arrays,strings and records,

to6/3/10 Consideration for optimazation, scope of optimization


13 8/3/10 Local optimization, loop optimization, frequency reduction,folding,DAG Representati

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

expression elimination
15 22/3/10 to Induction variable elements, Live variable analysis,copy propogation

27/3/10 Object code generation:- Object code forms,machine dependent code

optimization,register allocation and assignment

16 29/3/2010 to Register allocation and assignment generic code operation algorithms,DAG for registe

3/04/2010 allocation

FACULTY: HOD: PRINCIPAL:

10. TOPICS COVERED BEYOND THE SYALLABUS


11. WEB LINKS

• ONLINE HELP
o GNU Manuals
http://www.delorie.com/gnu/docs/

• PROGRAMMING LANGUAGES AND COMPILERS ON THE WEB

The Compiler Connection


http://www.compilerconnection.com/

12.LECTURE NOTES
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 detail
2. 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' code
b) 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 grammar


E ->TE'
E' ->+TE'/e
T -> FT'
T' ->*FT'/e
F ->(E)/id

2. what is recursive decent parser?construct recursive desecnt parser for the following grammar
E ->E+T/T
T ->TF/F
F ->F*/a/b
3. What is ambiguous grammar?Eliminate ambiguties for the grammar:
E->E+E/E*E/(E)/id.
4. consider the following grammar
s ->0A|1B|0|1
A ->0S|1B|1
B ->0A|1S
construct the left most derivations and parse trees for the following sentences
i)0101

ii)1100101
5. Consider the following grammar
E ->T+E|T
T ->V*T|V
V ->id
Write 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'|e
T -> FT'
T' ->*FT'|e
F ->(E)/id
7.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|b
A ->SA|a
4. 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.
4. Explain the role of intermediate code generator in compilation process?
5. Write short notes on the following
a) 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 block
D:=B*C
E:=A+B
B:=B+C
A:=E-D
6. 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);
Code No: R05320502
Set No. 2
III B.Tech Supplimentary Examinations, Aug/Sep 2008
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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| 1
A 0S|1 B| 1
B 0 A|1 S
Construct leftmost derivations and parse trees for the following sentences
i. 0101
ii. 1100101
(b) Consider the following grammar
E T + E|T
T V * T|V
V id
Write down the procedures for the nonterminals of the grammar to make a
recursive 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 Program


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

1 of 2
Code No: R05320502
Set No. 2
c[i, j] :=0;

for i := 1 to n do
for j:=1 to n do
for k :=1 to n do
c[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 per
word 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
Code No: R05320502
Set No. 3
III B.Tech Supplimentary Examinations, Aug/Sep 2008
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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 TE
E +T E |
T FT [16]
T FT|
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 program
execution. 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 optimization


technique, 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
Code No: R05320502
Set No. 4
III B.Tech Supplimentary Examinations, Aug/Sep 2008
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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 TE
E +T E |
T FT
T FT|
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 C
E :=A+B
B := B+C
A := 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
Code No: R05320502
Set No. 4

time
(b) Generate the co de sequence using Code generation algorithm for the following
expression [8+8]
W:=(A-B)+(A-C)+(A-C)
Code No: R05320502
Set No. 21
8. (a)III
Describe, how
B.Tech II addressing
Semester modes
Regular can be used Apr/May
Examinations, for reducing
2008the memory access
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks

Explain
1. (a) the the
Explain input
di bu er scheme
erent phases of fora scanning
compiler,the sourcethe
showing program.
output How thephase,
of each use of
sentinels canthe
using improve
exampleits of
performance?
the followingDescribe in detail. [16]
statement:
position : = initial + rate * 60
2. Construct predictive parsing table for the following grammar.
(b)
E T Compare
E compiler and interpreter with suitable diagrams. [10+6]
E +T E |
2. (a) What is recursive descent parser? Construct recursive descent parser for the
T FT [16]
following grammar.
T FT|
E E + T|T
F (E)|id
T TF|F
F isFan operator
3. (a) What * |a|b
grammar? Give an example.
(b)
(b) What
Write is
anambiguous grammar?parsing
operator precedence Eliminate ambiguities
algorithm. for the grammar:
[6+10]
E E + E|E * E|(E)|id. [8+8]
4. (a) Write a note on the specification of a simple type checker.
3. Construct SLR parsing table for the following grammar.
(b) What is a type expression? Explain the equivalence of type expressions with
S AS|b
an appropriate examples. [8+8]
[16]
A SA|a
5. (a) Compare three di erent storage allocation strategies.
4. (a) Write the quadruple, triple, indirect triple for the statement a := b * -c+b * -c
(b) Consider the following array declaration in ‘c’;
(b) Explain the role of intermediate code generator in compilation process. [8+8]
oat a[100][100];
Assume
5. Write an thattotheperform
algorithm main memory
the tableinlookup
byte addressable andoperation
and insertion that the array is stored
for hashed
symbolstarting
table. from the memory address 100. What is the address of a[40][50]?[8+8] [16]

6.
6. Explain
(a) Whatdiiserent
code principal sources
optimization? of optimization
What technique with suitable exam-
are its advantages?
ples. [16]
(b) Explain brie y about folding.
7. (a)(c)
Write and
What areexplain live variable
the problems analysis compiler
in optimizing algorithm.design? [5+5+6]
(b) Explain the use of algebraic transformations with an example [8+8]
7. (a) Explain reducible and non-reducible ow graphs with an example.
8. (a)(b)
Explain thenatural
Explain di erentloops
issues
andininner
the design
loops of
of aa co
owdegraph
generator.
with an example. [8+8]
(b) Generate co de for the following C statements:
8. (a) Explain the concept of object code forms.
i. x= f(a) + f(a) + f(a)
(b) Generate optimal machine code for the following C program. [6+10]
ii. x= f(a) /g(b,c)
main()
{iii. x= f(f(a))
iv. int
x= i,++f(a)
a[10]; [8+8]
while (i =10) a[i] =0
}

1 of 21
Code No: R05320502
Set No. 3
III B.Tech II Semester Regular Examinations, Apr/May 2008
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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| 1
A 0S|1 B| 1
B 0 A|1 S
Construct leftmost derivations and parse trees for the following sentences
i. 0101
ii. 1100101
(b) Consider the following grammar
E T + E|T
T V * T|V
V id
Write down the procedures for the nonterminals of the grammar to make a
recursive 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
Code No: R05320502
Set No. 3
(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
Set No. 4
Code No: R05320502

III B.Tech Supplimentary Examinations, Aug/Sep 2008


COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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 TE
E +T E |
T FT
T FT|
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 C
E :=A+B
B := B+C
A := 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 21
Code No: R05320502
Set No. 4
8. (a) Describe, how addressing modes can be used for reducing the memory access
time
(b) Generate the co de sequence using Code generation algorithm for the following
expression [8+8]
W:=(A-B)+(A-C)+(A-C)

II). Related Questions in GATE & IES

2 of 2
III).INTERNAL QUESTION PAPERS :

IV). EXTERNAL QUESTION PAPERS :


Code No: R05320502
Set No. 1
(b)
III What
B.Tech
areIIthe
Semester
applications
Regular
of Examinations,
du and ud chains.
Apr/May
[8+8] 2009
COMPILER DESIGN
8. (a) What are the various(Computer
addressingScience
modes & available? GIve some example machine
Engineering)
Time: 3 hoursinstructions which reduces memory access time. Max Marks: 80
(b) Explain the concept ofAnswer
label tree
anyofFIVE
code Questions
generation. [8+8]
All 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 | b
obtain 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 are
indexed from 0 to 9 and whose columns are indexed from -10 to 10.
(c) Functions whose domains are functions from integers to pointers to integers
and 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 block
D := B * C
E :=A+B
B := B+C
A := 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) Explain in detail the procedure that eliminate global common sub - expression.

21 of 2
Code No: R05320502
Set No. 2
III B.Tech II Semester Regular Examinations, Apr/May 2009
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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 the
following grammar.
E E + T|T
T TF|F
F 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 grammar


S CC
[16]
C cC|d

4. (a) Which of the following recursive type expressions are equivalent? Justify your
answer?
e1 =integer e 1
; e 2 =integer ( integer e 2
); e 3 =integer ( integer
e1 ).
(b) Suppose that the type of each identifier is a sub range of integers for expressions
with 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 array
begin

read n
for i : = 2 to n do
a[i] : = true / * initialize */
count: = 0;

1 of 2
Code No: R05320502
Set No. 2
for i : 2 to n ** .5 do
if a [i] then /* i is a prime */
begin
count := count +1
for j : = 2 * i to n by i do
a[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
Code No: R05320502
Set No. 3
III B.Tech II Semester Regular Examinations, Apr/May 2009
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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 a
syntax 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.


begin
PROD: = 0;
I: =1;
do
begin
PROD:=PROD + A[I] B[I];
I:=I+1;
End
while I =20
end

1 of 2
Code No: R05320502
Set No. 3
(b) Write an algorithm for partition of basic blocks and apply it on the above
derived 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
Code No: R05320502
Set No. 4
III B.Tech II Semester Regular Examinations, Apr/May 2009
COMPILER DESIGN
(Computer Science & Engineering)
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All 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 using
the following prededence table. [8+8]
+ * ( ) id $
f230440
g135050

4. (a) Write a S - attributed grammar to connect the fopllowing grammar with prefix
rotator
L E
E E+T | E-T | T
T T*F | T/F | F
F P F|P
P (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
Code No: R05320502
Set No. 4
(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 can
be 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
15. EXPERT LEATURES/ SEMINARS
16. LATEST FINDINGS :
17. LAB JOUNALS AND MANUALS
18. RESULT ANALYSIS ON INTERNAL EXAMINATIONS(GRADING OF
STUDENTS INTO A/B/C CATEGORIES)

S-ar putea să vă placă și