Theory of Computation and Compiler Design Test 4: Number of Questions: 35 Section Marks: 30
Theory of Computation and Compiler Design Test 4: Number of Questions: 35 Section Marks: 30
Directions for questions 1 to 35: Select the correct alterna- 9. Limitation of L-Attributed Grammar is:
tive from the given choices. (A) uses only inherited Attributes.
1. Which of the following is FALSE for regular expres- (B) each inherited attribute inherits either from parent
sions L, M and N? or Left side sibling
(A) L + M = M + L (C) each inherit attribute inherits either from parent or
(B) (L + M) + N = L + (M + N) right side sibling
(C) (LM) N = (LM) N (D) each inherit attribute inherits either from parent or
(D) LM = ML Left side sub tree.
2. Which of the following does not hold for two regular 10. Which of the following statement is false?
expressions R and S? (A) It is always possible to rewrite a SDD to use only
(A) (R*)* = R* synthesized attributes.
(B) (∈ + R)* = R* (B) Evolution of L-Attributed grammar is BUP (Bot-
(C) (R*S*)* = (R + S)* tom up parsing)
(D) None of the above (C) Evolution of S-Attribute grammar is BUP (Bot-
tom up parsing)
3. Which of the following language is not regular?
(D) Evolution of L-Attributed grammar is Depth first.
(i) (0 + 1)*
Traversal, left to right.
(ii) Palindromes over {0, 1}
(iii) {0n10n/n ≥ 1} 11. A grammar is said to be ‘attribute grammar’ if and only
(A) (i), (ii), (iii) (B) (i), (iii) if it has
(C) (ii), (iii) (D) (iii) only (A) L-Attribute definition
(B) S-Attribute definition
4. Identify the regular languages from the following:
(C) SDT which does not have any side effects
(i) Set of strings of balanced parentheses
(D) SDT which must have side effects
(ii) {0n/n is a perfect square}
(iii) {ww/w ∈ {0, 1}*} 12. Which of the following statement is FALSE about
(A) (i), (ii) (B) (ii), (iii) L-Attributed definition?
(C) (i), (iii) (D) None of these (A) Traverse the parse tree in Breadth first manner
from Left to Right.
5. Which of the following properties hold for regular
(B) Evaluate inherited attributes if the node is visited
languages?
for first time.
(A) Complement (B) Difference
(C) Evaluate synthesized attributes if the node is vis-
(C) Reversal (D) All the above
ited for Last time.
6. Which of the following is TRUE? (D) None of the above.
(A) Pushdown automata has same expressing power as
13. Which of the following is not an advantage of reverse
Deterministic finite automata.
polish notation?
(B) NFA is an extension of pushdown automata.
(A) no rules of precedences
(C) Pushdown automata is an extension of ∈-NFA. (B) no associativity
(D) PDA does not have any storage component. (C) no parenthesis
7. Which type of language is accepted by DPDA? (D) not low level representation
(A) Regular languages only 14. A single tape Turing machine M has two states q0 and
(B) Context free languages only q1, of which q0 is the starting state. The tape alphabet
(C) The class of languages between regular languages of M is {0, 1, B} and its input alphabet is {0, 1}, the
and context free languages. symbol B is the blank symbol used to indicate end of an
(D) Recursively enumerable languages only input string. The transition function of M is described
8. Which of the following statement is TRUE about Top in the following table.
down parsing and bottom up parsing? 0 1 B
(A) Bottom up parser is more powerful. q0 q1, 1, R q1, 0, R q1, B, L
(B) Error detection in Top down parser is easy.
q1 q0, 1, R q0, 0, R Halt
(C) Table size in Bottom up parser and Top down pars-
er is approximately equal. Which of the following statements is TRUE about M?
(D) Design complexity of Top down parser and Bot- (A) M accepts all strings that end with 0 only
tom up parser are same. (B) M accepts all strings that end with 1 only
Theory of Computation and Compiler Design Test 4 | 3.161
(C) M accepts all strings of (0 + 1)+ only. 21. Let L and M be two context free languages then which
(D) M accepts all strings of (0 + 1)* 01 (0 + 1)* + of the following is not context free?
1 * 0* (A) L ∪ M (B) L M
15. Which phase is most important for complex parts of (C) L* (D) L ∩ M
any modern compiler? 22. Which of the following are undecidable?
(A) Syntax Analysis (B) Semantic Analysis (A) Is a given CFG, G ambiguous?
(C) Target code generator (D) Code optimizer (B) Is the intersection of two CFL’s empty?
16. Match the following: (C) Are two CFL’s the same.
Regular
(D) All the above
Finite Automata
expression 23. Which languages are accepted by Turing machines
R S only?
(i) R + S (A) ∈ (A) Regular languages
(B) Context free languages
∈ (C) Recursively enumerable languages
(ii) RS (B) ∈ R ∈
(D) All the above
∈
24. Which of the following languages are accepted by
Turing machines?
∈ ∈ (i) set of all strings of balanced parentheses
R
(iii) R* (C) (ii) {0n1m0n1m/m, n ≥ 1}
S (iii) {ww/w∈{0, 1}*}
∈ ∈
(A) (i), (ii) (B) (ii), (iii)
(A) (i)–(C), (ii)–(B), (iii)–(A) (C) (i), (iii) (D) (i), (ii), (iii)
(B) (i)–(A), (ii)–(B), (iii)–(C) 25. Which of the following is FALSE?
(C) (i)–(C), (ii)–(A), (iii)–(B) (A) A problem L is decidable if it is a recursive lan-
(D) (i)–(B), (ii)–(A), (iii)–(C) guage.
17. Consider below DFA: (B) A problem L is undecidable if it is not a recursive
language.
1
(C) If L is a recursive language then L is also recur-
0 sive.
(D) If L is recursively enumerable language then it is
also recursive language.
1
26. Consider the following grammar:
What is the language accepted by this DFA? S → Sd/aA/aB
(A) 1* + (01)* (B) [1* (01)*]* A → ab/d
(C) (1 + 01)* (D) Both (B) and (C) B → acd/dde
18. Consider the grammar: Parse a string w = adde using Brute force technique,
S → AS/∈ How many back tracks are required?
A → aa/ab/ba/bb (A) 6 (B) 4
What is the language generated by this grammar? (C) 0 (D) None of the above
(A) Generates all the strings of the form {anbn/n ≥ 0} 27. Consider the following Grammar:
(B) Generates all the strings of even length.
S → Aa/bAc/Bc/bBa
(C) Generates all the strings of equal number of a’s
A → d/a/aB
and b’s.
(D) Generates all the strings possible with {a, b}*. B → d/e
Parse a string w = “bea” using Brute Force Technique,
19. Which of the following is not Context-free language? What is the maximum height of parse tree and how
(A) {anbncn/n ≥ 1} (B) {wwR/w ∈ (0 + 1)*} many back tracks are required?
(C) {wcw /w ∈ (0 + 1)*} (D) {anbn/n ≥ 1}
R
(A) 2, 13 (B) 3, 16
20. Which of the following are Deterministic context free (C) 3, 4 (D) 2, 4
language(s)?
(i) {0n1m+n 1m/m, n ≥ 0} 28. In LL(1) parsing, while parsing a string ‘w’, the Top
(ii) {0n1m0n/n and m are arbitrary} of the stack contains non terminal ‘X’ and input string
(A) (i) only (B) (ii) only look ahead symbol ‘a’ and LL(1) parsing Table con-
(C) Both (i) and (ii) (D) Neither (i) nor (ii) tains M[X, a]X → aBc
3.162 | Theory of Computation and Compiler Design Test 4
After performing appropriate action, how many sym- 32. While constructing LL(1) parsing Table, place produc-
bols are there in stack and what is the Top of the stack? tion ‘A → a’ in the following cells of M[X, a], where
(A) 4, a (B) 4, c ‘a’ is [first (a) contains ‘∈’ and terminals]:
(C) 3, a (D) 3, c (A) only first (a) – {∈}
(B) first (a) ∪ follow(A)
29. Consider the following grammar:
(C) only in follow(A) – {∈}
A → X1|X2|e
(D) first (a) ∪ follow(A) – {∈}
here X1 and X2 are the productions of ‘A’.
The grammar should be LL(1) grammar if and only if 33. In LL(1) parsing Table, M[X, $] contains production if
(A) first(X1) ∩ first (x2) = f and only if [here X → ABC]
(B) first(X1) = first(x2) (A) first (X) contains {∈}
(C) follow(A) ∩ first(x1) ≠ f (B) first (A) contains {∈}
(D) first(X1) ∩ first (x2) ≠ f (C) first (AB) contains {∈}
(D) data is insufficient
30. A non-terminal ‘A’ is deriving one production
A → X1 X2 X3, 34. Consider the following operator precedence Relational
here X1, X2, X3 are non terminals, which have some Table. For the string W = id + id, × id, how many han-
productions. Which of the following statement always dles are possible to accept?
holds to find first(A)? id + * $
*
(A) first(A) = first(X1) if (X1 ⇒ ∈) id •> •> •>
(B) first(A) = first(X1)∪ first(X2) ∪ first(X3)
+ <• •> <• •>
(C) first(A) = first(X1)∪ first(X2) ∪ first(X3) – {∈}
* * <• •> •> •>
if (X1 ⇒ ∈)
$ <• <• <•
(D) first(A) = first(X1) – {∈} ∪ first(X2 X3)
*
if (X1 ⇒ ∈) (A) 4 (B) 5
31. Consider the following Grammar: (C) 6 (D) Data insufficient
S → AB/aAbAd 35. In the above precedence table, what is the associativity
B → a/b/c/∈, find follow of the Non-terminal A? of ‘+’ and ‘*’?
(A) follow(A) = first(B) – {∈} (A) + is right associative and * is left associative
(B) follow(A) = first(B) ∪ {d} (B) + and * Left associative
(C) follow(A) = first(B) ∪ {$} – {∈} (C) + and * Right associative
(D) follow(A) = first(B) ∪ {d, $} – {∈} (D) Data insufficient
Answer Keys
1. D 2. D 3. C 4. D 5. D 6. C 7. C 8. A 9. B 10. B
11. C 12. A 13. D 14. C 15. D 16. C 17. D 18. B 19. C 20. C
21. D 22. D 23. C 24. D 25. D 26. D 27. B 28. C 29. A 30. D
31. D 32. D 33. A 34. B 35. B
11. A grammar is said to be attribute grammar if and only 19. The CFL’s are accepted by PDA’s. The PDA has a stack
if it does not contain side effects like any action rule storage it moves only towards right side of string. It
print something. Choice (C) can’t check equality of a’s b’s and c’s. But it can check
12. L-Attributed grammar Traverses parse tree in Depth {wwR}, {wcwR}, {an bn} patterns. Choice (C)
first search manner, left to right. Choice (A) 20. {0n 1m+n 0m/m, n ∈ 0}
13. Reverse polish notation, Abstract syntax tree, Direct Push 0’s whenever 1’s are in input, pop 0’s i.e., match-
acyclic graph are high level intermediate code forms, ing between 0’s and 1’s. After that push remaining 1’s
three address code is low level intermediate code form. and pop them whenever 0’s occur.
Choice (D) There is no non determinism. So it is DCFL.
Similarly we can check the equality of 0’s in (ii) by
14.
pushing first set of 0’s & pop them with last set of 0’s.
B, B/L Choice (C)
1,0,R
21. CFL’s are not closed under intersection. Choice (D)
0,1,R B 22. Choice (D)
qo q1 HALT
23. Recursively enumerable languages are only accepted
by TM. Regular, CFL’s are accepted by TM but they are
also accepted by FA, PDA respectively. Choice (C)
24. A TM has infinite storage buffer, which can move in
0, 1, R two directions (forward, backward) and also it has both
read and write capabilities.
1,0,R
All the given three languages are accepted by TM’s.
For example, take string 0110 and check whether it is Choice (D)
accepted 25. A language L is recursive if both L and L are recur-
by TM or not sively enumerable. Choice (D)
26. Fall into infinite Loop in Brute Force Technique,
qo 0110B
Blindly substitute the first productions.
1q1 110B S ⇒ Sd
⇒ Sdd
10qo10B
⇒ Sddd
100q1 0B ⇒ Sdddd
1001 qoB :
:
Infinite Loop
q1 Choice (D)
27.
Final accepting state S S
S S S S
6
\ Any string of length 1 or more of {0, 1} is accepted
a a A a A a a
by given TM. Choice (C) A A A b A c
1 2 5
15. In early age of compilers, developers focused on syntax a B a B 7
d a a B d
analysis and recently, on optimization, focused mainly 3
4
d
on code optimization and risc. Choice (D) e
S S S
12 S 15 S
16. Choice (C)
b A c b A b A
17. Given DFA accepts any number of 1’s and (01’s) 11 B c B c
repeatedly. The regular expression is (1 + 01)* 8
a a B a B 13 14
= [1* (01)*]*. Choice (D) d e
9 10
18. S → AS/∈ d e
S S
A → aa/ab/ba/bb
It generates {an bn} but it generates {aa, aaaa, ...} b Ba b B a
also. It also won’t generate equal number of a’s and b’s. 16
It won’t generate single ‘a’. It generates even length d e
strings. Choice (B)
Choice (B)
3.164 | Theory of Computation and Compiler Design Test 4