Compilers Multiple Choice Questions & Answers (MCQs) on “L-Attributed Definition”.
1. Dynamic linking can cause security concerns because ______________
a) Security is dynamic
b) None of the mentioned
c) Security is dynamic & Cryptographic procedures are not available for dynamic linking
d) Cryptographic procedures are not available for dynamic linking
Answer: d
Clarification: Required by the program are linked during run time.
2. Which of the following statements is FALSE?
a) In up-typed languages, values do not have any types & Dynamic languages have no variables types
b) In up-typed languages, values do not have any types
c) Dynamic languages have no variables types
d) None of the mentioned
Answer: c
Clarification: They have dynamically changing types.
3. What is grammar?
S -> C C C -> eC | d
a) LL (1)
b) SLR (1) but not LL (1)
c) LALR (1) but not SLR (1)
d) LR (1) but not LALR (1)
Answer: c
Clarification: The grammar is CLR and can be reduced to LALR.
4. The 3-address code sequence generated by which definition?
S -> id: = E " newtemp (); gen(t . place . place;); .place t} " .place .place;} For the statement ‘X: = Y + Z ’,
a) X = Y + Z
b) t1 = Y + Z; X t1
c) t1 = Y; t2 = t1 + Z; X = t2
d) t1 = Y; t2 = Z; t3 + t2; X = t3
Answer: d
Clarification: In 3-address code we use temporary variables.
5. If the programming language uses static scoping and call by need parameter passing mechanism, the values printed will be?
a) 115, 220
b) 25, 220
c) 25, 15
d) 115, 105
Answer: d
Clarification: So i = 100 & j = 5 P (i + j) = P (100 + 5) = P(105) So x = 105 x + 10 = 105 + 10 = 115 So 115 & 105 will be printed.
6. If dynamic scoping is used and call by name mechanism is used, the values printed will be?
a) 115, 220
b) 25, 220
c) 25, 15
d) 115, 105
Answer: b
Clarification: Since x = i + j & in P (x) i = 200 & j = 20 x = 200 + 20 = 220 & printing (x + 10) 9. = i + j + 10 = 10 + 5 + 10 = 25.
7. What will be the output of the following code?
P x =new Q(); Q y =new Q(); P z =new Q(); x. f (1); ((P) y). f (1); z.f(1);
a) 1 2 1
b) 2 1 1
c) 2 1 2
d) 2 2 2
Answer:d
Clarification: Here,
1. Px = newQ(); 2. Qy = newQ(); 3. Pz = newQ(); 4. x : f(1); print 2 # i = 2 5. ((P) y) :f(1); 6. z : f(1) print 2 # i = 2
but line 6. will print 2 because typecast to parent class can’t prevent over ridding.
8. Which of the following is NOT an advantage of using shared, dynamically linked libraries as compared to statically linked libraries?
a) Smaller sizes of executable
b) Lesser overall page fault rate in the system
c) Faster program start-up
d) Existing programs need not be re-linked to take advantage of newer versions of libraries
Answer: c
Clarification: No need for re-linking if newer versions of libraries are there.
9. Which grammar violate rules of an operator grammar?
(i) P-> QR (ii) P -> Q s R (iii) P -> ε (iv) P ->Q t
a) (i) only
b) (i) and (iii) only
c) (ii) and (iii) only
d) (iii) and (iv) only
Answer: b
Clarification: (I) P ” QR is not possible since two NT should include one operator as Terminal.
10. Consider the grammar rule. E -> E1 − E2 for arithmetic expressions. If E1 and E2 do not have any common sub expression, in order to get the shortest possible code.
a) E1 should be evaluated first
b) E2 should be evaluated first
c) Evaluation of E1 and E2 should necessarily be interleaved
d) Order of evaluation of E1 and E2 is of no consequence
Answer: b
Clarification: E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2.