Notes:Parsing
From Maths
Contents
[hide]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:
- Nullable(ε)=true
- Nullable(aa)=false
- Nullable(αβ)=Nullable(α)∧Nullable(β)
- Nullable(N)=Nullable(α1)∨⋯∨Nullable(αn)
- Where N consists of n productions, N→α1 to N→αn
First
Definition of First(α) (a set):
- c∈First(α)⟺∃β (possibly empty)[α˙⟹cβ]
The algorithm for First is also defined by structural induction:
- First(ε) = ∅
- First(a)={a}
- First(αβ)={First(α)∪First(β)if Nullable(α)First(α)if not Nullable(α)
- 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)):
- a∈Follow(α)⟺∃ (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.