Tribhuwan University

Institute of Science and Technology

2076

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.
Explain briefly about different phases involved in compiler, with a block diagram[6]
2.
Given a regular expression $(\varepsilon + 0)^* 10$. Construct the DFA recognizing the pattern described by this regular expression using syntax tree based reduction.[6]
3.
What is shift reduce parsing techniques? Show shift reduce parsing action for the string (x+x)*a, given the grammar[6]
4.
Construct SLR parsing table for the following grammar.

$S \rightarrow aAa | bAb | ba$
[6]
5.
Define Syntax directed definition. Construct annotated parse tree for the input expression (5*3+2)*5 according to the following syntax directed definition.

$\[\begin{array}{|l|l|}\hline \text{Production} & \text{Semantic Rule} \\ \hline L \to E\text{n} & \text{Print } E.\text{val} \\ \hline E \to E_1 + T & E.\text{val} \to E_1.\text{val} + T.\text{val} \\ \hline E \to T & E.\text{val} \to T.\text{val} \\ \hline T \to T_1 * F & T.\text{val} \to T_1.\text{val} * F.\text{val} \\ \hline T \to F & T.\text{val} \to F.\text{val} \\ \hline F \to (E) & F.\text{val} \to (E.\text{val}) \\ \hline F \to \text{digit} & F.\text{val} \to \text{digit.lexval} \\ \hline \end{array}\]$
[6]
6.
Write Syntax Directed Definition to carry out type checking for the following expression.

$E \rightarrow id | E1 \text{ op } E2 | E1 \text{ relop } E2 | E1[E2] | E1↑$
[6]
7.
Explain with example about different methods of intermediate code representation.[6]
8.
What is the purpose of code optimization? Explain different types of loop optimization techniques with example.[6]
9.
Discuss about the different factors affecting target code generation.[6]
10.
Discuss the importance of error handler in compiler. How is it manipulated in the different phases of compilation?[6]