Bcse307l Fat A2 2024

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

VIT

VIT :2)81j22
Reg. No.
Vellore Institute of Technology
(Deemed to he Unvenily under sectn ) of the LtiN A 190)

Final Assessment Test (FAT)- May 2024


Semester WINTER SEMESTER 2023 - 24
Programme B.Tech.
Course Title COMPILER DESIGN Course Code BCSE307L
A2+TA2
Slot
Faculty Name Prof. Mercy Rajaselvi Beaulah P Class Nbr CH2023240502679
Time 3 Hours Max. Marks 100
General Instructions:
"Writeonly Register Number in the Question Paper where space is provided (right-side at the top) &do
not write any other details.

Section -I
Answer all questions (7 X 10 Marks = 70 Marks)
01. Consider the following grammar. The character R is the Non-terminal and [10]
the symbols #,%,(,),a,b are Terminals.
Grammar:
R’R#|#R| RR|R% |(R)|a| b
(i) Check whether given grammar is LL(1) grammar or not. (8 Marks)
(ii) Justify your answer. (2 Marks)

02. A Context free grammar defining a programming block is given below. The uppercase strings [10]
represents the Non-terminals and characters in lowercase italics x ,y and symbols {} are
terminals.
Grammar:
BLOCK’{ BODY}
BODY - {BODY STMT} | STMT
STMT x|y

(i)Generate the canonical LR(1) items and construct corresponding parsing table for the given
grammar. (7 marks)
(ii) Ilustrate the parsing action of the given programming construct using the parsing table and
the stack. (3 marks)

Programming Construct : ({ xy }* }}
03. Consider the following Syntax directed translation scheme for the declaration of the variables of [10)
integer anddouble data type. The attributes of the grammar symbols 'ype' and 'width' are used
to hold the datatype and memory size(bytes) of the declared variables. The 'm' and ' '
represents temporary variables. The function Addsymtab is used to enter the datatype and

Page 1 of 4
storage size of the variable into the symbol table.The uppercase alphabets D, I, P, A, Aj, V, VË
represents the Non-terminals and the strings int, double, num, id and the symbols [U, ¬
are terminals.
Grammar with SDT:
D’T{V.ype =T.hype; V.wid1h= T.width }V; D|¬
T’P{m= P.ype; = P.width }
A {Ttype =A.type; T.width- A. width }
P’ int { P.ype = integer ; P.width = 4 }
P’ double { P.type = double ; P.width =8}
A’ [num| A, {A.type-array(num.value, A1.ype); A.width =num.value *Al.with)
A’¬ { A.type = m;A.width = n
V’ {Vyype =V.ype; VË.wid1h = V.width} VË,id { Addsymtab(id.entry, V.type, V.widh)}
V’ id { Addsymtab(id.entry, V.type, V.width) }

i) Draw the annotated parse tree for the following declaration statement. (6 marks)
int a, b ; double (4] 3| x;

(i) Draw the corresponding dependency graph. (2 marks)


(iüü)Show the status of the Symbol Table after parsing the given declaration statement. (2 marks)

04. Convert the following string into three address code using the given grammar(4 Marks) and [10]
represent them in quadruple, triple, and indirect triple( 6 Marks). The symbols @, #, S are
binary operators and % is unary operator.
Grammar :
W ’W @X|X
X’X#Y|Y
Y’YSZ|Z
Z’ %Z|a|b|c|d
String:
a# b$ % d $c @ d#% a
05. Apply Back-patching in the generation of three address code for the following programming [10)
construct (5 Marks). Illustrate the Back-patching through annotated parse tree (5 Marks).

while (i <10)

if(a <6) && (b> i)


a=a+i;i=i+1;

06. Consider the following three address code: [10)

t=a+b
s=c* d

Page 2 of 4
u=b+ a
v=d* c
X=t+u
w=y* s
Z=X- W

p=z

(i)Construct the Direct Acyclic Graph and generate the optimized three address code. (4 Marks)
(ii) Generate the machine code for the above optimized three address code using the instruction
sets of suitable microprocessor. (4 Marks)
ii) Construct the Activation tree for the following code. (2 Marks)

int main(0

int ml, m2;


float avg;
printf(" Enter the lst markn"):
scanf("%d", &ml);
printf(" Enter the 2nd markn"):
scanf("%d", &m2);
avg = average(m1,m2);
printf("average =%f",avg);

float average(int x, int y)


{return sum(x,y)/2; }

int sum(int a, int b)


{ return atb;}
07. (i) Discuss the impact of Instruction scheduling and software pipelining in the design of [10)
compilers for parallel processing architecture. (5 Marks)
() Discuss the design aspects of vector operations supported by vectorizing compiler in
achieving parallelism on a vector architecture. (5 Marks)
Section - II
Answer all questions (2 X 15 Marks = 30 Marks)
08. Consider the regular expression given below whieh specifies the definition of the floating-point [15]
number with exponent,

(digit)*. digit (E | e) (+|-)(digit)*


Where digit represents the numbers from 0-9 and '' represents the decimal point.
i)Compute the first position, last position and follow position for the given regular
expression. (6 Marks)
(ii))Construct the deterministic finite automaton using the Direct method. (6 Marks)
(iii) Simulate the string "25.4E+18" using the constructed DFA. (3 Marks)

Page 3of 4
09. Consider the following code segment: [15]
Code:
p=3.14;
for( i= 0; i< 10; i++)
{
c=2*p* a[i];
a=p*a[i]^2;

())Convert the code segment into three address code. (4 Marks)


(ii) Identify the basic blocks and flow graph in the three address code. (6 Marks)
(ii) Deseribe suitable optimization techniques and apply them on the Basic blocks and generate
the optimized three address code. (5 Marks)

Page 4

You might also like