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 following ANSI C program:
int main () {
Integer x;
return 0;
}
Which one of the following phases in a seven-phase C compiler will throw an error?Lexical analyzer | |
Syntax analyzer | |
Semantic analyzer | |
Machine dependent optimizer |
Question 2 Explanation:
Question 3 |
Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation (SDT) actions, given as pseudo-code
\begin{array}{lll} P & \rightarrow & D^* E^* \\ D & \rightarrow & \textsf{int ID} \{ \text{record that } \textsf{ID.} \text{lexeme is of type} \textsf{ int\}} \\ D & \rightarrow & \textsf{bool ID} \{ \text{record that } \textsf{ID.} \text{lexeme is of type} \textsf{ bool\}} \\ E& \rightarrow & E_1 +E_2 \{ \text{check that } E_1. \text{type}=E_2. \text{type} = \textsf{int}; \text{set } E.\text{type }:= \textsf{int} \} \\ E & \rightarrow & !E_1 \{ \text{check that } E_1. \text{type} = \textsf{bool}; \text{ set } E.\text{type} := \textsf{bool} \} \\ E & \rightarrow & \textsf{ID} \{ \text{set } E. \text{type } := \textsf{int} \} \end{array}
With respect to the above grammar, which one of the following choices is correct?
\begin{array}{lll} P & \rightarrow & D^* E^* \\ D & \rightarrow & \textsf{int ID} \{ \text{record that } \textsf{ID.} \text{lexeme is of type} \textsf{ int\}} \\ D & \rightarrow & \textsf{bool ID} \{ \text{record that } \textsf{ID.} \text{lexeme is of type} \textsf{ bool\}} \\ E& \rightarrow & E_1 +E_2 \{ \text{check that } E_1. \text{type}=E_2. \text{type} = \textsf{int}; \text{set } E.\text{type }:= \textsf{int} \} \\ E & \rightarrow & !E_1 \{ \text{check that } E_1. \text{type} = \textsf{bool}; \text{ set } E.\text{type} := \textsf{bool} \} \\ E & \rightarrow & \textsf{ID} \{ \text{set } E. \text{type } := \textsf{int} \} \end{array}
With respect to the above grammar, which one of the following choices is correct?
The actions can be used to correctly type-check any syntactically correct program | |
The actions can be used to type-check syntactically correct integer variable declarations and integer expressions | |
The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions. | |
The actions will lead to an infinite loop |
Question 3 Explanation:
Question 4 |
Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X_1,X_2,X_3,X_4,X_5 \; and \; X_6 be the placeholders for the non-terminals D, T, L or L_1 in the following table:

Which one of the following are the appropriate choices for X_1,X_2,X_3 \; and \; X_4?

Which one of the following are the appropriate choices for X_1,X_2,X_3 \; and \; X_4?
X_1=L,X_2=T,X_3=L_1,X_4=L | |
X_1=T,X_2=L,X_3=L_1,X_4=T | |
X_1=L,X_2=L,X_3=L_1,X_4=T | |
X_1=T,X_2=L,X_3=T,X_4=L_1 |
Question 4 Explanation:
Question 5 |
Which one of the following statements is FALSE?
Context-free grammar can be used to specify both lexical and syntax rules. | |
Type checking is done before parsing. | |
High-level language programs can be translated to different Intermediate Representations. | |
Arguments to a function can be passed using the program stack. |
Question 5 Explanation:
There are 5 questions to complete.