JNTU exam papers B-Tech Examinations, IIIrd sem Computer graphics, Aug/Sep 2008

JNTU III B.Tech Supplimentary Examinations, Aug/Sep 2008

COMPILER DESIGN

(Computer Science & Engineering)

SET-II

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

identifier, comments, constants, and arithmetic operators.

 

2. (a) Consider the following grammar.

S ! 0A|1B|0| 1

A ! 0S|1B| 1

B ! 0A|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.

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

resenting precedence functions for operators +, *, id, $.

 

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

(b) Write a note on polymorphic functions.

 

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?

 

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

(b) Explain briefly about folding.

(c) What are the problems in optimizing compiler design?

 

7. Consider the following matrix multiplication Program

begin

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

Leave a Comment