∑GateAndNet
Practice MCQs
GATE CS / Compiler Design
Edit
INTERMEDIATE🔥 High-Yield Exam Topic 4 min read 4 views

LL(1) & LR(0), SLR(1), LALR(1), CLR(1) Parsing Power & Conflicts

FIRST/FOLLOW rules, parsing hierarchy Venn relationships, state count equality between SLR(1) and LALR(1), and ambiguity.

LL(1) Grammar Necessary & Sufficient Conditions

  1. Grammar must be free of Left Recursion (an left-recursive grammar can never be LL(k)LL(k)).
  2. For every non-terminal A→α∣βA \to \alpha \mid \beta:
    • FIRST⁡(α)∩FIRST⁡(β)=∅\operatorname{FIRST}(\alpha) \cap \operatorname{FIRST}(\beta) = \emptyset
    • If ϵ∈FIRST⁡(α)\epsilon \in \operatorname{FIRST}(\alpha), then FIRST⁡(β)∩FOLLOW⁡(A)=∅\operatorname{FIRST}(\beta) \cap \operatorname{FOLLOW}(A) = \emptyset.
🚨 Exam Trap Alert

Ambiguous Grammars: An ambiguous grammar can NEVER be LL(k)LL(k) or LR(k)LR(k) for any k≥0k \ge 0! Also, when merging CLR(1)CLR(1) states with identical LR(0)LR(0) cores to form LALR(1)LALR(1), no new Shift-Reduce conflict can ever arise — only a Reduce-Reduce conflict can be introduced!

📐 Quick Revision Formula Sheet
Expressive Power Inclusion
LR(0)⊊SLR(1)⊊LALR(1)⊊CLR(1)=DCFL\text{LR}(0) \subsetneq \text{SLR}(1) \subsetneq \text{LALR}(1) \subsetneq \text{CLR}(1) = \text{DCFL}
💡 LL(1) subsetneq CLR(1), and every LL(1) or LR(k) grammar is UNAMBIGUOUS!
DFA State Count Relationship
∣StatesLR(0)∣=∣StatesSLR(1)∣=∣StatesLALR(1)∣≤∣StatesCLR(1)∣|\text{States}_{\text{LR}(0)}| = |\text{States}_{\text{SLR}(1)}| = |\text{States}_{\text{LALR}(1)}| \le |\text{States}_{\text{CLR}(1)}|
💡 Merging CLR(1) cores to form LALR(1) can NEVER introduce Shift-Reduce conflicts (only Reduce-Reduce)!
#Compiler Design#Parsing#LL1#LR

🎯 Practice PYQs on This Topic (4)

Q1.GATE CS Compiler PYQMCQMEDIUM
+2 Marks • -0.67 Neg

Which of the following statements about bottom-up LR parsers is FALSE?

Q2.GATE CS CompilerMCQEASY
+1 Marks • -0.33 Neg

Which pair of bottom-up LR parsers always have the exact same number of states for any given context-free grammar?

Q3.GATE CS CompilerMCQMEDIUM
+2 Marks • -0.67 Neg

If a Context-Free Grammar GG is ambiguous, which of the following statements is guaranteed to be TRUE?

Q4.GATE CS CompilerMCQEASY
+2 Marks • -0.67 Neg

How many lexical tokens does a C lexical analyzer emit for the statement: printf("i = %d, &i = %x", i, &i);?

Previous TopicMinimal DFA Construction, Pumping Lemma, CFGs & Pushdown AutomataNext Topic Syntax-Directed Translation (SDT), Three-Address Code & Register Liveness