Given the following statements: S1 : SLR uses FOLLOW information to guide…

2013

Given the following statements:

S1 : SLR uses FOLLOW information to guide reductions. In the case of LR and LALR parsers, the lookaheads are associated with the items and they make use of the left context available to the parser.

S2 : LR grammar is a larger subclass of context-free grammar as compared to SLR and LALR grammars.

Which of the following is true?

  1. A.

    S1 is not correct and S2 is not correct.

  2. B.

    S1 is not correct and S2 is correct.

  3. C.

    S1 is correct and S2 is not correct.

  4. D.

    S1 is correct and S2 is correct.

Attempted by 72 students.

Show answer & explanation

Correct answer: D

Concept. Bottom-up LR family parsers differ in HOW they decide a reduction and in HOW many grammars they accept. Two governing facts settle this item: (1) the source of reduce-time lookahead, and (2) the grammar-class containment SLR ⊆ LALR ⊆ LR(1).

  1. S1 — how reductions are guided. An SLR parser has no per-item lookahead; on a complete item A → α· it reduces whenever the next input symbol lies in FOLLOW(A), i.e. it uses FOLLOW information. Canonical LR(1) and LALR(1) instead attach a lookahead set to each item, so the reduce decision is conditioned on the parser state (the left context already seen). This is exactly what S1 asserts, so S1 holds.

  2. S2 — how large the grammar class is. In this comparison “LR” denotes the canonical LR(1) construction. The classes nest strictly: every SLR grammar is LALR and every LALR grammar is LR(1), but not conversely (SLR ⊆ LALR ⊆ LR(1)). Hence canonical LR(1) recognises the largest subclass of context-free grammars among the three, which is precisely S2, so S2 holds.

Cross-check. Counterexamples confirm the strict nesting: there exist LALR grammars that are not SLR (an SLR conflict resolved by LALR-merged lookaheads), and LR(1) grammars that are not LALR (where merging LR(1) states creates a reduce-reduce conflict). Both directions therefore cannot collapse, so LR(1) is genuinely the broadest class.

Result. Both S1 and S2 are correct, so the true statement is “S1 is correct and S2 is correct.”

Explore the full course: Mppsc Assistant Professor