First and Follow Sets
First and Follow Sets
First and Follow Sets
I have found First and Follow Sets very difficult to follow, so I have tried to rewrute the rules for createing
them so that they are easier to understand.
Rules for First Sets
1. If X is a terminal then First(X) is just X!
2. If there is a Production X -> ∈ then add∈ to first(X)
3. If there is a Production X -> Y1Y2..Yk then add first(Y1Y2..Yk) to first(X)
4. First(Y1Y2..Yk) is either
1. First(Y1) (if First(Y1) doesn't contain ∈)
2. OR (if First(Y1) does contain ∈) then First (Y1Y2..Yk) is everything in First(Y1) <except
for ∈ > as well as everything in First(Y2..Yk)
3. If First(Y1) First(Y2)..First(Yk) all contain ∈ then add ∈ to First(Y1Y2..Yk) as well.