Introduction to Syntax

From Wiki**3

Revision as of 16:03, 6 April 2008 by Root (talk | contribs) (New page: == Computing the FIRST Set == The FIRST set for a given string or symbol can be computed as follows: # If '''a''' is a terminal symbol, then FIRST('''a''') = {'''a'''} # If X is a non-te...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Computing the FIRST Set

The FIRST set for a given string or symbol can be computed as follows:

  1. If a is a terminal symbol, then FIRST(a) = {a}
  2. If X is a non-terminal symbol and X -> ε is a production then add ε to FIRST(X)
  3. If X is a non-terminal symbol and X -> Y1...Yn is a production, then
    a ∈ FIRST(X) if a ∈ FIRST(Yi) and ε ∈ FIRST(Yj), i<j (i.e., Yj ε)

As an example, consider production X -> Y1...Yn

  • If Y1 ε then FIRST(X) = FIRST(Y1)
  • If Y1 ε and Y2 ε then FIRST(X) = FIRST(Y1) \ {ε} ∪ FIRST(Y2)
  • If Yi ε (∀i) then FIRST(X) = ∪i(FIRST(Yi)\{ε}) ∪ {ε}