Consider the following grammar. S → S#cS | SS | Sε | <S> | a | b | c The…

2025

Consider the following grammar.

S → S#cS | SS | Sε | <S> | a | b | c

The cardinality of Follow(s) is

  1. A.

    6

  2. B.

    8

  3. C.

    5

  4. D.

    7

Attempted by 21 students.

Show answer & explanation

Correct answer: D

  1. Rule 1: Start Symbol

    Since S is the start symbol, the end-of-input marker $ is always in Follow(S).

    • Follow(S) = {$}

  2. Rule 2: S -> S#cS

    • Looking at the first S (before #), the terminal # follows S.

    • Looking at the second S (at the end), anything in Follow(S) is added to Follow(S) (no new terminals).

    • Follow(S) = {$, #}

  3. Rule 3: S -> SS

    • For the first S, anything in First(S) is added to Follow(S).

    • From the productions, First(S) = {a, b, c, <}.

    • Follow(S) = {$, #, a, b, c, <}

  4. Rule 4: S -> <S>

    • The terminal > follows S.

    • Follow(S) = {$, #, a, b, c, <, >}

Final Set and Cardinality

The complete set is Follow(S) = { $, #, a, b, c, <, > }.

The number of elements (cardinality) is 7.

Correct Option: 4

Explore the full course: Mppsc Assistant Professor