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
- A.
6
- B.
8
- C.
5
- D.
7
Attempted by 21 students.
Show answer & explanation
Correct answer: D
Rule 1: Start Symbol
Since S is the start symbol, the end-of-input marker $ is always in Follow(S).
Follow(S) = {$}
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) = {$, #}
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, <}
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