GATE / CS ARCHIVE

GATE CSE 2007 / QUESTION 53

Regular grammars versus existence of LR(1) grammars

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2007 paper

GATE 2007, Q53 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 53, GATE 2007: Consider P: Every regular grammar is LL(1). Q: Every regular language has an LR(1) grammar. Which is true?
Options:
(A) Both P and Q true
(B) P true,Q false
(C) P false,Q true
(D) Both false
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Approach. P concerns every presentation of a language, whereas Q asks whether a suitable presentation exists. A language can have a poorly factored grammar even though another grammar parses deterministically.

2. Derivation and interpretation. P is false: the right-linear regular grammar S→aA | aB, A→b, B→c has two alternatives whose FIRST sets both contain a, so this particular grammar is not LL(1). Q is true: construct a grammar from a DFA by using one nonterminal per state, production Q→aR for each transition on a, and Q→ε for each accepting state. Determinism gives at most one alternative per terminal; epsilon is selected at end of input. This yields an LL(1), hence LR(1), grammar for the regular language (or use the standard inclusion of regular languages in deterministic context-free languages). Thus P false and Q true, option C.

Original paper, page 13