0% found this document useful (0 votes)
22 views2 pages

FOLLOW SET Rules

Uploaded by

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

FOLLOW SET Rules

Uploaded by

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

FIRST Set and FOLLOW Set for Grammar Worked Example

FOLLOW SET Rules:


Rule 1) Follow(S) = {$} #Start symbol
Rule 2) If A → αB then Follow(B) = Follow(A)
Rule 3) If A → αBβ,
• If ∈ ∉ First(β), then Follow(B) = First(β)
• If ∈ ∈ First(β), then Follow(B) = { First(β) – ∈ } ∪ Follow(A)

Production Rules Example Grammar:


E -> TE’
E’ -> +T E’|Є
T -> F T’
T’ -> *F T’ | Є
F -> (E) | id

Find FOLLOW(E):
E -> TE’ # Rule 1 Ans: Follow (E) = {$}
F -> (E)|id # Rule 2 Ans: Follow (E) = {)}
Answer: Follow(E) = {$, )}

Find FOLLOW(E’):
E -> TE’ # Rule 2 Ans: Follow (E’) = Follow (E)
E’ -> +TE’|Є # Rule 2 Ans: Follow (E’) = Follow (E’) #ignore
Answer: Follow (E’) = Follow (E)
Follow(E’) = {$,)}
Find FOLLOW(T):
E -> TE’ # Rule 3 Ans: Follow (T) = First(E') - Є U Follow (E)
E’ -> +TE’|Є # Rule 2 Ans: Follow (T) = Follow (E')
Answer: Follow (T) = {First(E’) – Є} U Follow (E’) U Follow (E)
Follow(T) = {+,$,)}
Find FOLLOW(T’):
T -> FT’ # Rule 2 Ans: Follow (T’) = Follow (T)
T’ -> *FT’|Є # Rule 2 Ans: Follow (T’) = Follow (T') #ignore
Answer: Follow (T’) = Follow (T)
Follow(T)= {+, $,)}
Find FOLLOW(F):
T -> FT’ # Rule 3 Ans: Follow (F) = FIRST(T') - Є U Follow (T)
T’ ->*FT’|Є # Rule 2 Ans: Follow (F) = Follow (T')
Answer: Follow (F) = {First(T’) – Є} U Follow (T) U Follow (T’)
Follow(F)= {*,+,$,)}
FIRST set:
First(E) = First (T) = { ( , id }
First (E’) = { +, Є }
First (T) = First (F) = { ( , id }
First (T’) = { *, Є }
First (F) = { ( , id }
FOLLOW Set:
Follow(E) = { $, ) }
Follow (E’) = { $, ) }
Follow (T) = { +, $, ) }
Follow (T’) = { +, $, ) }
Follow (F) = { *, +, $, ) }

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