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.

$S \rightarrow AA$

$A \rightarrow 0A$

$A \rightarrow \varepsilon$
[10]
3.
Explain the optimization techniques for code optimization. Convert the following program to basic block and control flow.

$M = A + B$

$N = C + D$

$\text{IF } (M > N) \rightarrow X = M - N;$

$\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.

$S \rightarrow AB$

$A \rightarrow 0A' \mid 1A' \mid \varepsilon$

$A' \rightarrow SSA' \mid \varepsilon$

$B \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.

$S \rightarrow AS1 \mid C$

$A \rightarrow 0$

$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.

$A \rightarrow BB$

$B \rightarrow bB \mid a$
[5]