Professional Documents
Culture Documents
CT 801 / CSE802 - Compiler Construction
CT 801 / CSE802 - Compiler Construction
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 ET|T
T TF| 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
Cd
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
b) Write Heuristic algorithm for optimal ordering of code. Explain the algorithm by taking 8
an example.
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) 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
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 ET/T
T T F/F
F ( E ) / id
S abSa / aaAc / b
A abAb /
OR
S CC
C eC
Cd
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.
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
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
7. a) Explain phrase level error recovery for LR parser with suitable example. 8
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
i) Loop jamming
iii) Dominator
OR
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 .
OR
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.
OR
GUG/S/18/7030 1 P.T.O
5. a) Explain Syntax Directed Definations ? Write syntax directed definition for a given 8
statement
E ET
ET
T TF
TF
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
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.
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
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) Comment on the following statements : A multipass compiler can be made less space then 8
a single pass compiler.
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 → TF 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]
_
+
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