0% found this document useful (0 votes)
33 views26 pages

Lec 02. Find First Function

Uploaded by

zainfayyaz498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views26 pages

Lec 02. Find First Function

Uploaded by

zainfayyaz498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Find First Function

 First (α) is a set of all Terminals that may be in beginning in any


sentential form, derived from α.
 First (α) is calculated for both Terminals and Non- Terminals.
 If α is a Terminals, then
 First (α) = {α}
 If α is a strings of Terminals e.g. abc
 First (abc) = {a}
Find First Function
 If α is a Non-Terminals, defined by α → ε, then
 First (α) = {ε}
 If α is a Non-Terminals, defined by α → β, β ϵ T
 First (α) = {β}
Find First Function Rules
 If α is a Non-Terminals, defined by , then
 First (α) = {}
 Iff → ! ϵ
 First (α) = [First ( U First (] - ϵ
 Iff → ϵ && Iff → ! ϵ
First (α) = [First ( U First ( U First (] - ϵ
 Iff → ϵ && Iff → ϵ && Iff → ! ϵ
First (α) = [First ( U First ( U First (
 Iff → ϵ && Iff → ϵ && Iff → ! ϵ
Example
S→a/b/ϵ
 First(S) = Follow(S) =
S → aA / bB
A→ε
B→ε
 First(S) = Follow(S) =
 First (A) = Follow(A) =
 First(B) = Follow(B) =
Example

S → aAb / Ba
A → aA / b
B→c/d
 First(S) = Follow(S) =
 First (A) = Follow(A) =
 First (B) = Follow(B) =
Example
S → AaB / BA
A→a/b
B→d/e
 First(S) = Follow(S) =
 First(A) = Follow(A) =
First(B) = Follow(B) =
Example
S → AaB
A→b/ε
B→c
 First(S) = Follow(S) =
 First(A) = Follow(A) =
First(B) = Follow(B) =
Example
S → AaB / Bb
A → bA / ε
B → cB / ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Example
S → AB
A→a/ ε
B→b/ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Example
S → ABCDE
A→a/ε
B→b/ε
C→c/ε
D→ d
E→e/ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
 First(C) = Follow(C) =
 First(D) = Follow(D) =
 First(E) = Follow(E) =
Example
S → aAB / BA
A → BA / ε
B → AB / a / ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Example
S → AA
A → aA
B→ b
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Example
S → (L) / a
L → SL’
L’ → ,SL’ / ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Example
E → TE’
E’ → +TE ’ / ε
T → FT’
T’ → *FT’ / ε
F → (E) / id
 First(E) = Follow(E)
 First(E’) = Follow(E’) =
 First(T) = Follow(T) =
 First(T’) = Follow(T’) =
 First(F) = Follow(F) =
Example
A → aA’
A’ → (A)A’ / ε
 First(A) = Follow(A) =
 First(A’) = Follow(A’) =

A → (A)A’ / aA’
A’ → AA’ / ε
 First(A) = Follow(A) =
 First(A’) = Follow(A’) =
Example
S → aBDh First(S) = Follow(S) =
B → cC First(B) = Follow(B) =
C → bC / ε First(C) = Follow(C) =
D → EF First(D) = Follow(D) =
E→g/ε First(E) = Follow(E) =
F→f/ε First(F) = Follow(F) =
Find Follow Function
 Follow(A) is the set of all terminals that may follow to the right of (A) in any
form of sentential Grammar.
 Rules:
 If A is the start symbol then Follow(A) = {$}
 If A → αAβ, β → ! ϵ
 Follow (A) = First (β)
 If S → αA
 Follow (A) = Follow(S)
 S → αAβ, Where β → ϵ
 Follow(A) = First(β) U Follow - ϵ
Example
S→ε
 First(S) = Follow(S) =

S → aA
A → bA / ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
Example
S → AaBb / BbAa
A→ ε
B→ ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Example
E→E+T/T
T→ T*F/F
F → (E) / id
 First(E) = Follow(E) =
 First(T) = Follow(T) =
 First(F) = Follow(F) =
Example
S → aAb
A → Ba / b
B→ d
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Examples
S → S0S1 / ε
 First(S) = Follow(S) =

S → AaAb / BaBb
A→ ε
B→ ε
 First(S) = Follow(S) =
 First(A) = Follow(A) =
 First(B) = Follow(B) =
Example
S → aBCbD
B → bBh / BD / d
C → CE / a
D → EC / b / ε
E → CDb / ε
 First(S) = Follow(S) =
 First(B) = Follow(B) =
 First(C) = Follow(C) =
 First(D) = Follow(D) =
 First(E) = Follow(E) =
Any Question?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy