Professional Documents
Culture Documents
First Set: A A A A A
First Set: A A A A A
Blue :
First Set
First (=A) =
First(A) , if First(A)
First(A) {} First(), if First(A)
Red : A
Blue :
G0
Red : A
Blue :
Step 1:
G0
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
First
First
First
First
First
( EV Tail ) =
( PrefixF) =
( Prefix )=
( Tail+E) =
( Tail ) =
First( V ) = { V }
First( F) = { F}
First( ) - { } First( ) = { }
First( +) = { +}
First( ) - { } First( ) = { }
Red : A
Blue :
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
G0
Step 1:
First
First
First
First
First
( EV Tail ) =
( PrefixF) =
( Prefix )=
( Tail+E) =
( Tail ) =
{ V}
{ F}
{ }
{ +}
{ }
Step
Step 1
First Set
E
Pref
x
Tail
First(Prefix(E)){V
{F,
{+,
Red : A
Blue :
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
G0
Step 2:
First
First
First
First
First
( EV Tail) = { V }
( PrefixF) = { F }
( Prefix )= { }
( Tail+ E) = { + }
( Tail ) = Step
{ }
Step 1
{F, }
First Set
E
Pref
x
Tail
First(Prefix(E)){V
{F,
{+,
Red : A
Blue :
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
G0
Step 2:
Step 1
First Set
E
Pref
x
Tail
First(Prefix(E)){V
{F,
{+,
Red : A
Blue :
Step 2:
First
First
First
First
First
First
G0
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
Step 1
First Set
E
Pref
x
Tail
First(Prefix(E))
{V}
{F,
}
{+,
}
Red : A
Blue :
Step 3:
First
First
First
First
First
First
G0
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
( EPrefix (E))= { F, (}
( EV Tail) = { V }
( PrefixF) = { F }
( Prefix )=If{ no
} more change
( Tail+ E) =The
{ + } first set of a termin
( Tail ) =symbol
{ }
is itself
Step
First Set
E
Pref
x
Tail
Step 1
First(Prefix(E)){
V}
{F,
}
{+,
}
Step 2
{F,
{+,
Another Example.
Red : A
Blue :
G0
Red : A
Blue :
Step 1:
First
First
First
First
First
First
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
First( a) ={ a}
First( B)
= First( b)={ b}
First( C )
First( c ) ={ c}
First( d)={ d}
G0
S aSe
SB
B bBe
BC
C cCe
C d
Red : A
Blue :
Step 1:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
S aSe
SB
B bBe
BC
C cCe
C d
{ a}
First( B)
= { b}
First( C )
{ c}
{ d}
Step
First Set
S
Step 1
C
{c,
Red : A
Blue :
Step 2:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
S aSe
SB
B bBe
BC
C cCe
C d
{ a}
First( B) = { b}First( C )
= { b}
First( C )
{ c}
{ d}
Step
First Set
S
Step 1
C
{c,
Red : A
Blue :
Step 2:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
S aSe
SB
B bBe
BC
C cCe
C d
{ a}
{ b}First( C )
= { b}
First( C )
{ c}
{ d}
Step
Step 1
First Set
S
{a}First(B)
{b}First(C)
{c,
d}
a b c
Red : A
Blue :
Step 2:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
S aSe
SB
B bBe
BC
C cCe
C d
{ a}
{ b}First( C )
= { b}
First( C ) = { c, d }
{ c}
{ d}
Step
Step 1
First Set
S
{a}First(B)
{b}First(C)
{c,
d}
a b c
Red : A
Blue :
Step 2:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
S aSe
SB
B bBe
BC
C cCe
C d
{ a}
{ b}First( C )
= { b}
{ c, d }
{ c}
{ d}
Step
Step 1
First Set
S
{a}First(B)
{b}First(C)
{c,
d}
a b c
Red : A
Blue :
Step 3:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
S aSe
SB
B bBe
BC
C cCe
C d
{ a}
{ b}First( C ) = { b} { c, d }
= { b}
{ c, d }
{ c}
{ d}
Step
Step 1
First Set
S
{a}First(B)
{b}First(C)
{c,
d}
a b c
Red : A
Blue :
Step 3:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
{ a}
{ b, c, d }
= { b}
{ c, d }
{ c}
{ d}
Ste
p
First Set
S
Step
1
S aSe
SB
B bBe
BC
C cCe
C d
{a}First(B)
B
{b}First(C)
C
{c,
d}
a b c
Red : A
Blue :
Step 3:
First
First
First
First
First
First
G0
( SaSe) =
( SB) =
( B bBe)
( B C) =
( C cCe) =
( C d ) =
S aSe
SB
B bBe
BC
C cCe
C d
{ a}
{ b, c, d }
= { b}
{ c,Ifd }no more change
{ cThe
}
first set of a termin
{ dsymbol
}
is itself
Step
First Set
S
Step 1
{a}First(B)
{b}First(C)
{c,
d}
Step 2
{a} {b}First(C)
{b}{c, d} =
{c,
Another Example.
Red : A
Blue :
G0
Red : A
Blue :
Step 1:
First
First
First
First
First
( SA Bc) =
( Aa) =
( A ) =
( B b) =
( B ) =
First( ABc )
First( a)
First( )First( )
First( b)
First( )First( )
G0
S ABc
Aa
A
Bb
B
Red : A
Blue :
Step 1:
First
First
First
First
First
( SA Bc) =
( Aa) =
( A ) =
( B b) =
( B ) =
S ABc
Aa
A
Bb
B
G0
First( ABc )
{ a}
{ }
{ b}
{ }
Step
First Set
S
Step 1
First(ABc)
A
{a, }
B
{b, }
Red : A
Blue :
G0
S ABc
Aa
A
Bb
B
Step 2:
{a}
A
{a, }
B
{b, }
Red : A
Blue :
Step 3:
First ( SABc )
First
First
First
First
( Aa)
( A )
( B b)
( B )
=
=
=
=
G0
S ABc
Aa
A
Bb
B
= { a } First( Bc )
= { a } { b, }
= { a } { b, } - { } First( c )
= { a } { b,c }
{ a}
{ }
{ b} Step
First Set
S
A
B
a
b
c
{ }
Step
1
Step
First(ABc)
{a}
{a,
}
{b,
}
{a,
{b,
Red : A
Blue :
Step 3:
First
First
First
First
First
( SA Bc) =
( Aa) =
( A ) =
( B b) =
( B ) =
S ABc
Aa
A
Bb
B
G0
{ a,b,c }
{ a}
{ }
{ b}
If no more change
{ The
}
first set of a termin
symbol is itself
Ste
p
First Set
S
Step
1
Step
First(ABc)
{a} First(Bc)
{a, }
{b, }
{a, }
{b, }
Follow Set
E
A
Follow (A) =
EA
Follow (A) =
First()
Step 0:
Step
Step 0
Follow Set
E
Pref
x
Tail
{}
G0
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
EA
Follow (A) =
G0
Step 1:
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
Follow Set
E
Prefx
Tail
Step 0
Step 1
Follow(E) {)}
Follow (Tail)
= {, )}
Follow (Prefix)
{(}
={(}
Follow (Tail)
Follow (E)
= {}
EA
Follow (A) =
Step 2:
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
Follow Set
E
Prefx
Tail
Step 0
Step 1
Follow(E) {)}
Follow (Tail)
= {, )}
Follow (Prefix)
{(}
={(}
Follow (Tail)
Follow (E)
= {}
Step 2
Follow(E) {)}
Follow (Prefix)
Follow (Tail)
EA
Follow (A) =
G0
Step 3:
Step
Follow Set
E
Prefx
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)
= {, }}
EPrefix(E)
EV Tail
PrefixF
Prefix
Tail
Tail
Another Example.
EA
Follow (A) =
First()
G0
S aSe
SB
B bBe
BC
C cCe
C d
EA
Follow (A) =
First()
Step 0:
Step
Step 0
Follow Set
S
{}
G0
S aSe
SB
B bBe
BC
C cCe
C d
EA
Follow (A) =
First()
G0
Step 1:
S aSe
Follow (S) = Follow (S) {e}
SB
Follow (B )
= Follow (B) Follow (S)
B bBe
Follow (B) = Follow (B) {e}
BC
Step
Follow Set
Follow (C)
S (C) Follow B(B)
= Follow
CStep
0cCe
Follow
Step
1
Follow(S)
Follow
Follow (B)
(C) =
(C)Follow(S)
{e}
{e}
{e}
Cd
= {, e}
={, e}
=> No Non-Terminal
S aSe
SB
B bBe
BC
C cCe
C d
EA
Follow (A) =
First()
G0
Step 2:
S aSe
Follow (S) = Follow (S) {e}
SB
Follow (B )
= Follow (B) Follow (S)
B bBe
Follow (B) = Follow (B) {e}
BC
Step
Follow Set
Follow (C)
S (C) Follow B(B)
= Follow
CStep
0cCe
Follow
Step
1
Follow(S)
Follow
Follow (B)
(C) =
(C)Follow(S)
{e}
{e}
{e}
Cd
= {, e}
={, e}
=> 2No Follow(S)
Non-Terminal
Step
S aSe
SB
B bBe
BC
C cCe
C d
EA
Follow (A) =
First()
Step 3:
Step
G0
S aSe
SB
B bBe
BC
C cCe
C d
Follow Set
S
Step 0
Step 1
Follow(S)
{e}
= {, e}
Step 2
Follow(S)
{e}
= {, e}
Step 3
Follow(S)
{e}
= {, e}
Another Example.
EA
Follow (A) =
First()
G0
S ABc
Aa
A
Bb
B
EA
Follow (A) =
First()
Step 0:
Step
Step 0
Follow Set
S
{}
G0
S ABc
Aa
A
Bb
B
EA
Follow (A) =
First()
Step 1:
S ABc
Follow (A)
= Follow (A) First (Bc)
= Follow (A) {b,c}
S ABc
Follow (B) = Follow (B) {c}
Aa
No Non-Terminal
Step
A
S
=> No Non-Terminal
Step 0
{}
Bb
Step 1
{}
=> No Non-Terminal
B
Follow Set
A
Follow (A)
{b,c} = {b,c}
Follow (B)
{c} = {c}
G0
S ABc
Aa
A
Bb
B
EA
Follow (A) =
First()
Step 2:
S ABc
Follow (A)
= Follow (A) First (Bc)
= Follow (A) {b,c}
S ABc
Follow (B) = Follow (B) {c}
Aa
No Non-Terminal
Step
A
S
=> No Non-Terminal
Step 0
{}
Bb
Step 1
{}
=> No Non-Terminal
B
Follow Set
A
Follow (A)
{b,c} = {b,c}
Follow (B)
{c} = {c}
G0
S ABc
Aa
A
Bb
B