Question 1 |
Consider the syntax directed translation given by the following grammar and semantic rules. Here N, I, F \; and \; B are non-terminals. N is the starting non-terminal,
and \#,0 \; and \; 1 are lexical tokens corresponding to input letters "\#","0" \; and \; "1",
respectively. X.val denotes the synthesized attribute (a numeric value) associated
with a non-terminal X. I_1 and F_1 denote occurrences of I and F on the right hand
side of a production, respectively. For the tokens 0 and 1, 0.val=0 and 1.val=1.
The value computed by the translation scheme for the input string
\begin{aligned} N & \rightarrow I \# F & N.val=I.val+F.val \\ I &\rightarrow I_1B & I.val = (2 I1.val) + B.val\\ I &\rightarrow B&I.val = B.val\\ F &\rightarrow BF_1& F.val = \frac{1}{2}(B.val + F1.val)\\ F &\rightarrow B& F.val = \frac{1}{2} B.val\\ B&\rightarrow 0& B.val = 0.val\\ B &\rightarrow 1&B.val = 1.val \end{aligned}
10\# 011
is ____ (Rounded off to three decimal places)
The value computed by the translation scheme for the input string
\begin{aligned} N & \rightarrow I \# F & N.val=I.val+F.val \\ I &\rightarrow I_1B & I.val = (2 I1.val) + B.val\\ I &\rightarrow B&I.val = B.val\\ F &\rightarrow BF_1& F.val = \frac{1}{2}(B.val + F1.val)\\ F &\rightarrow B& F.val = \frac{1}{2} B.val\\ B&\rightarrow 0& B.val = 0.val\\ B &\rightarrow 1&B.val = 1.val \end{aligned}
10\# 011
is ____ (Rounded off to three decimal places)
5.324 | |
2.375 | |
6.215 | |
8.257 |
Question 1 Explanation:
Question 2 |
Consider the control flow graph shown.

Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?

Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?
B1: {}, B2: {a}, B3: {a}, B4: {a} | |
B1: {i, j}, B2: {a}, B3: {a}, B4: {i} | |
B1: {a, i, j}, B2: {a, i, j}, B3: {a, i}, B4: {a} | |
B1: {a, i, j}, B2: {a, j}, B3: {a, j}, B4: {a, i, j} |
Question 2 Explanation:
Question 3 |
Consider the following statements regarding the front-end and back-end of a compiler.
S1: The front-end includes phases that are independent of the target hardware.
S2: The back-end includes phases that are specific to the target hardware.
S3: The back-end includes phases that are specific to the programming language used in the source code.
Identify the CORRECT option.
S1: The front-end includes phases that are independent of the target hardware.
S2: The back-end includes phases that are specific to the target hardware.
S3: The back-end includes phases that are specific to the programming language used in the source code.
Identify the CORRECT option.
Only S1 is TRUE. | |
Only S1 and S2 are TRUE. | |
S1, S2, and S3 are all TRUE. | |
Only S1 and S3 are TRUE. |
Question 3 Explanation:
Question 4 |
Consider the following grammar along with translation rules.
\begin{aligned} &S \rightarrow S_1 \# T & & \{S._{val}=S_{1.val}*T._{val} \} \\ &S \rightarrow T & & \{S._{val}=T._{val} \} \\ &T \rightarrow T_1 \% R & & \{T._{val}=T_{1.val} \div R._{val} \} \\ &T \rightarrow R & & \{T._{val}=R._{val} \} \\ &R \rightarrow id & & \{R._{val}=id._{val} \} \\ \end{aligned}
Here \# and \% are operators and id is a token that represents an integer and id_{.val} represents the corresponding integer value. The set of non-terminals is \{S,T,R,P \} and a subscripted non-terminal indicates an instance of the non-terminal.
Using this translation scheme, the computed value of S_{.val} for root of the parse tree for the expression 20 \# 10 \% 5 \# 8 \% 2 \% 2 is
\begin{aligned} &S \rightarrow S_1 \# T & & \{S._{val}=S_{1.val}*T._{val} \} \\ &S \rightarrow T & & \{S._{val}=T._{val} \} \\ &T \rightarrow T_1 \% R & & \{T._{val}=T_{1.val} \div R._{val} \} \\ &T \rightarrow R & & \{T._{val}=R._{val} \} \\ &R \rightarrow id & & \{R._{val}=id._{val} \} \\ \end{aligned}
Here \# and \% are operators and id is a token that represents an integer and id_{.val} represents the corresponding integer value. The set of non-terminals is \{S,T,R,P \} and a subscripted non-terminal indicates an instance of the non-terminal.
Using this translation scheme, the computed value of S_{.val} for root of the parse tree for the expression 20 \# 10 \% 5 \# 8 \% 2 \% 2 is
20 | |
65 | |
160 | |
80 |
Question 4 Explanation:
Question 5 |
Consider the augmented grammar with \{+, *, (, ), id \} as the set of terminals.
\begin{aligned}&S' \rightarrow S \\ &S \rightarrow S+R|R \\ &R \rightarrow R*P|P \\ &P \rightarrow (S)|id \end{aligned}
If I_0 is the set of two LR(0) items \{ [S' \rightarrow S.], [S \rightarrow S.+R] \}, then goto(closure(I_0 ),+) contains exactly ______ items.
\begin{aligned}&S' \rightarrow S \\ &S \rightarrow S+R|R \\ &R \rightarrow R*P|P \\ &P \rightarrow (S)|id \end{aligned}
If I_0 is the set of two LR(0) items \{ [S' \rightarrow S.], [S \rightarrow S.+R] \}, then goto(closure(I_0 ),+) contains exactly ______ items.
2 | |
3 | |
4 | |
5 |
Question 5 Explanation:
There are 5 questions to complete.