0% found this document useful (0 votes)
13 views2 pages

Compre 2023 B

The document outlines the comprehensive examination for the Compiler Construction course at Birla Institute of Technology and Science, Pilani, for the second semester of 2022-2023. It includes various programming and theoretical questions related to code analysis, flow graphs, grammar generation, and symbol table implementation. The examination is closed book, lasts 120 minutes, and consists of multiple parts requiring detailed coding and algorithmic responses.

Uploaded by

f20220136
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Compre 2023 B

The document outlines the comprehensive examination for the Compiler Construction course at Birla Institute of Technology and Science, Pilani, for the second semester of 2022-2023. It includes various programming and theoretical questions related to code analysis, flow graphs, grammar generation, and symbol table implementation. The examination is closed book, lasts 120 minutes, and consists of multiple parts requiring detailed coding and algorithmic responses.

Uploaded by

f20220136
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Birla Instituteof Technology and Science, Pilani

Department of Computer Science and Information Systems


Second Semester 2022-2023
Compiler Construction (CS F463)
Comprehensive Examination
(Closed Book) Part 2
Date: May 22, 2023 Marks(Part Zy 5
Day: Monday Duration: 120 minstes
Instructions: Write neathy using a blue or black penon the answer sheet given Answers wrilten withpenil ail bo
considered for evaluation Over written answers will not be considered for reevaluation
Ql Consider the following code fragment of sorting program.
i = m - 1; j = n; v = a(n];
while (1) {
do i i + 1; while (a[i] < v) ;
do j = j - l; while (alj] > v) i
if (i S= j) break;
X = a [i]; a (i] = alj]; a[j] =%;
X = a [i]; a [i] = a [n] ; a [n] = x;
o Generate the three-address code intermediate representation of the above code segmet
aIransform
all its nodesthe generated three-address code (in part a) into flow graph of basic blocks ciearty inicaing
and edges. - Ba
OL. Consider the following flowgraph of basic blocks (B1-B6) and answer the following questions by
applying the analysis on the computation of Reaching Definitions (RD) that are coming in and out of the
basic block as per the iterative algorithm for the computation of RD (as discussed in the class).
|3+36F12M)
entry exit

BI dl: i=1 d10: t5 = /-l


dll: t6 = 88*t3
d12: a[t6]= 1.0
B2 d2: j =11 d13: i =i+ 1 B6
8,4

if i<=10 go to Bó
d3: t1 = 10 *i
d4: t2 = ti +j 18,
3,
d5: t3 = 8 * t2
d6: t4 = t3 - 88 d9: i= 1 BS B (

d7:j =j+l
ifj<=10go to B3
d8: i=i +1
B3 if i<=10 go to B2 B4
1,9,
13

a) Çompute the GEN set by performing the localanalysis within the boundaries of allthe basic blocks.
b Find out the KILL set by performing areaching definition analysis on all the basic blocks locally.
rAlso, show the step-by-step computation of IN and OUT sets in all the required iterations.
Q3.
Consider the following CFG [ES. (if. exp. then, else. while, do, begin, end,
P, S]where S is the start symbol and Plist}.
is defined as otherstatements, i
follows: [2+4+3 = 9 MJ

S’ if exp then S1
|ifexp then Selse S R
|whileexp do S)
|begin list endFa
|otherstatements
list ’ list; Sy
|S

sa) Generate the Augmented Grammar and compute the closure ofS'>.S(where S' is the new start symbol
of above CFG. 19slalt
Ab) Design the DFA of LR (0) items indicating all the valid LR (0) items in each state.
yConstruct the LR (0) parsing table clearly indicating the shift and reduce entries in the ACTION and
GOTO part of all the states.
(e.g., 0342,
Q4. A language allows decimal, hexadecimal (e.g. XF234. XA23FF, and so on), octal numbers23.4E12, 34.9E
0654, O111, and so on), and real numbers using both exponent and mantissa form (e.g.
prefix X and O specity
16, 1.5e+12, and so on) and simple decimal point form (e.g. 23.45,45.39 etc.). The real number can use
the hexadecimal and octal numbers respectively. The exponent and mantissa form of a
signed or unsigned exponent values, using upper or lower case E ore for exponent. Write the regular
Deterministic Finite Automaton. Clearly
expressions for these five different types of numbers and draw the
Make sure that the DFA has one start state only.
DFA.
WTitethe responsibilities of each accept state in the [10 M]
the first nesting
Consider a symbol table T implementing the nested static scopes with functions atkey k so that T[k]
Q5.
tables such that h[<function name>]hashes toa
level. The symbol table is a tree of hash nesting level 1. The static children of the function get associated
points to the hash table of variables at the so that deeper nested scopes are implemented with deeper hash
way
withthis hash table in a hierarchicallinks are one way and children can access the parent's hash table only
Parent-to-child that maps
tables appropriately.
hash function for mapping function names and p is a hash function
using explicit stack. Ifh isthe necessary fields of table
names to unique keys, then answer the following questions. Specify
example. [6x2M=12M]
the variable contents of the symboltable using an appropriate
entries of T. and draw the
recursion? Cyclic
you implement the symbol table ifthe language does not allow cyclic function (say f2).
(a)How will when one function (say fl) calls
another
recursion refers to the recursion occurring and illustrate using an example.
the logic
and f2 calls fl, and so on. Explain table for accessing the non-local variables from their static
symbol
b) How will you implement theand illustrate using an example.
ancestors? Explain the logic

You might also like