• Motivating the FIRST, FOLLOW, and FIRST+ sets

  • CS4240

  • for parsing context-free-language

  • we consider bottom-up parsing, where each character matches a nonterminal

  • the FIRST set of a nonterminal is all characters which may be the first character of that nonterminal

  • the FOLLOW set of a nonterminal is all characters which may follow that nonterminal

  • Consider parsing a string.

    • It may seem like we can just match using the FIRST set of each nonterminal (so e.g., expr has the FIRST set including ( and the parser that sees ( can pick expr in its candidates)

    • However, we cannot use the FIRST set to match which nonterminal if the FIRST set contains ϵ\epsilon, so if ϵ∈FIRST\epsilon\in\text{FIRST}, use the union of the FIRST set and the FOLLOW set (since the nonterminal may be ϵ\epsilon).

Snapshot: 84b34f19db8bb5a5ba52e85643e64a9ae86eeffeb6adbcd9b323cdcfe913a6fc117a765d81740449b2b352eafd96385b999cfdb00145d6017943a0c3191903f6 list?snapshot=84b34f19db8bb5a5ba52e85643e64a9ae86eeffeb6adbcd9b323cdcfe913a6fc117a765d81740449b2b352eafd96385b999cfdb00145d6017943a0c3191903f6