Notes:Parsing

From Maths
Revision as of 19:06, 24 September 2016 by Alec (Talk | contribs) (Saving notes)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Algorithms

These algorithms apply to CFGs:

  • α,β,γ, denote sequences (possibly empty) of terminals and nonTerminals Caution:Done from memory, still to do, check this
    • EXCEPT: ε - which means "the empty string"
  • a,b,c terminal symbols Caution:Check
  • a,b,c terminal or non terminal symbols Caution:Check

Nullable

Definition of Nullable(α) (a predicate):

  • Nullable(α)[α˙ε]

The algorithm for Nullable is defined by structural induction:

  1. Nullable(ε)=true
  2. Nullable(aa)=false
  3. Nullable(αβ)=Nullable(α)Nullable(β)
  4. Nullable(N)=Nullable(α1)Nullable(αn)
    • Where N consists of n productions, Nα1 to Nαn

First

Definition of First(α) (a set):

  • cFirst(α)β (possibly empty)[α˙cβ]

The algorithm for First is also defined by structural induction:

  1. First(ε) =
  2. First(a)={a}
  3. First(αβ)={First(α)First(β)if Nullable(α)First(α)if not Nullable(α)
  4. First(N)=First(α1)First(αn)
    • Where N has n productions, Nα1 to Nαn

Follow

Definition of Follow(N) (a set (of terminals)):

  • aFollow(α) (a derivation from the start symbol, S, such that S˙αNaβ for α,β (possibly empty) sequences of grammar symbols)

Note that unlike the others given this is not a property directly from the argument, but a property based on all productions that use N (directly or not)

Algorithm to come.