Question 1 |
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 1 Explanation:
Question 2 |
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 2 Explanation:
Question 3 |
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 3 Explanation:
Question 4 |
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 4 Explanation:
Question 5 |
Consider the following Java code fragment:
public class While
{
public void loop()
{
int x = 0;
while(1)
{
System.out.println("x plus one is" +(x+1));
}
}
}
There is syntax error in line no. 1 | |
There is syntax errors in line nos. 1 & 6 | |
There is syntax error in line no. 8 | |
There is syntax error in line no. 6 |
Question 5 Explanation:
Question 6 |
Which of the following statements is FALSE?
In statically typed language, each variable in a program has a fixed type | |
In up-typed languages, values do not have any types | |
In dynamically typed languages, variables have no types | |
In all statically typed languages, each variable in a program is associated
with values of only a single type during the execution of the program |
Question 6 Explanation:
Question 7 |
In a bottom-up evaluation of a syntax directed definition, inherited attributes can
always be evaluated | |
be evaluated if the definition is L-attributed | |
be evaluated only if the definition has synthesized attributes | |
never be evaluated |
Question 7 Explanation:
Question 8 |
Type checking is normally done during
lexical analysis | |
syntax analysis | |
syntax directed translation | |
code optimization |
Question 8 Explanation:
Question 9 |
A shift reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of grammar
S \rightarrow xxW \;\text{{print "1"}}
S \rightarrow y \;\text{{print "2"}}
W \rightarrow Sz\; \text{{print "3"}}
What is the translation of xxxxyzz using the syntax directed translation scheme described by the above rules?
S \rightarrow xxW \;\text{{print "1"}}
S \rightarrow y \;\text{{print "2"}}
W \rightarrow Sz\; \text{{print "3"}}
What is the translation of xxxxyzz using the syntax directed translation scheme described by the above rules?
23131 | |
11233 | |
11231 | |
33211 |
Question 9 Explanation:
There are 9 questions to complete.