Tribhuwan University

Institute of Science and Technology

2081.1

Bachelor Level / Third Year / Sixth Semester / Science

B.Sc in Computer Science and Information Technology (CSC376)

(Compiler Design and Construction)

Full Marks: 60

Pass Marks: 24

Time: 3 Hours

Candidates are required to give their answers in their own words as for as practicable.

The figures in the margin indicate full marks.

Section A

Long Answers Questions

Attempt any TWO questions.
[2*10=20]
1.
Discuss about Directed Acyclic Graph with an example. Represent the expression A = (B + C) - (D - E) using 3AC, Quadruple and Triple. [10]
2.
Create the LR(1) parsing table for following grammar.
SAAS \rightarrow AA
A0AA \rightarrow 0A
AεA \rightarrow \varepsilon
[10]
3.
Explain the optimization techniques for code optimization. Convert the following program to basic block and control flow.
M=A+BM = A + B
N=C+DN = C + D
IF (M>N)X=MN;\text{IF } (M > N) \rightarrow X = M - N;
ELSE E=M+N+X\text{ELSE } E = M + N + X
[10]
Section B

Short Answers Questions

Attempt any Eight questions.
[8*5=40]
4.
Compute the FIRST and FOLLOW of all the non-terminals in following grammar.
SABS \rightarrow AB
A0A1AεA \rightarrow 0A' \mid 1A' \mid \varepsilon
ASSAεA' \rightarrow SSA' \mid \varepsilon
BAS1B \rightarrow AS \mid 1
[5]
5.
What are the operations performed in symbol table? Discuss about activation tree. [5]
6.
What are the roles of macros and preprocessor? Discuss about one pass and multi pass compiler. [5]
7.
Define explicit and implicit type conversion. Why do we need to check type of the system? Justify with an example. [5]
8.
Differentiate between synthesized and inherited attributes with example. [5]
9.
Construct the LL(1) parsing table for the following grammar.
SAS1CS \rightarrow AS1 \mid C
A0A \rightarrow 0
C2CεC \rightarrow 2C \mid \varepsilon
[5]
10.
What are the advantages of intermediate code? How do you convert procedure call to 3AC? [5]
11.
What is a symbol table? Discuss the general structure of an LR parser. [5]
12.
Generate the LR(0) item sets for the following grammar.
ABBA \rightarrow BB
BbBaB \rightarrow bB \mid a
[5]