πŸ“Š Theory of Computation and Compiler Design
Q. Consider the following grammar.
S -> S * E
S -> E
E -> F + E
E -> F
F -> id
Consider the following LR(0) items corresponding to the grammar above.
(i) S -> S * .E
(ii) E -> F. + E
(iii) E -> F + .E
Given the items above, which two of them will appear in the same set in the canonical
sets-of-items for the grammar?
  • (A) (i) and (ii)
  • (B) (ii) and (iii)
  • (C) (i) and (iii)
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) None of the above
πŸ“Š Theory of Computation and Compiler Design
Q. A canonical set of items is given below
S --> L. > R
Q --> R.
On input symbol < the set has
  • (A) a shift-reduce conflict and a reduce-reduce conflict.
  • (B) a shift-reduce conflict but not a reduce-reduce conflict.
  • (C) a reduce-reduce conflict but not a shift-reduce conflict.
  • (D) neither a shift-reduce nor a reduce-reduce conflict.
πŸ’¬ Discuss
βœ… Correct Answer: (D) neither a shift-reduce nor a reduce-reduce conflict.
πŸ“Š Theory of Computation and Compiler Design
Q. Consider the grammar defined by the following production rules, with two
operators ∗ and +
S --> T * P
T --> U | T * U
P --> Q + P | Q
Q --> Id
U --> Id
Which one of the following is TRUE?
  • (A) + is left associative, while ∗ is right associative
  • (B) + is right associative, while ∗ is left associative
  • (C) Both + and ∗ are right associative
  • (D) Both + and ∗ are left associative
πŸ’¬ Discuss
βœ… Correct Answer: (B) + is right associative, while ∗ is left associative
πŸ“Š Theory of Computation and Compiler Design
Q. Consider the following grammar:
S → FR
R → S | ε
F → id
In the predictive parser table, M, of the grammar the entries M[S, id] and M[R, $]
respectively.
  • (A) {S → FR} and {R → ε }
  • (B) {S → FR} and { }
  • (C) {S → FR} and {R → *S}
  • (D) {F → id} and {R → ε}
πŸ’¬ Discuss
βœ… Correct Answer: (A) {S → FR} and {R → ε }
πŸ“Š Theory of Computation and Compiler Design
Q. Consider the following translation scheme. S → ER R → *E{print("*");}R | ε E→ F + E {print("+");} | F F → (S) | id {print(id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input '2 * 3 + 4', this translation scheme prints
  • (A) 2 * 3 + 4
  • (B) 2 * +3 4
  • (C) 2 3 * 4 +
  • (D) 2 3 4+*
πŸ’¬ Discuss
βœ… Correct Answer: (D) 2 3 4+*
πŸ“Š Theory of Computation and Compiler Design
Q. Consider the grammar S → (S) | a Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar be n1, n2 and n3 respectively. The following relationship holds good
  • (A) n1 < n2 < n3
  • (B) n1 = n3 < n2
  • (C) n1 = n2 = n3
  • (D) n1 ≥ n3 ≥ n2
πŸ’¬ Discuss
βœ… Correct Answer: (B) n1 = n3 < n2
πŸ“Š Theory of Computation and Compiler Design
Q. Consider the following expression grammar. The seman-tic rules for expression
calculation are stated next to each grammar production.
E → number E.val = number. val
| E '+' E E(1).val = E(2).val + E(3).val
| E '×' E E(1).val = E(2).val × E(3).val
The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1)
parser generator) for parsing and evaluating arithmetic expressions. Which one of the
following is true about the action of yacc for the given grammar?
  • (A) It detects recursion and eliminates recursion
  • (B) It detects reduce-reduce conflict, and resolves
  • (C) It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce action
  • (D) It detects shift-reduce conflict, and resolves the conflict in favor of a reduce over a shift action
πŸ’¬ Discuss
βœ… Correct Answer: (C) It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce action
πŸ“Š Theory of Computation and Compiler Design
Q. Which one of the following languages over the alphabet {0,1} is described by the regular expression: (0+1)*0(0+1)*0(0+1)*?
  • (A) The set of all strings containing the substring 00.
  • (B) The set of all strings containing at most two 0’s.
  • (C) The set of all strings containing at least two 0’s.
  • (D) The set of all strings that begin and end with either 0 or 1.
πŸ’¬ Discuss
βœ… Correct Answer: (C) The set of all strings containing at least two 0’s.
πŸ“Š Theory of Computation and Compiler Design
Q. Which one of the following is FALSE?
  • (A) There is unique minimal DFA for every regular language
  • (B) Every NFA can be converted to an equivalent PDA.
  • (C) Complement of every context-free language is recursive.
  • (D) Every nondeterministic PDA can be converted to an equivalent deterministic PDA.
πŸ’¬ Discuss
βœ… Correct Answer: (D) Every nondeterministic PDA can be converted to an equivalent deterministic PDA.

Jump to