1) For the C program given below the statement that does not hold true is
for (i = 0; ifor(j = 0; jif (i%c)
{
x += (4*j+5*i);
y+=(7+4*j);
}
}
}
a. There is a scope strength reduction
b. There is a scope of dead code elimination
c. There is a scope of common sub-expression elimination
d. None of the above
ANS:- There is a scope of dead code elimination
2) In compilers generation of intermediate code based on an abstract machine model is useful because
a. Syntax-directed translations can be written for intermediate code generation
b. To generate code for real machines directly from high-level language programs is not possible
c. Portability of the front end of the compiler is enhanced
d. Implementation of lexical and syntax analysis is easier
ANS:- Implementation of lexical and syntax analysis is easier
3) Consider the grammar where P, Q, R are not terminals and r, s, t are terminals
a. P->Q R
b. P->Q s R
c. P->ε
d. P->Q t R r
The grammar rules that violate the requirements of an operator grammar is
a. a and c only
b. b and c only
c. a and d only
d. a only
ANS:- a and c only
4) Which one of the following statement is false for the SLR (1) and LALR (1) parsing tables for a context free grammar?
a. The reduce entries in both the tables may be different
b. The error entries in both the tables may be different
c. The go to part of both tables may be different
d. The shift entries in both the tables may be identical
ANS:- The go to part of both tables may be different
5) We have a grammar with not epsilon and unit production (i.e. of type A->ε and
A ->a) to parse a string, with n tokens. What is the maximum number of reduces moves that can be taken by a bottom-up parser for this grammar?
a. 2n – 1
b. 2n
c. n-1
d. n/2
ANS:- 2n – 1
For questions 6 and 7 refer to the data given below:
The processor allows only register operands in its instructions and the given code segment is executed in that processor. For each instruction almost two source operands and one destination
operand is available. Assume that all the variables are dead after this code segment.
z = x + y;
p = z * x;
q = c + x;
j = z * z;
If (j > x)
{
M = x*x;
}
else
{
p = p*p;
q = q*q;
}
6) Only two registers are available in the instruction set architecture of the processor. The code motion moves the statements from one place to another while preserving correctness. The only allowed complier optimization is code motion. In the compiled code, the minimum number of spills to memory is
a. 0
b. 1
c. 2
d. 3
ANS:- 1
7) Assume that no other optimization other than optimizing register allocation is applied. To compile this code segment without any spill to memory the minimum number of registers needed in the instruction set architecture of the processor is
a. 3
b. 6
c. 4
d. 5
ANS:- 4
8) We have the grammar E->E + n I E x n I n. The handles in the right-sentential form of the reduction for a sentence n + n x n are
a. n, n + n and n + n x n
b. n, E + n and E x n
c. n, E + n and E + E x n
d. n, E + n and E + n x n
ANS:- n, E + n and E x n
9) The languages that need heap allocation in the runtime environment are
a. Those that use global variables
b. Those that use dynamic scoping
c. Those that support recursion
d. Those that allow dynamic data structure
ANS:- Those that allow dynamic data structure
10) When is the type checking usually done?
a. During syntax directed translation
b. During lexical analysis
c. During code optimization
d. During syntax analysis
ANS:- During syntax directed translation
11) What information need to be included in an object module, if a linker is given object modules for a set of programs that were compiled separately?
a. Names and locations of all external symbols defined in the object module
b. Object code
c. Absolute addresses of internal symbols
d. Relocation bits
ANS:- Absolute addresses of internal symbols
12) We have two sets of LR (1) items of LR (1) grammar described below.
X->c.X, c/d X->c.X, $
X->.cX, c/d X->.cX, $
X->.d, c/d X->.d, $
Related to the merging of two sets in the corresponding parser, the statement that does not hold true is
a. Cannot be merged since look aheads are different.
b. Cannot be merged but will result in R-R conflict
c. Cannot be merged but will result in S-R conflict
d. All of the above
ANS:- All of the above
13)a. Begin
b. Program
c. <>
While compiling a Pascal program, without looking at the next input character the string that can be definitely said to be token is
a. b
b. c
c. a
d. All of the above
ANS:- c
14) S->xx W {print”1”}
S->y {print”2”}
W->Sz {print”3”}
A shift reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of grammar. Using the syntax directed translation scheme described
by the above rule, the translation of xxxxyzz is
a. 11231
b. 11233
c. 23131
d. 33211
ANS:- 23131
15) In some programming language, L denotes the set of letters and D denotes the set of digits. An identifier is permitted to be a letter followed by any number of letters or digits. The expression that defines an identifier is
a. (L.D)*
b. (L + D)*
c. L (L.D)
d. L (L + D)*
ANS:- L (L + D)*
16) Which one of the following statement is true?
a. Canonical LR parser is more powerful than LALR parser
b. SLR parser is more powerful than LALR
c. LALR parser is more powerful than canonical LR parser
d. SLR parser, canonical LR parser and LALR parser all have the same power
ANS:- Canonical LR parser is more powerful than LALR parser
17) The activities are listed below. What is the pass numbers of each of the activities respectively?
a. Object code generation
b. Literals added to the literal table
c. Listing printed
d. Address resolution of local symbols that occur in a two pass assembler
a. 1, 2, 2, 2
b. 2, 1, 1, 1
c. 1, 2, 1, 2
d. 2, 1, 2, 1
ANS:- 2, 1, 2, 1
18) In a compiler _______________ checks every character of the source text.
a. The lexical analyzer
b. The syntax analyzer
c. The code generator
d. The code optimizer
ANS:- The lexical analyzer
For questions 19 and 20 refer to the data given below:
The programming language given below is written in the programming language that does not allow nested declarations of functions and allows global variables.
global int j = 100, k = 5;
void M(n)
{
int j = 10;
print (n + 10);
j = 200;
k = 20;
print (n);
}
main()
{
M(j + k);
}
19) What is the output of the above program if the programming language uses static scoping and call by need parameter passing mechanism?
a. 25, 220
b. 115, 105
c. 220, 115
d. 105, 220
ANS:- 115, 105
20) What is the output of the above program if the programming language uses dynamic scoping and call by name parameter passing mechanism?
a. 105, 25
b. 105, 115
c. 220, 25
d. 115, 220
ANS:- 115, 220
21) ______________ is not an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries.
a. Lesser overall page fault rate in the system
b. Faster program startup
c. Existing programs need not be relinked to take advantage of newer versions
d. Smaller sizes of executable files
ANS:- Existing programs need not be relinked to take advantage of newer versions
22) The instructions of a simplified computer, which has only two registers, are given below:
OP Rj, Rk – Performs Rj OP Rk and stores the result in register Rk.
OP m, Rj – Performs the content of memory location m OP Rj and stores the result in Rj
MOV m, Rk – Moves the content of memory location m to register Rk.
MOV Rk, m – Moves the content of register Rk to memory location m.
OP is either ADD or SUB.
We have the following basic block:
T1 = a + b
T2 = c + d
T3 = e – T2
T4 = T1 – T3
Assuming that all operands are initially in memory and the final value of the computation in memory, the minimum number of MOV instructions in the code generated for this basic block is
a. 3
b. 2
c. 6
d. 4
ANS:- 3
For questions 23 and 24 refer to the data given below:
Consider the language L = {ai bi I i ? j}?
23) The grammar that generates this language is
a. S->aS\Sb\a\b
b. S->AC\CB
C->aC b\a\b
A->aA\ ∈
B->Bb\ ∈
c. S->AC\CB
C->aCb\∈
A->aA\a
B->bB\b
d. S->AC\CB
C->aC b\∈
A->aA\ ∈
B->Bb\ ∈
ANS:- S->AC\CB
C->aCb\∈
A->aA\a
B->bB\b
24) In the correct grammar from question 23 to generate the string al bm with l ≠ m, the length of the derivation (number of steps starting from s) is
a. max (l, m) + 3
b. max (l, m) + 2
c. l + m + 2
d. l + m + 3
ANS:- max (l, m) + 2
25) Consider the following C program:
int min (){ /*line 1*/
int I, N; /*line 2*/
fro (I=0, I
While creating the object module, the compiler’s response about line no. 3 is
a. Only syntax error
b. No compilation error
c. Only lexical error
d. Both lexical and syntax error
ANS:- Only syntax error
26) We have the translation scheme given below:
S->FR
R->*E{print(‘*’);R\ε
E->F + E{print (‘+’);\F
F->(S)\id {print (id.value);}
In the above translation scheme id represents the token in integer form and id value represents the corresponding integer value. What will be printed by this translation scheme when an input
is ‘2 * 3 + 4’?
a. 2 3 * 4 +
b. 2 3 4 + *
c. 2 * + 3 4
d. 2 * 3 + 4
ANS:- 2 3 4 + *
27) We have the grammar with the translation rules:
E->E1 # T {E.value = E1.value * T.value}
I T {E.value = T.value}
T->T1 & F {T.value = T1.value F.value}
I F {T.value = F.value}
F->num {F.value = num.value}
In the above grammar E is the start symbol. What will be the value of E for the root parser tree for the expression 2 # 3 & 5 # 6 & 4?
a. 50
b. 100
c. 200
d. 160
ANS:- 160
28) For the expression grammar
E->E*F I F+E I F
F->F – I id
The statement, which holds true, is
a. + and – have same precedence
b. Precedence of * is higher +
c. Precedence of – is higher *
d. Precedence of + is higher *
ANS:- Precedence of – is higher *
29) Which one of the following statement holds true for a bottom-up evaluation of syntax directed definition?
a. Inherited attributes can always be evaluated
b. Inherited attributes can never be evaluated
c. Inherited attributes can be evaluated only if the definition is L-attributed
d. Inherited attributes can be evaluated only if the definition has synthesized attributes
For questions 30 and 31 refer to the data given below:
{S, A, B} is the non-terminal alphabet and {a, b} is the terminal alphabet of the CFG. S is the start symbol. The set of production rules are given below,
S->aB S->bA
B->b A->a
B->bS A->aS
B->aBB A->bAA
ANS:- Inherited attributes can be evaluated only if the definition has synthesized attributes
30) The string that is generated by the grammar is
a. aabbbb
b. abbbba
c. aabbab
d. aaaabb
ANS:- aabbab
31) The number of derivation trees for the correct answer strings to question 30 is
a. 4
b. 1
c. 3
d. 2
ANS:- 2
32) For a grammar G, Shift reduce (S-R) conflicts is present in LALR (1) parser, if and only if
a. The LR (1) parser for G has S-R conflicts
b. The LR (0) parser for G has S-R conflicts
c. The SLR (1) parser for G has S-R conflicts
d. The SLR (0) parser for G has S-R conflicts
ANS:- The LR (1) parser for G has S-R conflicts
33) For arithmetic expression the grammar rule is E->E1-E2. A CPU has a single user register and the code generated is target to the CPU. The first operand should be in the register for the subtraction operation. E1 and E2 do not have any common sub-expression. Which one of the following is true in order to get the shortest possible code?
a. Order of evaluation of E1 and E2 has no consequence
b. E1 and E2 evaluation should be interleaved
c. E2 should be evaluated first
d. E1 should be evaluated first
ANS:- E2 should be evaluated first
34) Consider the grammar G whose SLR parser has n1 states and LALR parser has n2 states. What is the relation between n1 and n2?
a. n1 = n2
b. n1 < n2 c. n1 > n2
d. None of the above
ANS:- n1 = n2
35) A program P has M1 and M2, the two source modules contained in two different files. When is the reference resolved if M1 contains reference to a function defined in M2?
a. Edit time
b. Load time
c. Compile time
d. Link time
ANS:- Link time
36) For predictive parsing the grammar A->AA I a. I ε is not suitable because
a. The grammar is right recursive
b. The grammar is left recursive
c. The grammar is ambiguous
d. The grammar is an operator grammar
ANS:- The grammar is left recursive
37) How many tokens are there in the following C statement?
printf (“j=%d, &j=%x”, j&j)
a. 4
b. 5
c. 9
d. 10
ANS:- 10
38) Assuming that the input is scanned in left to right order, while parsing an input string the top-down parser use
a. Rightmost derivation
b. Leftmost derivation
c. Rightmost derivation that is traced out in reverse
d. Leftmost derivation that is traced out in reverse
ANS:- Rightmost derivation
39) To convert an arbitrary CFG to an LL (1) grammar
a. Factor the grammar alone
b. Remove left recursion alone
c. Remove left recursion and factor the grammar
d. None of the above
ANS:- Remove left recursion and factor the grammar
40) S->S*E
S->E
E->F+E
E->F
F->Id
Corresponding to the above grammar, we have following LR (0) items.
a. S->S*E
b. E->F.+E
c. E->F+.E
The two items that will appear in the same set in the canonical sets-of-items for the grammar is
a. a and c
b. a and b
c. b and c
d. a, b and c
ANS:- a and c
41) __________________ is a top-down parser
a. Operator precedence parser
b. An LALR (k) parser
c. An LR (k) parser
d. Recursive descent parser
ANS:- Recursive descent parser
42) Why is the code optimizations are carried out on the intermediate code?
a. Because for optimization information from the front end cannot be used
b. Because program is more accurately analyzed on intermediate code than on machine code.
c. Because for optimization information from data flow analysis cannot be used
d. Because they enhance the portability of the compiler to the other target processor.
ANS:- Because program is more accurately analyzed on intermediate code than on machine code.
43) In a compiler, when is the keyboards of a language are recognized?
a. During the lexical analysis of a program
b. During parsing of the program
c. During the code generation
d. During the data flow analysis
ANS:- During the lexical analysis of a program
44) In a compiler, the data structure responsible for the management of information about variables and their attributes is
a. Semantic stack
b. Parser table
c. Symbol table
d. Abstract syntax-tree
ANS:- Symbol table
45) The lexical analysis for Java needs _____________ in a necessary and sufficient sense.
a. Turing machine
b. Non-deterministic push down automata
c. Deterministic push down automata
d. Finite state automata
ANS:- Finite state automata