You are on page 1of 8

Code No: 36024 R05 Set No.

2
III B.Tech II Semester Supplimentary Examinations,January 2010
COMPILER DESIGN
Computer Science And Engineering
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
?????

1. (a) Explain the different issues in the design of a code generator.


(b) Generate code 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. (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]

3. (a) Consider the following fragment of ‘C’ code:


oat 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. [10+6]

4. Construct a DFA whose states are the canonical collection of LR(1) items for the
following augmented grammer:
S→A
A →BA |∈
B → aB |b [16]

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


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

6. Explain code-improving transformation techniques with suitable examples. [16]

7. (a) Write a CFG for the ‘while’ statement in ‘c’ language


(b) Compute FIRST and FOLLOW sets for all nonterminals in the following gram-
mar.
S → Aa|bAc|Bc|bBa
A→d [8+8]
B→d
8. Consider the following matrix multiplication Program
begin

1
Code No: 36024 R05 Set No. 2
for i := 1 to n do
for j:=1 to n do
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]

?????

2
Code No: 36024 R05 Set No. 4
III B.Tech II Semester Supplimentary Examinations,January 2010
COMPILER DESIGN
Computer Science And Engineering
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
?????

1. (a) Compare top down parsing and bottom up parsing.


(b) Explain backtracking in top down parsing with an example. [8+8]

2. 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]

3. (a) Write an algorithm for linear search with respect to an ordered symbol table
organization.
(b) Write an algorithm for binary search with respect to an ordered symbol table
organization. [8+8]

4. (a) What is regular expression? Write regular expressions for the following pat-
terns:
identifiers and float constants.
(b) Define lexeme, token and pattern. Identify the lexemes, that make up the
tokens in the following program segment. Indicate corresponding token and
pattern. [6+10]

void swap(int i, int j)


{
int t;
t=i;
i=j;
j=t;
}

5. 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

3
Code No: 36024 R05 Set No. 4
a[i] : = true / * initialize */
count: = 0;
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) Translate the above program into three address statements assuming a is al-
located static storage.
(b) Construct a flow graph from the three address statements and indicate the
back edges and their natural loops [8+8]

6. (a) What is Unreachable Code? Explain a technique for the removal of unreach-
able instructions with an example
(b) Explain Flow-of-Control Optimization technique [8+8]

7. (a) Write an algorithm to implement the elimination of redundant subexpressions


in constructing a DAG?
(b) Construct the DAG for the following code:
A[I]:=B

P := C
D:=A[J]
E:= *P

P:=A[I]
Assume that
i. P can point anywhere,
ii. P points to only B or D.
Do not forget to show the implied order constraints. [8+8]

8. Construct SLR parsing table for the following grammar.


S → AS|b
[16]
A → SA|a

?????

4
Code No: 36024 R05 Set No. 1
III B.Tech II Semester Supplimentary Examinations,January 2010
COMPILER DESIGN
Computer Science And Engineering
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
?????

1. Explain different principal sources of optimization technique with suitable exam-


ples. [16]

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. [10+6]

3. (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
}

4. Construct SLR parsing table for the following grammar.


E → E + T |T
T → T ∗ F |F [16]
F → (E)| id
5. Construct predictive parsing table for the following grammar.
E → T E0
E0 → +T E0 |ε
T → F T0 [16]
T0 → ∗ F T0 |ε
F → (E)|id
6. Explain the following:

(a) Common sub-expression elimination


(b) Dead-code elimination
(c) Renaming of temporary variables
(d) Interchange of two independent adjacent statements [4+4+4+4]

7. What is the necessity of creating an intermediate code form during the compiletion
process? Describe the various forms of intermediate code highlighting the utility of
each form. [16]

5
Code No: 36024 R05 Set No. 1
8. (a) Compare three different 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 stored
starting from the memory address 100. What is the address of a[40][50]?[8+8]

?????

6
Code No: 36024 R05 Set No. 3
III B.Tech II Semester Supplimentary Examinations,January 2010
COMPILER DESIGN
Computer Science And Engineering
Time: 3 hours Max Marks: 80
Answer any FIVE Questions
All Questions carry equal marks
?????

1. Explain the following concepts:

(a) Next-use information


(b) Register descriptors
(c) Address descriptors.
(d) Register interference [4+4+4+4]

2. (a) Explain the different phases of a compiler, showing the output of each phase
using the example for the statement:
x=(a+b) * (c+d)
(b) Write short notes on bootstrapping process. [8+8]

3. (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]

4. (a) What is loop invariant operation? Write an algorithm for detecting loop in-
variant computations.
(b) Consider the following program fragment code:
int p=1, k=0, n;
while(k<n)
{
p=2*p;
k=k+1;
}
Apply the invariant operation elimination on the above program segment:
[8+8]

5. C onstruct LALR Parsing table for the following grammar


S → Aa|bAc|Bc|bBa
A →d
B→d [16]

6. (a) What is an induction variable? Explain with an example


(b) Draw flow graph and eliminate induction variables, wherever possible, of the
following program code:
begin

7
Code No: 36024 R05 Set No. 3
read n
for i : = 2 to n do
a[i] : = true / * initialize */
count: = 0;
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 [6+10]

7. (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]

8. Write short notes on the following:

(a) S-attributed definitions.


(b) L-attributed definitions.
(c) Dependency graph. [6+6+4]

?????

You might also like