First and Follow solved Examples Part 1 | Syntax Analysis LL(1) Parsing Table | 68

Опубликовано: 25 Октябрь 2024
на канале: Gate Instructors
39,958
133

Playlist for all videos on this topic:    • Compiler Design (COMPUTER SCIENCE) Vi...  
Automata Theory, in hindi, lectures, iit, tutorial, First Follow solved examples Part 1 Video lecture for gate exa m preparation CS IT MCA, first and follow in compiler, how to calculate first and follow in compiler design, compute first and follow for the grammar,
S ::= aBA | BB | Bc
A ::= Ad | d
B ::= ε
We have
FIRST(B) = FIRST(ε)
= {ε}

FIRST(A) = FIRST(Ad) ∪ FIRST(d)
= FIRST(A) ∪ {d}
= {d}

FIRST(S) = FIRST(aBA) ∪ FIRST(BB) ∪ FIRST(Bc)
= FIRST(a) ∪ (FIRST(B)\{ε}) ∪ FIRST(B) ∪ (FIRST(B)\{ε) ∪ FIRST(c)
= {a, ε, c}
Consider the following grammar
FOLLOW
1
(T’) = { +, ), # }
FOLLOW
1
We Want to make First sets so first we list the sets we need

FIRST(E) = {}

FIRST(E') = {}

FIRST(T) = {}

FIRST(T') = {}

FIRST(F) = {}

First We apply rule 2 to T' → ε and E' → ε

FIRST(E) = {}

FIRST(E') = {ε}

FIRST(T) = {}

FIRST(T') = {ε}

FIRST(F) = {}

First We apply rule 3 to T' → *FT' this rule tells us that we can add everything in First(*FT') into First(T')

Since First(*) useing rule 1 is * we can add * to First(T')

FIRST(E) = {}

FIRST(E') = {+,ε}

FIRST(T) = {}

FIRST(T') = {*,ε}

FIRST(F) = {}

First We apply rule 3 to T' → *FT' this rule tells us that we can add everything in First(*FT') into First(T')

Since First(*) useing rule 1 is * we can add * to First(T')

FIRST(E) = {}

FIRST(E') = {+,ε}

FIRST(T) = {}

FIRST(T') = {*,ε}

FIRST(F) = {}

Two more productions begin with terminals F → (E) and F → id If we apply rule 3 to these we get...

FIRST(E) = {}

FIRST(E') = {+,ε}

FIRST(T) = {}

FIRST(T') = {*,ε}

FIRST(F) = {'(',id}

Next we apply rule 3 to T → FT' once again this tells us that we can add First(FT') to First(T)

Since First(F) doesn't contain ε that means that First(FT') is just First(F)

FIRST(E) = {}

FIRST(E') = {+,ε}

FIRST(T) = {'(',id}

FIRST(T') = {*,ε}

FIRST(F) = {'(',id}

Lastly we apply rule 3 to E → TE' once again this tells us that we can add First(TE') to First(E)

Since First(T) doesn't contain ε that means that First(TE') is just First(T)

FIRST(E) = {'(',id}

FIRST(E') = {+,ε}

FIRST(T) = {'(',id}

FIRST(T') = {*,ε}

FIRST(F) = {'(',id}

We want to make Follow sets so first we list the sets we need

FOLLOW(E) = {}

FOLLOW(E') = {}

FOLLOW(T) ={}

FOLLOW(T') = {}

FOLLOW(F) = {}

The First thing we do is Add $ to the start Symbol 'E'

FOLLOW(E) = {$}

FOLLOW(E') = {}

FOLLOW(T) ={}

FOLLOW(T') = {}

FOLLOW(F) = {}

Next we apply rule 2 to E' →+TE' This says that everything in First(E') except forε should be in Follow(T)

FOLLOW(E) = {$}

FOLLOW(E') = {}

FOLLOW(T) ={+}

FOLLOW(T') = {}

FOLLOW(F) = {}

Next we apply rule 3 to E →TE' This says that we should add everything in Follow(E) into Follow(E')

FOLLOW(E) = {$}

FOLLOW(E') = {$}

FOLLOW(T) ={+}

FOLLOW(T') = {}

FOLLOW(F) = {}

Next we apply rule 3 to T → FT' This says that we should add everything in Follow(T) into Follow(T')

FOLLOW(E) = {$}

FOLLOW(E') = {$}

FOLLOW(T) ={+}

FOLLOW(T') = {+}

FOLLOW(F) = {}

Now we apply rule 2 to T' →*FT' This says that everything in First(T') except for ε should be in Follow(F)

FOLLOW(E) = {$}

FOLLOW(E') = {$}

FOLLOW(T) ={+}

FOLLOW(T') = {+}

FOLLOW(F) = {*}

Now we apply rule 2 to F → (E) This says that everything in First(')') should be in Follow(E)

FOLLOW(E) = {$,)}

FOLLOW(E') = {$}

FOLLOW(T) ={+}

FOLLOW(T') = {+}

FOLLOW(F) = {*}

Next we apply rule 3 to E → TE' This says that we should add everything in Follow(E) into Follow(E')

FOLLOW(E) = {$,)}

FOLLOW(E') = {$,)}

FOLLOW(T) = {+}

FOLLOW(T') = {+}

FOLLOW(F) = {*}

Next we apply rule 4 to E' → +TE' This says that we should add everything in Follow(E') into Follow(T) (because First(E') contains ε)

FOLLOW(E) = {$,)}

FOLLOW(E') = {$,)}

FOLLOW(T) = {+,$,)}

FOLLOW(T') = {+}

FOLLOW(F) = {*}

Next we apply rule 3 to T → FT' This says that we should add everything in Follow(T) into Follow(T')

FOLLOW(E) = {$,)}

FOLLOW(E') = {$,)}

FOLLOW(T) = {+,$,)}

FOLLOW(T') = {+,$,)}

FOLLOW(F) = {*}

Finaly we apply rule 4 to T' → *FT' This says that we should add everything in Follow(T') into Follow(F)

FOLLOW(E) = {$,)}

FOLLOW(E') = {$,)}

FOLLOW(T) = {+,$,)}

FOLLOW(T') = {+,$,)}

FOLLOW(F) = {*,+,$,)}
first and follow examples

first and follow in compiler design

first and follow program in c

first and follow ppt

first and follow in compiler design ppt

first and follow algorithm

first and follow examples in compiler design pdf

first and follow parsing