Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

B.E.

(with Credits)-Regular-Semester 2012 - Computer Technology /


Computer Science and Engineering Sem VIII
CT 801 / CSE802 - Compiler Construction
P. Pages : 2 GUG/S/17/7030
Time : Three Hours *2263* Max. Marks : 80
_______________________________________ ______________________________
Notes : 1. All questions carry equal marks.
2. Due credit will be given to neatness and adequate dimensions.
3. Assume suitable data wherever necessary.

1. a) Explain the front end and back end of phases of compiler with examples. 8
b) Describe cross compiler in details with example. 8
OR
2. a) Explain different compiler writing tools LEX and YACC. 8
b) Write a LEX to recognize positive number, negative number and negative real number. 8
3. a) Construct the parsing table for the following grammar : 10
E ET|T
T  TF| F
F  (E ) | id
Also show the moves made by these LL(1) parser on input id  id  id .
b) Show that no left recursive grammar can be LL(1). 6
OR
4. a) Construct LALR parsing table for the following grammar 10
S  CC
C  eC
Cd
b) Write an algorithm for construction of parsing table for CLR parser. 6
5. a) Translate following statement into intermediate code. 10
A[I, J, K] = B[I, J] + C[I + J + K]
where
A is 3D array of size 10 x 10 x 10
B is 2D array of size 10 x 10
C is 1D array of size 30
bpw = 2
b) Write the translation scheme for 'for' loop in C programming language. 6
OR
6. a) Give translation scheme & generate three address code for the following program 10
Repeat
while (A < C and B < D) do
if A==1 then C = C + 1
else
while A < = D do
A=A+3
until B > D or C < A
GUG/S/17/7030 1 P.T.O
b) What is synthesized attributes and inherited attributes ? Explain with example. 6

7. a) Explain various error recovery techniques used by compiler. 8

b) Write labelling algorithm to determine the minimum number of registers required to 8


evaluate the tree. Use labelling algorithm to determine the number of registers required to
evaluate following expression
Z  X  Y  XYV
OR
8. a) Generate code for the following sequence of three address code statement using simple 8
code generation algorithm.
T1  A  B
T2  C  D
T3  E  T2
T4  T  T3

b) Write Heuristic algorithm for optimal ordering of code. Explain the algorithm by taking 8
an example.

9. a) Consider a flow graph 10

I= 2 B1
J = I+ 1

B2 I= 1

B3 J=J+1

B4 J=J–4

B5

Compute IN & OUT using iterative solution of data flow equation after second iteration.
Also calculate id-chain for B4.

b) How do you eliminate local common sub-expression ? Give suitable example. 6


OR
10. a) Explain the algorithm for detecting & eliminating induction variables. 10

b) Write the steps or algorithm for partitioning a sequence of three-address statement into 6
basic blocks.

*********

GUG/S/17/7030 2
B.E. (with Credits) Computer Science and Engineering / Computer Technology Engineering Sem
VIII
CSE 802 / CT 801 - Compiler Construction

P. Pages : 3 GUG/W/17/7030
Time : Three Hours *2181* Max. Marks : 80
_____________________________________________________________________
Notes : 1. All questions carry equal marks.
2. Due credit will be given to neatness and adequate dimensions.
3. Assume suitable data wherever necessary.
4. Illustrate your answers wherever necessary with the help of neat sketches.

1. a) Explain the phases of compiler? And how the following statement will be translated into 8
every phase position = initial + rate * 60.

b) What is cross compiler? Why is boat strapping required to generate cross compilers? 8

OR

2. a) Explain the backtracking with example. 8

b) What do you mean by a left recursive grammar? Check whether the following grammar is 8
left recursive. If so obtain the non left recursive grammar for it.

E  ET/T
T  T  F/F
F  ( E ) / id

3. a) Obtain LL (1) parsing table for the following grammar. 10

S  abSa / aaAc / b
A  abAb / 

b) Comment on following statements :- No left recursive grammar can be LL(1) 6

OR

4. a) Construct CLR parsing table for the following grammar. 10

S  CC
C  eC
Cd

b) What is viable prefix? Calculate all viable prefix for the string "id+id*id" using following 6
grammar.

E  E  E / E  E / id

GUG/W/17/7030 1 P.T.O
5. a) Write SDTS for the following: 8

i) If-then-else statement.

ii) While statement.

b) Give translation scheme and generate three address code for following code fragment. 8

for (I  1; I  10 ; I   )
if (a  b) then x  y  z

OR

6. a) Translate following statement into three address code 10

A [ I, J, K]  B [I, C [K ]]  C [ I ]
assume array
A of size 10x20x30
B of size 20x30
C of size 30
and bpw = 4

b) What is Dependency Graph? Explain with example. 6

7. a) Explain phrase level error recovery for LR parser with suitable example. 8

b) Write about the following Peephole optimizations:- 8

i) Redundant loads and stores.


ii) Unreachable code.
iii) Algebraic simplification
iv) Multiple jumps

OR

8. a) Explain the working or implementation of labelling algorithm for the statement given 6
below:-

X = (a + b) - ((c + d) - e)

b) State whether the order of computation affects the cost of generated code. If yes find an 10
optimal order of computation and generate code for the following sequence of three
address code.

t1  a  b
t2  c  d
t3  e  t 2
t 4  t1  t 3

GUG/W/17/7030 2
9. a) Using detecting and eliminating induction variables algorithm obtain modified flow graph 10
for the following flow graph.
PROD=0
I=1

T 2 = addr (A) _ 4
T 4 = addr (B) _ 4

T1 = 4 * I
T 3 = T 2 [T 1]
T 5 = T 4 [T 1]
T6 = T3 * T5
PROD = PROD + T 6
I=I+1
if I <= 20 geto B2

b) Write a short note on 6

i) Loop jamming

ii) Loop unrolling

iii) Dominator

OR

10. a) Explain the method to eliminate global common subexpressions. 8

b) Define leader statement? Write the steps for partitioning a sequence of three-address 8
statements into basic blocks.

********

GUG/W/17/7030 3 P.T.O
GUG/W/17/7030 4
B.E.- Computer Technology / Computer Science and Engineering Sem VIII
CSE802 / CT801 : Compiler Construction

P. Pages : 3 GUG/S/18/7030
Time : Three Hours *2146* Max. Marks : 80
_______________________________________ ______________________________
Notes : 1. All questions carry equal marks.
2. Assume suitable data wherever necessary.
3. Illustrate your answers wherever necessary with the help of neat sketches.

1. a) Explain the different phases of compiler with the help of suitable diagram. Illustrate the 8
translation of the following statement on all the phase of compiler a  b  c  60 .

b) Describe how various phases could be combined as a pass in a compiler. 8

OR

2. a) Explain compiler writing tools : LEX and YACC. 8

b) What is front end and back end of a compiler ? What are advantages of breaking up the 8
compiler functionally into these two distinct stages.

3. a) Consider the following grammar G 12


E  TE
E  TE/ 
T  FT
T  FT/ 
F  (E) / id
where  denotes the empty string of symbols.
i) Compute FIRST and FOLLOW for each non-terminal of the grammar.
ii) Construct a predictive parsing table for grammar.
iii) Show the sequence made by the parser for the string w = id + id * id.

b) Show that no left-recursive grammar can be LL(1). 4

OR

4. a) Consider the following grammar 10


S  AaAb / BbBa
A
B
i) Construct LR(1) set of items.
ii) Construct LR(1) parsing table (CLR(1) parsing table)

b) Describe the concept of predictive parsing and shift reduce parsing. 6

GUG/S/18/7030 1 P.T.O
5. a) Explain Syntax Directed Definations ? Write syntax directed definition for a given 8
statement
E ET
ET
T  TF
TF
F  id

b) Give translation scheme and generate three address code for the following program while 8
(B > D and A < C) do
if (A > Z) then
C=C+1;
else
while (A < D) do
A=A+Z;

OR

6. a) Translate following statement into three address code. 8


A[I, J, K] = B[I, C[K]] + C[I]
assume array A of size 10 x 20 x 30
B of size 20 x 30
C of size 30
and bpw = 4

b) Write SDTS for the following - 8


i) for statement
ii) do-while statement

7. a) Explain various error recovery techniques used by compiler. 8

b) Generate code for the following sequence of three address code statement using simple 8
code generation algorithm
T1  A  B
T2  C  D
T3  e  T2
T4  T1  T3

OR

8. a) Write heuristic algorithm for optimal ordering of code. Explain the algorithm by taking an 8
example.

b) Write labelling algorithm to determine the minimum number of registers required to 8


evaluate the tree.
Use labelling algorithm to the number of registers required to evaluate following
expression z  x  y  x  y  v .

GUG/S/18/7030 2
9. a) Write algorithm for detecting & eliminating induction variables. Using this algorithm 16
obtain modified flow graph for the following.
PROD = 0
I=1

T2 = addr (A) - 4
T4 = adder (B) - 4

T1 = 4 * I
T3 = T2 [T1]
T5 = T4 [T1]
T6 = T3 * T5
PROD = PROD + T6
I=I+1
if I < 20 goto B3

OR

10. a) Consider flow graph below 10


B1 I=2
J=I+1

B2 I=1

B3 J=J+1

B4 J=J-4 I=I+1 B5

Compute IN and OUT using iterative solution of data flow equation after second iteration.
Also calculate UD-chain for B3.

b) What is leader statement ? Write the steps or algorithm for partitioning a sequence of three 6
- address statement into basic blocks.

**********

GUG/S/18/7030 3 P.T.O
GUG/S/18/7030 4
B.E. Computer Technology / Computer Science & Engineering Eighth Semester
CSE802 - Compiler Construction
P. Pages : 2 GUG/W/18/1997
Time : Three Hours *1529* Max. Marks : 80
_______________________________________ ______________________________
Notes : 1. All questions are compulsory.
2. All questions carry equal marks.
3. Assume suitable data wherever necessary.
4. Illustrate your answers wherever necessary with the help of neat sketches.

1. a) Explain with neat diagram various stages of phases of compiler. Also explain analysis and 8
synthesis tasks performed by compiler.

b) Explain the following with appropriate example : 8


i) Boot Strapping. ii) Cross compiler
OR
2. a) Explain the following compiler writing tools 8
i) LEX tool ii) YACC tool

b) Comment on the following statements : A multipass compiler can be made less space then 8
a single pass compiler.

3. a) Construct LL(1) parsing table for the following grammar. 8


S → aAB | bA | 
A → aAb | 
B → bB | C

b) Comment on the following statements : 8


i) No left recursive grammar can be LL(1)
ii)  -free LL(1) grammar can parser a sentence without FOLLOW( ) set.
OR
4. a) Describe implementation of CLR parsing table. 6
b) Frame the transition table (transition diagram), Action table and Goto table for the 10
grammar
S → AaAb
S → BbBa
A →
B→

5. a) Give the syntax directed definition with the synthesized attribute val Draw the annotated 8
parse tree for the expression 2 + 3  5
E →E+T E  val = E  val + T  val
E→T E  val = T  val
T → TF T  val = T  val + F  val
T→F T  val = F  val
F → id F  val = num  lexval

GUG/W/18/1997 1 P.T.O
b) Generate three-address code for the following switch statement. 8
switch (i + j)
{
case 1 : x = y + z
case 2 : u = v + w
default : p = q + r
}
OR
6. a) Write the translation scheme for the given array reference and write TAC for the given 8
multidimensional array, arrays are statically allocated and size of B is 10 x 10 x 20, size of
C is 20, size of D is 20 x 10 and BPW is 8
B[i, j, k] = C[i] + D[i, j]

b) Generate three address code using SDTS for following statement 8


while (A < B and C > D or E = F)
do
if (G = 0)
X=X+1
else
X=Y+Z

7. a) Describe phrase level error recovery in LR parser. 8


b) Write labelling algorithm to determine the minimum number of register required to 8
evaluate the tree. Use labelling algorithm to evaluate following expression
Z = X − Y + XYV
OR
8. Generate object code for the following DAG using labelling algorithm. 16

_
+

A B E +

C D
9. a) For the given program fragment, generate TAC bpw = 4 8
PROD = PROD + A[I]  B[J]
I=I+1
If I  20 goto (1)
Eliminate local common subexpression.
b) Explain the method to eliminate global common subexpression. 8
OR
10. a) Write and explain syntax directed translation scheme for array reference. 8
b) Explain phrase level error recovery for LR parser with suitable example. 8

***********

GUG/W/18/1997 2

You might also like