Bcse307l Fat A2 2024
Bcse307l Fat A2 2024
Bcse307l Fat A2 2024
VIT :2)81j22
Reg. No.
Vellore Institute of Technology
(Deemed to he Unvenily under sectn ) of the LtiN A 190)
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;
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)
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
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;
Page 4