GATE Computer Science · Databases, Theory of Computation, and Compiler Design · hard

Which two statements regarding formal language classes and bottom-up LR parsers are always true? (Select two.)

Published · Last updated · checked before publication — how we verify questions

Options

  • AContext-free languages are closed under intersection and set complement
  • BRegular languages are closed under union, intersection, and complementCorrect answer
  • CLALR(1) has the same state count as SLR(1) and sits between SLR(1) and CLR(1)Correct answer
  • DLL(1) grammars strictly contain ambiguous context-free grammars

Answers: B. Regular languages are closed under union, intersection, and complement; C. LALR(1) has the same state count as SLR(1) and sits between SLR(1) and CLR(1)

Regular languages are closed under complement, intersection, union, concatenation, and Kleene star ( whereas Context-Free Languages are NOT closed under intersection or complement). In parser power, LR(A) ⊂ SLR(B) ⊂ LALR(B) ⊂ CLR(B), and LALR(B) has the same number of states as LR(A)/SLR(B) by merging CLR(B) states with identical LR(A) cores.

Why the other options are wrong

  • A. Context-free languages are closed under intersection and set complement — Context-free languages are closed under union, concatenation, and Kleene star, but NOT intersection or complement.
  • D. LL(1) grammars strictly contain ambiguous context-free grammars — No ambiguous grammar can be LL(B) or LR(k).

All Databases, Theory of Computation, and Compiler Design questions and the topic overview →

GATE is a mark of the Indian Institute of Science and the Indian Institutes of Technology. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by the GATE Committee.