Compilers Questions and Answers – L-Attributed Definition – 1

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “L-Attributed Definition – 1”.

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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: c
Explanation: They have dynamically changing types.

3. What is grammar?

S -> C C 
C -> eC | d 
advertisement
advertisement

a) LL (1)
b) SLR (1) but not LL (1)
c) LALR (1) but not SLR (1)
d) LR (1) but not LALR (1)
View Answer

Answer: c
Explanation: The grammar is CLR and can be reduced to LALR.

4. The 3-address code sequence generated by which definition?

Note: Join free Sanfoundry classes at Telegram or Youtube
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
View Answer

Answer: d
Explanation: In 3-address code we use temporary variables.
advertisement

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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: 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.
advertisement

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
View Answer

Answer:d
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: b
Explanation: (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
View Answer

Answer: b
Explanation: E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2.

Sanfoundry Global Education & Learning Series – Compilers.

To practice all areas of Compilers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.