Professional Documents
Culture Documents
Compiler Design Test 1: Number of Questions: 25 Section Marks: 30
Compiler Design Test 1: Number of Questions: 25 Section Marks: 30
Directions for questions 1 to 25: Select the correct alterna- 8. Which of the following action is not performed by an
tive from the given choices. LL parser?
1. Which of the following implementation of Lexical ana- (i) Matching top of the parser stack with next input
lyzer is easy to modify and faster? token.
(i) Lexical-analyzer by hand (ii) Predicting a production and apply it in a deriva-
(ii) Lexical-analyzer generator tion step.
(A) (i) only (B) (ii) only (iii) Accept and terminate the parsing of a sequence of
(C) Both (i) and (ii) (D) Neither (i) nor (ii) tokens.
(iv) Reporting an error message.
2. Which of the following tasks are performed by a
(A) (i), (iv) (B) (iii), (iv)
Lexical analyzer?
(C) (ii), (iii) (D) None of the above
(i) Identification of Lexemes
(ii) Stripping-out Comments 9. Consider the following grammar:
(iii) Stripping-out white spaces S → AcB
(iv) Correlating error messages generated by the com- A → aA | e
piler with the source program. B → bBS | e
(A) (i), (ii) (B) (i), (ii), (iii) For this grammar, FOLLOW(B) is
(C) (iii), (iv) (D) (i), (ii), (iii), (iv) (A) {a, $} (B) {a, c}
(C) {a, c, $} (D) {c}
3. Which of the following statement is TRUE?
(i) Every LL(k) language is deterministic context- 10. Which of the following statements is FALSE?
free language. (A) Every LR(0) grammar is in SLR (1).
(ii) Every deterministic context free language is LL(k) (B) Every SLR (1) grammar is in LR (0).
language. (C) Every SLR(1) grammar is a canonical LR(1)
(A) (i) only (B) (ii) only grammar.
(C) Both (i) and (ii) (D) Neither (i) nor (ii) (D) Every LR(1) grammar is not necessarily SLR(1).
4. Which of the following grammar is LL(3) grammar but 11. Which of the following grammars for {an bn+k| n, k ∈ N}
not LL(2) and not LL(1)? are in LL(1)?
(A) S → aS|b (B) S → aaS | ab| b (i) S → PQ
(C) S → aaaS | aab | ab | b (D) None of the above P → aPb | e
Q → bQ | e
5. On errorneous input,
(ii) S → aSb| T
(A) LALR parser makes more moves than LR parser.
T → bT| e
(B) LR parser makes more moves than LALR parser.
(A) (i) only (B) (ii) only
(C) LALR parser makes equal number of moves as an
(C) Both (i) and (ii) (D) Neither (i) nor (ii)
LR parser.
(D) Unpredictable 12. Based on which of the following parameters does a
6. What kind of conflict does the following grammar LR(k) parser performs reduction?
leads to? (i) The complete left context
S→A (ii) The reducible phrase itself
A → xA | yA | y (iii) The k-terminal symbols to its right
(A) Shift-reduce conflict (A) (i), (iii) only (B) (ii), (iii) only
(B) Reduce-reduce conflict (C) (i), (ii),(iii) (D) (i) only
(C) No conflict exist 13. After removing left-recursion from the following gram-
(D) Both (A) and (B) mar the resultant grammar will be:
7. Which of the following statement(s) is/are TRUE? P→P+Q|Q
(i) Synthesized attributes may be calculated only Q → int | (P)
from attributes of children. (A) P → Q + Q
(ii) Inherited attributes may be calculated only from Q → int | (P)
attributes of parents. (B) P → QP1
(A) (i) only (B) (ii) only P1 → +QP1 | e
(C) Both (i) and (ii) (D) Neither (i) nor (ii) Q → int | (P)
3.146 | Compiler Design Test 1
24. Which of the following is TRUE about LR-attributed 25. Which of the following conditions must hold to call a
grammar? grammar is in SLR(1)?
(i) Attributes can be evaluated in LR parsing (i) For any production A → x.yz in the set, with ter-
(ii) LR-Attribute grammars are a subset of L-attribut- minal y, there is no complete item B → W. In that
ed grammars set with ‘y’ in FOLLOW (B).
(iii) LR-attribute grammars are a subset of S-attributed (ii) For any two complete productions A → X and
grammars. B → Y. In the set, the follow sets must be disjoint.
(A) (i), (ii) only (B) (ii), (iii) only (A) (i) only (B) (ii) only
(C) (i), (iii) only (D) (i), (ii), (iii) only (C) Both (i) and (ii) (D) Neither (i) nor (ii)
Answer Keys
1. B 2. D 3. A 4. C 5. A 6. A 7. A 8. D 9. C 10. B
11. A 12. C 13. B 14. B 15. C 16. C 17. D 18. A 19. A 20. B
21. D 22. B 23. D 24. A 25. C