SlideShare a Scribd company logo
First Set
• First (=A) = First(A) , if  ∉ First(A)
First(A) – {} ∪First(), if  ∈ First(A)
We will use some examples for this operation…
Red : A Blue : 
First Set (2)
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Red : A Blue : 
First Set (2)
• First (EPrefix(E))=First(Prefix(E)) ? = {Waiting operation}
– We don’t know First(Prefix) at this moment.
– So we keep the operation of First(Prefix(E)) until we know First(Prefix).
• First (EV Tail) = First(V) = {V}
• First (PrefixF) = First(F) = {F}
• First (Prefix )= First() - {} ∪First() = {}
• First (Tail+E) = First(+) = {+}
• First (Tail ) = First() - {} ∪First() = {}
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Red : A Blue : 
Step 1:
First Set (2)
• First (EPrefix(E))=First(Prefix(E)) ? = {Waiting operation}
– We don’t know First(Prefix) at this moment.
– So we keep the operation of First(Prefix(E)) until we know First(Prefix).
• First (EV Tail) = {V}
• First (PrefixF) = {F}
• First (Prefix )= {}
• First (Tail+E) = {+}
• First (Tail ) = {}
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Red : A Blue : 
Step First Set
E Prefix Tail ( ) V F +
Step 1 First(Prefix(E))∪{V} {F, } {+, }
Step 1:
First Set (2)
• First (EPrefix(E))=First(Prefix(E)) ? = {Waiting operation}
– In this step, we know First(Prefix).
– So we replace the First(Prefix) with {F, }.
• First (EV Tail) = {V}
• First (PrefixF) = {F}
• First (Prefix )= {}
• First (Tail+E) = {+}
• First (Tail ) = {}
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Red : A Blue : 
{F, }
Step 2:
Step First Set
E Prefix Tail ( ) V F +
Step 1 First(Prefix(E))∪{V} {F, } {+, }
First Set (2)
• First (EPrefix(E))=First(Prefix(E)) = {F, }
= {F, } - {} ∪ First((E)) = {F, (}
• First (EV Tail) = {V}
• First (PrefixF) = {F}
• First (Prefix )= {}
• First (Tail+E) = {+}
• First (Tail ) = {}
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Red : A Blue : 
Step 2:
Step First Set
E Prefix Tail ( ) V F +
Step 1 First(Prefix(E))∪{V} {F, } {+, }
First Set (2)
• First (EPrefix(E))= {F, (}
• First (EV Tail) = {V}
• First (PrefixF) = {F}
• First (Prefix )= {}
• First (Tail+E) = {+}
• First (Tail ) = {}
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Red : A Blue : 
Step First Set
E Prefix Tail ( ) V F +
Step 1 First(Prefix(E))∪{V} {F, } {+, }
Step 2 {F, (} ∪ {V} ={F, (, V} {F, } {+, }
Step 2:
First Set (2)
• First (EPrefix(E))= {F, (}
• First (EV Tail) = {V}
• First (PrefixF) = {F}
• First (Prefix )= {}
• First (Tail+E) = {+}
• First (Tail ) = {}
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Step First Set
E Prefix Tail ( ) V F +
Step 1 First(Prefix(E))∪{V} {F, } {+, }
Step 2 {F, (} ∪ {V} ={F, (, V} {F, } {+, }
Step 3 {F, (, V} {F, } {+, } {(} {)} {V} {F} {+}
If no more change…
The first set of a terminal
symbol is itself
Red : A Blue : 
Step 3:
Another Example….
First Set (2)
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
Red : A Blue : 
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = First(a) ={a}
• First (SB) = First(B)
• First (B  bBe) = First(b)={b}
• First (B  C) = First(C)
• First (C  cCe) = First(c) ={c}
• First (C  d) = First(d)={d}
Red : A Blue : 
Step 1:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = First(B)
• First (B  bBe) = {b}
• First (B  C) = First(C)
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step First Set
S B C a b c d
Step 1 {a}∪First(B) {b}∪First(C) {c, d}
Step 1:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = First(B) = {b}∪First(C)
• First (B  bBe) = {b}
• First (B  C) = First(C)
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step First Set
S B C a b c d
Step 1 {a}∪First(B) {b}∪First(C) {c, d}
Step 2:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = {b}∪First(C)
• First (B  bBe) = {b}
• First (B  C) = First(C)
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step 2:
Step First Set
S B C a b c d
Step 1 {a}∪First(B) {b}∪First(C) {c, d}
Step 2 {a}∪ {b}∪First(C)
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = {b}∪First(C)
• First (B  bBe) = {b}
• First (B  C) = First(C) = {c, d}
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step 2:
Step First Set
S B C a b c d
Step 1 {a}∪First(B) {b}∪First(C) {c, d}
Step 2 {a}∪ {b}∪First(C)
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = {b}∪First(C)
• First (B  bBe) = {b}
• First (B  C) = {c, d}
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step First Set
S B C a b c d
Step 1 {a}∪First(B) {b}∪First(C) {c, d}
Step 2 {a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d}
Step 2:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = {b}∪First(C) = {b}∪ {c, d}
• First (B  bBe) = {b}
• First (B  C) = {c, d}
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step 3:
Step First Set
S B C a b c d
Step 1 {a}∪First(B) {b}∪First(C) {c, d}
Step 2 {a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d}
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = {b, c, d}
• First (B  bBe) = {b}
• First (B  C) = {c, d}
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step 3:
Step First Set
S B C a b c d
Step
1
{a}∪First(B) {b}∪First(C) {c, d}
Step
2
{a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d}
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
First Set (2)
• First (SaSe) = {a}
• First (SB) = {b, c, d}
• First (B  bBe) = {b}
• First (B  C) = {c, d}
• First (C  cCe) = {c}
• First (C  d) = {d}
Red : A Blue : 
Step 3:
Step First Set
S B C a b c d
Step 1 {a}∪First(B) {b}∪First(C) {c, d}
Step 2 {a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d}
Step 3 {a}∪ {b}∪{c, d} = {a,b,c,d} {b}∪{c, d} = {b,c,d} {c, d} {a} {b} {c} {d}
If no more change…
The first set of a terminal
symbol is itself
Another Example….
First Set (2)
S  ABc
A  a
A  
B  b
B  
G0
Red : A Blue : 
First Set (2)
S  ABc
A  a
A  
B  b
B  
G0
Red : A Blue : 
• First (SABc) = First(ABc)
• First (Aa) = First(a)
• First (A  ) = First()∪First()
• First (B  b) = First(b)
• First (B  ) = First()∪First()
Step 1:
First Set (2)
S  ABc
A  a
A  
B  b
B  
G0
Red : A Blue : 
• First (SABc) = First(ABc)
• First (Aa) = {a}
• First (A  ) = {}
• First (B  b) = {b}
• First (B  ) = {}
Step 1:
Step First Set
S A B a b c
Step 1 First(ABc) {a, } {b, }
First Set (2)
S  ABc
A  a
A  
B  b
B  
G0
Red : A Blue : 
• First (SABc) = First(ABc) = {a, }
= {a, } - {} ∪ First(Bc)
= {a} ∪ First(Bc)
• First (Aa) = {a}
• First (A  ) = {}
• First (B  b) = {b}
• First (B  ) = {}
Step 2:
Step First Set
S A B a b c
Step 1 First(ABc) {a, } {b, }
Step 2 {a} ∪ First(Bc) {a, } {b, }
First Set (2)
S  ABc
A  a
A  
B  b
B  
G0
Red : A Blue : 
• First (SABc) = {a} ∪ First(Bc)
= {a} ∪{b, }
= {a} ∪{b, } - {} ∪First(c)
= {a} ∪{b,c}
• First (Aa) = {a}
• First (A  ) = {}
• First (B  b) = {b}
• First (B  ) = {}
Step 3:
Step First Set
S A B a b c
Step 1 First(ABc) {a, } {b, }
Step 2 {a} ∪ First(Bc) {a, } {b, }
Step 3 {a} ∪ {b, c}= {a,b,c} {a, } {b, }
First Set (2)
S  ABc
A  a
A  
B  b
B  
G0
Red : A Blue : 
• First (SABc) = {a,b,c}
• First (Aa) = {a}
• First (A  ) = {}
• First (B  b) = {b}
• First (B  ) = {}
Step 3:
Step First Set
S A B a b c
Step
1
First(ABc) {a, } {b, }
Step
2
{a} ∪ First(Bc) {a, } {b, }
If no more change…
The first set of a terminal
symbol is itself
Follow Set
• Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
• We will use some examples for this operation…
E…A
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
• Step 0:
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Step Follow Set
E Prefix Tail
Step 0 {}  
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step 1:
• From “EPrefix(E) “, We can get…
• Follow (Prefix) = Follow (Prefix) ∪First(()
= Follow (Prefix) ∪{(} and
• Follow (E) = Follow (E) ∪ First()) = Follow (E) ∪ {)}
• From “EVTail “, We can get…
• Follow (Tail) = Follow (Tail) ∪ First()
= Follow (Tail) ∪ {} = Follow (Tail) ∪ Follow (E)
• From “Tail+E “, We can get…
• Follow (E) = Follow (E) ∪ First()
= Follow (E) ∪ {} = Follow (E) ∪ Follow (Tail)
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Step Follow Set
E Prefix Tail
Step 0   
Step 1 Follow(E) ∪ {)} ∪ Follow (Tail)
= {, )}
Follow (Prefix) ∪{(}
={(}
Follow (Tail) ∪ Follow (E)
= {}
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Step Follow Set
E Prefix Tail
Step 0   
Step 1 Follow(E) ∪ {)} ∪ Follow (Tail)
= {, )}
Follow (Prefix) ∪{(}
={(}
Follow (Tail) ∪ Follow (E)
= {}
Step 2 Follow(E) ∪ {)} ∪ Follow (Tail)
= {, )}
Follow (Prefix) ∪{(}
={(}
Follow (Tail) ∪ Follow (E)
= {, }}
Step 2:
• From “EPrefix(E) “, We can get…
• Follow (Prefix) = Follow (Prefix) ∪First(()
= Follow (Prefix) ∪{(} and
• Follow (E) = Follow (E) ∪ First()) = Follow (E) ∪ {)}
• From “EVTail “, We can get…
• Follow (Tail) = Follow (Tail) ∪ First()
= Follow (Tail) ∪ {} = Follow (Tail) ∪ Follow (E)
• From “Tail+E “, We can get…
• Follow (E) = Follow (E) ∪ First()
= Follow (E) ∪ {} = Follow (E) ∪ Follow (Tail)
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step 3:
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail+E
Tail 
G0
Step Follow Set
E Prefix Tail
Step 0   
Step 1 Follow(E) ∪ {)} ∪ Follow (Tail)
= {, )}
Follow (Prefix) ∪{(}
={(}
Follow (Tail) ∪ Follow (E)
= {}
Step 2 Follow(E) ∪ {)} ∪ Follow (Tail)
= {, )}
Follow (Prefix) ∪{(}
={(}
Follow (Tail) ∪ Follow (E)
= {, }}
Step 3 Follow(E) ∪ {)} ∪ Follow (Tail)
= {, )}
Follow (Prefix) ∪{(}
={(}
Follow (Tail) ∪ Follow (E)
= {, }}
Another Example….
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step 0:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step Follow Set
S B C
Step 0 {}  
Step 1:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
• S  aSe
 Follow (S) = Follow (S) ∪ {e}
• S  B
 Follow (B )
= Follow (B) ∪ Follow (S)
• B  bBe
 Follow (B) = Follow (B) ∪ {e}
• B  C
 Follow (C)
 = Follow (C) ∪ Follow (B)
• C  cCe
 Follow (C) = Follow (C) ∪ {e}
• C  d
=> No Non-Terminal
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step Follow Set
S B C
Step 0   
Step 1 Follow(S) ∪ {e}
= {, e}
Follow (B) ∪Follow(S) ∪ {e}
={, e}
Follow (C) ∪ Follow(B) ∪ {e}
= {e}
Step 2:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
• S  aSe
 Follow (S) = Follow (S) ∪ {e}
• S  B
 Follow (B )
= Follow (B) ∪ Follow (S)
• B  bBe
 Follow (B) = Follow (B) ∪ {e}
• B  C
 Follow (C)
 = Follow (C) ∪ Follow (B)
• C  cCe
 Follow (C) = Follow (C) ∪ {e}
• C  d
=> No Non-Terminal
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step Follow Set
S B C
Step 0   
Step 1 Follow(S) ∪ {e}
= {, e}
Follow (B) ∪Follow(S) ∪ {e}
={, e}
Follow (C) ∪ Follow(B) ∪ {e}
= {e}
Step 2 Follow(S) ∪ {e}
= {, e}
Follow (B) ∪Follow(S) ∪ {e}
={, e}
Follow (C) ∪ Follow(B) ∪ {e}
={, e}
Step 3:
S  aSe
S  B
B  bBe
B  C
C  cCe
C  d
G0
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step Follow Set
S B C
Step 0   
Step 1 Follow(S) ∪ {e}
= {, e}
Follow (B) ∪Follow(S) ∪ {e}
={, e}
Follow (C) ∪ Follow(B) ∪ {e}
= {e}
Step 2 Follow(S) ∪ {e}
= {, e}
Follow (B) ∪Follow(S) ∪ {e}
={, e}
Follow (C) ∪ Follow(B) ∪ {e}
={, e}
Step 3 Follow(S) ∪ {e}
= {, e}
Follow (B) ∪Follow(S) ∪ {e}
={, e}
Follow (C) ∪ Follow(B) ∪ {e}
={, e}
Another Example….
S  ABc
A  a
A  
B  b
B  
G0
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step 0:
S  ABc
A  a
A  
B  b
B  
G0
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step Follow Set
S A B
Step 0 {}  
Step 1:
• S  ABc
 Follow (A)
= Follow (A) ∪ First (Bc)
= Follow (A) ∪ {b,c}
• S  ABc
 Follow (B) = Follow (B) ∪ {c}
• A  a
 No Non-Terminal
• A  
=> No Non-Terminal
• B  b
=> No Non-Terminal
• B 
=> No Non-Terminal
S  ABc
A  a
A  
B  b
B  
G0
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step Follow Set
S A B
Step 0 {}  
Step 1 {} Follow (A) ∪ {b,c} = {b,c} Follow (B) ∪ {c} = {c}
Step 2:
• S  ABc
 Follow (A)
= Follow (A) ∪ First (Bc)
= Follow (A) ∪ {b,c}
• S  ABc
 Follow (B) = Follow (B) ∪ {c}
• A  a
 No Non-Terminal
• A  
=> No Non-Terminal
• B  b
=> No Non-Terminal
• B 
=> No Non-Terminal
S  ABc
A  a
A  
B  b
B  
G0
E…A
Follow (A) = Follow(A) ∪ First() , if  ∉ First()
Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
Step Follow Set
S A B
Step 0 {}  
Step 1 {} Follow (A) ∪ {b,c} = {b,c} Follow (B) ∪ {c} = {c}
Step 2 {} Follow (A) ∪ {b,c} = {b,c} Follow (B) ∪ {c} = {c}

More Related Content

Similar to Compiler first set_followset_brief

Đề Thi HK2 Toán 7 - THCS Bình Trị Đông
Đề Thi HK2 Toán 7 - THCS Bình Trị Đông Đề Thi HK2 Toán 7 - THCS Bình Trị Đông
Đề Thi HK2 Toán 7 - THCS Bình Trị Đông
Công Ty TNHH VIETTRIGROUP
 
01_Sets.pdf
01_Sets.pdf01_Sets.pdf
01_Sets.pdf
RAMESH Mojjada
 
07122555 0937185627
07122555 093718562707122555 0937185627
07122555 0937185627
faisupak
 
Assessments for class xi
Assessments  for class  xi Assessments  for class  xi
Assessments for class xi
indu psthakur
 
Đề Thi HK2 Toán 8 - THCS Hậu Giang
Đề Thi HK2 Toán 8 - THCS Hậu GiangĐề Thi HK2 Toán 8 - THCS Hậu Giang
Đề Thi HK2 Toán 8 - THCS Hậu Giang
Trung Tâm Gia Sư Việt Trí
 
5 top-down-parsers
5  top-down-parsers 5  top-down-parsers
5 top-down-parsers
Saeed Parsa
 
Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019
Bushra Al-Anesi
 
GEO_3º_1B_SOL (1) (1).pdf
GEO_3º_1B_SOL (1) (1).pdfGEO_3º_1B_SOL (1) (1).pdf
GEO_3º_1B_SOL (1) (1).pdf
erick444444
 
Module 5 circular functions
Module 5   circular functionsModule 5   circular functions
Module 5 circular functions
dionesioable
 
Shi20396 ch07
Shi20396 ch07Shi20396 ch07
Shi20396 ch07
Paralafakyou Mens
 
Diagram Venn Beserta Contoh Soal
Diagram Venn Beserta Contoh SoalDiagram Venn Beserta Contoh Soal
Diagram Venn Beserta Contoh Soal
Eman Mendrofa
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
Julien Truffaut
 
Ncert solutions for class 7 maths chapter 1 integers exercise 1.4
Ncert solutions for class 7 maths chapter 1 integers exercise 1.4Ncert solutions for class 7 maths chapter 1 integers exercise 1.4
Ncert solutions for class 7 maths chapter 1 integers exercise 1.4
iprepkumar
 
Functional optics
Functional opticsFunctional optics
Functional optics
Barnabás Oláh
 
SET
SETSET
Ncert solutions for class 7 maths chapter 1 integers exercise 1.2
Ncert solutions for class 7 maths chapter 1 integers exercise 1.2Ncert solutions for class 7 maths chapter 1 integers exercise 1.2
Ncert solutions for class 7 maths chapter 1 integers exercise 1.2
jobazine India
 
1f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.6
1f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.61f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.6
1f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.6
Dr. I. Uma Maheswari Maheswari
 
Homework 2 sol
Homework 2 solHomework 2 sol
Homework 2 sol
tt_aljobory
 
10 Mathematics Standard.pdf
10 Mathematics Standard.pdf10 Mathematics Standard.pdf
10 Mathematics Standard.pdf
RohitSindhu10
 
Đề Thi HK2 Toán 7 - THCS Lê Thành Công
Đề Thi HK2 Toán 7 - THCS Lê Thành CôngĐề Thi HK2 Toán 7 - THCS Lê Thành Công
Đề Thi HK2 Toán 7 - THCS Lê Thành Công
Công Ty TNHH VIETTRIGROUP
 

Similar to Compiler first set_followset_brief (20)

Đề Thi HK2 Toán 7 - THCS Bình Trị Đông
Đề Thi HK2 Toán 7 - THCS Bình Trị Đông Đề Thi HK2 Toán 7 - THCS Bình Trị Đông
Đề Thi HK2 Toán 7 - THCS Bình Trị Đông
 
01_Sets.pdf
01_Sets.pdf01_Sets.pdf
01_Sets.pdf
 
07122555 0937185627
07122555 093718562707122555 0937185627
07122555 0937185627
 
Assessments for class xi
Assessments  for class  xi Assessments  for class  xi
Assessments for class xi
 
Đề Thi HK2 Toán 8 - THCS Hậu Giang
Đề Thi HK2 Toán 8 - THCS Hậu GiangĐề Thi HK2 Toán 8 - THCS Hậu Giang
Đề Thi HK2 Toán 8 - THCS Hậu Giang
 
5 top-down-parsers
5  top-down-parsers 5  top-down-parsers
5 top-down-parsers
 
Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019Ch04 syntax analysis first_follow_2019
Ch04 syntax analysis first_follow_2019
 
GEO_3º_1B_SOL (1) (1).pdf
GEO_3º_1B_SOL (1) (1).pdfGEO_3º_1B_SOL (1) (1).pdf
GEO_3º_1B_SOL (1) (1).pdf
 
Module 5 circular functions
Module 5   circular functionsModule 5   circular functions
Module 5 circular functions
 
Shi20396 ch07
Shi20396 ch07Shi20396 ch07
Shi20396 ch07
 
Diagram Venn Beserta Contoh Soal
Diagram Venn Beserta Contoh SoalDiagram Venn Beserta Contoh Soal
Diagram Venn Beserta Contoh Soal
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
Ncert solutions for class 7 maths chapter 1 integers exercise 1.4
Ncert solutions for class 7 maths chapter 1 integers exercise 1.4Ncert solutions for class 7 maths chapter 1 integers exercise 1.4
Ncert solutions for class 7 maths chapter 1 integers exercise 1.4
 
Functional optics
Functional opticsFunctional optics
Functional optics
 
SET
SETSET
SET
 
Ncert solutions for class 7 maths chapter 1 integers exercise 1.2
Ncert solutions for class 7 maths chapter 1 integers exercise 1.2Ncert solutions for class 7 maths chapter 1 integers exercise 1.2
Ncert solutions for class 7 maths chapter 1 integers exercise 1.2
 
1f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.6
1f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.61f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.6
1f. Pedagogy of Mathematics (Part II) - Set language introduction and Ex.1.6
 
Homework 2 sol
Homework 2 solHomework 2 sol
Homework 2 sol
 
10 Mathematics Standard.pdf
10 Mathematics Standard.pdf10 Mathematics Standard.pdf
10 Mathematics Standard.pdf
 
Đề Thi HK2 Toán 7 - THCS Lê Thành Công
Đề Thi HK2 Toán 7 - THCS Lê Thành CôngĐề Thi HK2 Toán 7 - THCS Lê Thành Công
Đề Thi HK2 Toán 7 - THCS Lê Thành Công
 

Recently uploaded

Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 

Recently uploaded (20)

Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 

Compiler first set_followset_brief

  • 1. First Set • First (=A) = First(A) , if  ∉ First(A) First(A) – {} ∪First(), if  ∈ First(A) We will use some examples for this operation… Red : A Blue : 
  • 2. First Set (2) EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Red : A Blue : 
  • 3. First Set (2) • First (EPrefix(E))=First(Prefix(E)) ? = {Waiting operation} – We don’t know First(Prefix) at this moment. – So we keep the operation of First(Prefix(E)) until we know First(Prefix). • First (EV Tail) = First(V) = {V} • First (PrefixF) = First(F) = {F} • First (Prefix )= First() - {} ∪First() = {} • First (Tail+E) = First(+) = {+} • First (Tail ) = First() - {} ∪First() = {} EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Red : A Blue :  Step 1:
  • 4. First Set (2) • First (EPrefix(E))=First(Prefix(E)) ? = {Waiting operation} – We don’t know First(Prefix) at this moment. – So we keep the operation of First(Prefix(E)) until we know First(Prefix). • First (EV Tail) = {V} • First (PrefixF) = {F} • First (Prefix )= {} • First (Tail+E) = {+} • First (Tail ) = {} EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Red : A Blue :  Step First Set E Prefix Tail ( ) V F + Step 1 First(Prefix(E))∪{V} {F, } {+, } Step 1:
  • 5. First Set (2) • First (EPrefix(E))=First(Prefix(E)) ? = {Waiting operation} – In this step, we know First(Prefix). – So we replace the First(Prefix) with {F, }. • First (EV Tail) = {V} • First (PrefixF) = {F} • First (Prefix )= {} • First (Tail+E) = {+} • First (Tail ) = {} EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Red : A Blue :  {F, } Step 2: Step First Set E Prefix Tail ( ) V F + Step 1 First(Prefix(E))∪{V} {F, } {+, }
  • 6. First Set (2) • First (EPrefix(E))=First(Prefix(E)) = {F, } = {F, } - {} ∪ First((E)) = {F, (} • First (EV Tail) = {V} • First (PrefixF) = {F} • First (Prefix )= {} • First (Tail+E) = {+} • First (Tail ) = {} EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Red : A Blue :  Step 2: Step First Set E Prefix Tail ( ) V F + Step 1 First(Prefix(E))∪{V} {F, } {+, }
  • 7. First Set (2) • First (EPrefix(E))= {F, (} • First (EV Tail) = {V} • First (PrefixF) = {F} • First (Prefix )= {} • First (Tail+E) = {+} • First (Tail ) = {} EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Red : A Blue :  Step First Set E Prefix Tail ( ) V F + Step 1 First(Prefix(E))∪{V} {F, } {+, } Step 2 {F, (} ∪ {V} ={F, (, V} {F, } {+, } Step 2:
  • 8. First Set (2) • First (EPrefix(E))= {F, (} • First (EV Tail) = {V} • First (PrefixF) = {F} • First (Prefix )= {} • First (Tail+E) = {+} • First (Tail ) = {} EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Step First Set E Prefix Tail ( ) V F + Step 1 First(Prefix(E))∪{V} {F, } {+, } Step 2 {F, (} ∪ {V} ={F, (, V} {F, } {+, } Step 3 {F, (, V} {F, } {+, } {(} {)} {V} {F} {+} If no more change… The first set of a terminal symbol is itself Red : A Blue :  Step 3:
  • 10. First Set (2) S  aSe S  B B  bBe B  C C  cCe C  d G0 Red : A Blue : 
  • 11. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = First(a) ={a} • First (SB) = First(B) • First (B  bBe) = First(b)={b} • First (B  C) = First(C) • First (C  cCe) = First(c) ={c} • First (C  d) = First(d)={d} Red : A Blue :  Step 1:
  • 12. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = First(B) • First (B  bBe) = {b} • First (B  C) = First(C) • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 1:
  • 13. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = First(B) = {b}∪First(C) • First (B  bBe) = {b} • First (B  C) = First(C) • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 2:
  • 14. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = {b}∪First(C) • First (B  bBe) = {b} • First (B  C) = First(C) • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step 2: Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 2 {a}∪ {b}∪First(C)
  • 15. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = {b}∪First(C) • First (B  bBe) = {b} • First (B  C) = First(C) = {c, d} • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step 2: Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 2 {a}∪ {b}∪First(C)
  • 16. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = {b}∪First(C) • First (B  bBe) = {b} • First (B  C) = {c, d} • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 2 {a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d} Step 2:
  • 17. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = {b}∪First(C) = {b}∪ {c, d} • First (B  bBe) = {b} • First (B  C) = {c, d} • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step 3: Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 2 {a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d}
  • 18. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = {b, c, d} • First (B  bBe) = {b} • First (B  C) = {c, d} • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step 3: Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 2 {a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d}
  • 19. S  aSe S  B B  bBe B  C C  cCe C  d G0 First Set (2) • First (SaSe) = {a} • First (SB) = {b, c, d} • First (B  bBe) = {b} • First (B  C) = {c, d} • First (C  cCe) = {c} • First (C  d) = {d} Red : A Blue :  Step 3: Step First Set S B C a b c d Step 1 {a}∪First(B) {b}∪First(C) {c, d} Step 2 {a}∪ {b}∪First(C) {b}∪{c, d} = {b,c,d} {c, d} Step 3 {a}∪ {b}∪{c, d} = {a,b,c,d} {b}∪{c, d} = {b,c,d} {c, d} {a} {b} {c} {d} If no more change… The first set of a terminal symbol is itself
  • 21. First Set (2) S  ABc A  a A   B  b B   G0 Red : A Blue : 
  • 22. First Set (2) S  ABc A  a A   B  b B   G0 Red : A Blue :  • First (SABc) = First(ABc) • First (Aa) = First(a) • First (A  ) = First()∪First() • First (B  b) = First(b) • First (B  ) = First()∪First() Step 1:
  • 23. First Set (2) S  ABc A  a A   B  b B   G0 Red : A Blue :  • First (SABc) = First(ABc) • First (Aa) = {a} • First (A  ) = {} • First (B  b) = {b} • First (B  ) = {} Step 1: Step First Set S A B a b c Step 1 First(ABc) {a, } {b, }
  • 24. First Set (2) S  ABc A  a A   B  b B   G0 Red : A Blue :  • First (SABc) = First(ABc) = {a, } = {a, } - {} ∪ First(Bc) = {a} ∪ First(Bc) • First (Aa) = {a} • First (A  ) = {} • First (B  b) = {b} • First (B  ) = {} Step 2: Step First Set S A B a b c Step 1 First(ABc) {a, } {b, } Step 2 {a} ∪ First(Bc) {a, } {b, }
  • 25. First Set (2) S  ABc A  a A   B  b B   G0 Red : A Blue :  • First (SABc) = {a} ∪ First(Bc) = {a} ∪{b, } = {a} ∪{b, } - {} ∪First(c) = {a} ∪{b,c} • First (Aa) = {a} • First (A  ) = {} • First (B  b) = {b} • First (B  ) = {} Step 3: Step First Set S A B a b c Step 1 First(ABc) {a, } {b, } Step 2 {a} ∪ First(Bc) {a, } {b, } Step 3 {a} ∪ {b, c}= {a,b,c} {a, } {b, }
  • 26. First Set (2) S  ABc A  a A   B  b B   G0 Red : A Blue :  • First (SABc) = {a,b,c} • First (Aa) = {a} • First (A  ) = {} • First (B  b) = {b} • First (B  ) = {} Step 3: Step First Set S A B a b c Step 1 First(ABc) {a, } {b, } Step 2 {a} ∪ First(Bc) {a, } {b, } If no more change… The first set of a terminal symbol is itself
  • 27. Follow Set • Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() • We will use some examples for this operation… E…A
  • 28. E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() • Step 0: EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Step Follow Set E Prefix Tail Step 0 {}  
  • 29. E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step 1: • From “EPrefix(E) “, We can get… • Follow (Prefix) = Follow (Prefix) ∪First(() = Follow (Prefix) ∪{(} and • Follow (E) = Follow (E) ∪ First()) = Follow (E) ∪ {)} • From “EVTail “, We can get… • Follow (Tail) = Follow (Tail) ∪ First() = Follow (Tail) ∪ {} = Follow (Tail) ∪ Follow (E) • From “Tail+E “, We can get… • Follow (E) = Follow (E) ∪ First() = Follow (E) ∪ {} = Follow (E) ∪ Follow (Tail) EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Step Follow Set E Prefix Tail Step 0    Step 1 Follow(E) ∪ {)} ∪ Follow (Tail) = {, )} Follow (Prefix) ∪{(} ={(} Follow (Tail) ∪ Follow (E) = {}
  • 30. E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Step Follow Set E Prefix Tail Step 0    Step 1 Follow(E) ∪ {)} ∪ Follow (Tail) = {, )} Follow (Prefix) ∪{(} ={(} Follow (Tail) ∪ Follow (E) = {} Step 2 Follow(E) ∪ {)} ∪ Follow (Tail) = {, )} Follow (Prefix) ∪{(} ={(} Follow (Tail) ∪ Follow (E) = {, }} Step 2: • From “EPrefix(E) “, We can get… • Follow (Prefix) = Follow (Prefix) ∪First(() = Follow (Prefix) ∪{(} and • Follow (E) = Follow (E) ∪ First()) = Follow (E) ∪ {)} • From “EVTail “, We can get… • Follow (Tail) = Follow (Tail) ∪ First() = Follow (Tail) ∪ {} = Follow (Tail) ∪ Follow (E) • From “Tail+E “, We can get… • Follow (E) = Follow (E) ∪ First() = Follow (E) ∪ {} = Follow (E) ∪ Follow (Tail)
  • 31. E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step 3: EPrefix(E) EV Tail PrefixF Prefix Tail+E Tail  G0 Step Follow Set E Prefix Tail Step 0    Step 1 Follow(E) ∪ {)} ∪ Follow (Tail) = {, )} Follow (Prefix) ∪{(} ={(} Follow (Tail) ∪ Follow (E) = {} Step 2 Follow(E) ∪ {)} ∪ Follow (Tail) = {, )} Follow (Prefix) ∪{(} ={(} Follow (Tail) ∪ Follow (E) = {, }} Step 3 Follow(E) ∪ {)} ∪ Follow (Tail) = {, )} Follow (Prefix) ∪{(} ={(} Follow (Tail) ∪ Follow (E) = {, }}
  • 33. S  aSe S  B B  bBe B  C C  cCe C  d G0 E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
  • 34. Step 0: S  aSe S  B B  bBe B  C C  cCe C  d G0 E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step Follow Set S B C Step 0 {}  
  • 35. Step 1: S  aSe S  B B  bBe B  C C  cCe C  d G0 • S  aSe  Follow (S) = Follow (S) ∪ {e} • S  B  Follow (B ) = Follow (B) ∪ Follow (S) • B  bBe  Follow (B) = Follow (B) ∪ {e} • B  C  Follow (C)  = Follow (C) ∪ Follow (B) • C  cCe  Follow (C) = Follow (C) ∪ {e} • C  d => No Non-Terminal E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step Follow Set S B C Step 0    Step 1 Follow(S) ∪ {e} = {, e} Follow (B) ∪Follow(S) ∪ {e} ={, e} Follow (C) ∪ Follow(B) ∪ {e} = {e}
  • 36. Step 2: S  aSe S  B B  bBe B  C C  cCe C  d G0 • S  aSe  Follow (S) = Follow (S) ∪ {e} • S  B  Follow (B ) = Follow (B) ∪ Follow (S) • B  bBe  Follow (B) = Follow (B) ∪ {e} • B  C  Follow (C)  = Follow (C) ∪ Follow (B) • C  cCe  Follow (C) = Follow (C) ∪ {e} • C  d => No Non-Terminal E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step Follow Set S B C Step 0    Step 1 Follow(S) ∪ {e} = {, e} Follow (B) ∪Follow(S) ∪ {e} ={, e} Follow (C) ∪ Follow(B) ∪ {e} = {e} Step 2 Follow(S) ∪ {e} = {, e} Follow (B) ∪Follow(S) ∪ {e} ={, e} Follow (C) ∪ Follow(B) ∪ {e} ={, e}
  • 37. Step 3: S  aSe S  B B  bBe B  C C  cCe C  d G0 E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step Follow Set S B C Step 0    Step 1 Follow(S) ∪ {e} = {, e} Follow (B) ∪Follow(S) ∪ {e} ={, e} Follow (C) ∪ Follow(B) ∪ {e} = {e} Step 2 Follow(S) ∪ {e} = {, e} Follow (B) ∪Follow(S) ∪ {e} ={, e} Follow (C) ∪ Follow(B) ∪ {e} ={, e} Step 3 Follow(S) ∪ {e} = {, e} Follow (B) ∪Follow(S) ∪ {e} ={, e} Follow (C) ∪ Follow(B) ∪ {e} ={, e}
  • 39. S  ABc A  a A   B  b B   G0 E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First()
  • 40. Step 0: S  ABc A  a A   B  b B   G0 E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step Follow Set S A B Step 0 {}  
  • 41. Step 1: • S  ABc  Follow (A) = Follow (A) ∪ First (Bc) = Follow (A) ∪ {b,c} • S  ABc  Follow (B) = Follow (B) ∪ {c} • A  a  No Non-Terminal • A   => No Non-Terminal • B  b => No Non-Terminal • B  => No Non-Terminal S  ABc A  a A   B  b B   G0 E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step Follow Set S A B Step 0 {}   Step 1 {} Follow (A) ∪ {b,c} = {b,c} Follow (B) ∪ {c} = {c}
  • 42. Step 2: • S  ABc  Follow (A) = Follow (A) ∪ First (Bc) = Follow (A) ∪ {b,c} • S  ABc  Follow (B) = Follow (B) ∪ {c} • A  a  No Non-Terminal • A   => No Non-Terminal • B  b => No Non-Terminal • B  => No Non-Terminal S  ABc A  a A   B  b B   G0 E…A Follow (A) = Follow(A) ∪ First() , if  ∉ First() Follow(A) ∪First() – {} ∪Follow(E) , if  ∈ First() Step Follow Set S A B Step 0 {}   Step 1 {} Follow (A) ∪ {b,c} = {b,c} Follow (B) ∪ {c} = {c} Step 2 {} Follow (A) ∪ {b,c} = {b,c} Follow (B) ∪ {c} = {c}