Tribhuwan University

Institute of Science and Technology

2075

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.
Difference between compiler and interpreter. "Symbol table is necessary component of compiler". Justify this statement with examples. [6]
2.
List out the major tasks carried out in Lexical Analysis Phase. Convert the following NFA to DFA.
question image
[6]
3.
Differentiate between recursive descent and non-recursive predictive parsing method. Find first and follow of all the non-terminals in the following grammar.
ETA;A+TAε;TFB;BFBε;F(E)idE \rightarrow TA; A \rightarrow +TA|\varepsilon; T \rightarrow FB; B \rightarrow *FB|\varepsilon; F \rightarrow (E)|id
[6]
4.
Construct SLR parse table for the following grammar
SES \rightarrow E
EE+TTE \rightarrow E+T|T
TTFFT \rightarrow T*F|F
FidF \rightarrow id
[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.
ProductionSemantic RuleLEnPrint E.valEE1+TE.valE1.val+T.valETE.valT.valTT1FT.valT1.valF.valTFT.valF.valF(E)F.val(E.val)FdigitF.valdigit.lexval\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.
Differentiate between static and dynamic type checking. How can we carry out type checking for the following expression using syntax-directed definition?
Sid=ES \rightarrow id = E
SifEthenS1S \rightarrow if E then S1
SwhileEdoS1S \rightarrow while E do S1
SS1;S2S \rightarrow S1; S2
[6]
7.
Define three address codes. write three address codes for
S=dom=n+pwhilea<=bS = do m = n + p while a < = b
[6]
8.
Define code optimization. Discuss about any three code optimization techniques with example. [6]
9.
What is activation record? Discuss the different activities performed by caller and callee during procedure call and return. [6]
10.
Discuss about the different factors affecting target code generation. [6]