SlideShare a Scribd company logo
1 of 9
Rules for First Sets
 If X is a terminal then First(X) is just X!
 If there is a Production X → ε then add ε to first(X)
 If there is a Production X → Y1Y2..Yk then add
first(Y1Y2..Yk) to first(X)
 First(Y1Y2..Yk) is either
• First(Y1) (if First(Y1) doesn't contain ε)
• OR (if First(Y1) does contain ε) then First (Y1Y2..Yk) is
everything in First(Y1) <except for ε > as well as
everything in First(Y2..Yk)
• If First(Y1) First(Y2)..First(Yk) all contain ε then add ε to
First(Y1Y2..Yk) as well.
Example
E -> TE'
E’ ->+ TE' | ε
T -> FT'
T’ -> * FT' | ε
F ->( E ) | id
 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}
Doing anything else doesn't change the sets so we are done!
Rules for Follow Sets
First put $ (the end of input marker) in Follow(S) (S is the
start symbol)
If there is a production A → aBb, (where a can be a whole
string) then everything in FIRST(b) except for ε is placed
in FOLLOW(B).
If there is a production A → aB, then everything in
FOLLOW(A) is in FOLLOW(B)
If there is a production A → aBb, where FIRST(b) contains
ε, then everything in FOLLOW(A) is in FOLLOW(B)
 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) = {*,+,$,)}

More Related Content

What's hot (20)

Automata theory
Automata theoryAutomata theory
Automata theory
 
Nondeterministic Finite Automata
Nondeterministic Finite AutomataNondeterministic Finite Automata
Nondeterministic Finite Automata
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
push down automata
 push down automata push down automata
push down automata
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functions
 
Push down automata
Push down automataPush down automata
Push down automata
 
PDA (pushdown automaton)
PDA (pushdown automaton)PDA (pushdown automaton)
PDA (pushdown automaton)
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
First and follow set
First and follow setFirst and follow set
First and follow set
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Stack
StackStack
Stack
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Lecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithmLecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithm
 
KMP Pattern Matching algorithm
KMP Pattern Matching algorithmKMP Pattern Matching algorithm
KMP Pattern Matching algorithm
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
pushdown automata
pushdown automatapushdown automata
pushdown automata
 
Compiler question bank
Compiler question bankCompiler question bank
Compiler question bank
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Stack
StackStack
Stack
 

Similar to First() and Follow()

Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)Siddhesh Pange
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptxvenkatapranaykumarGa
 
Top down and botttom up 2 LATEST.
Top down     and botttom up 2 LATEST.Top down     and botttom up 2 LATEST.
Top down and botttom up 2 LATEST.Gerwin Ocsena
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 
EM3 mini project Laplace Transform
EM3 mini project Laplace TransformEM3 mini project Laplace Transform
EM3 mini project Laplace TransformAditi523129
 
Fourier Transform
Fourier TransformFourier Transform
Fourier TransformAamir Saeed
 
fourier transforms
fourier transformsfourier transforms
fourier transformsUmang Gupta
 
Advance Engineering Mathematics
Advance Engineering MathematicsAdvance Engineering Mathematics
Advance Engineering MathematicsPrasenjitRathore
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfStewart29UReesa
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdfsyedabdul78662
 
Spectral Continuity: (p, r) - Α P And (p, k) - Q
Spectral Continuity: (p, r) - Α P And (p, k) - QSpectral Continuity: (p, r) - Α P And (p, k) - Q
Spectral Continuity: (p, r) - Α P And (p, k) - QIOSR Journals
 
ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)Alexandru Radovici
 
the fourier series
the fourier seriesthe fourier series
the fourier seriessafi al amu
 

Similar to First() and Follow() (19)

Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Top down and botttom up 2 LATEST.
Top down     and botttom up 2 LATEST.Top down     and botttom up 2 LATEST.
Top down and botttom up 2 LATEST.
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
EM3 mini project Laplace Transform
EM3 mini project Laplace TransformEM3 mini project Laplace Transform
EM3 mini project Laplace Transform
 
Fourier Transform
Fourier TransformFourier Transform
Fourier Transform
 
fourier transforms
fourier transformsfourier transforms
fourier transforms
 
Advance Engineering Mathematics
Advance Engineering MathematicsAdvance Engineering Mathematics
Advance Engineering Mathematics
 
Ma2002 1.13 rm
Ma2002 1.13 rmMa2002 1.13 rm
Ma2002 1.13 rm
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
Ch8b
Ch8bCh8b
Ch8b
 
Stacks
Stacks Stacks
Stacks
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
 
4. cft
4. cft4. cft
4. cft
 
Spectral Continuity: (p, r) - Α P And (p, k) - Q
Spectral Continuity: (p, r) - Α P And (p, k) - QSpectral Continuity: (p, r) - Α P And (p, k) - Q
Spectral Continuity: (p, r) - Α P And (p, k) - Q
 
ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)
 
the fourier series
the fourier seriesthe fourier series
the fourier series
 
Fourier transform
Fourier transformFourier transform
Fourier transform
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 

First() and Follow()

  • 1. Rules for First Sets  If X is a terminal then First(X) is just X!  If there is a Production X → ε then add ε to first(X)  If there is a Production X → Y1Y2..Yk then add first(Y1Y2..Yk) to first(X)  First(Y1Y2..Yk) is either • First(Y1) (if First(Y1) doesn't contain ε) • OR (if First(Y1) does contain ε) then First (Y1Y2..Yk) is everything in First(Y1) <except for ε > as well as everything in First(Y2..Yk) • If First(Y1) First(Y2)..First(Yk) all contain ε then add ε to First(Y1Y2..Yk) as well.
  • 2. Example E -> TE' E’ ->+ TE' | ε T -> FT' T’ -> * FT' | ε F ->( E ) | id  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) = {}
  • 3.  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) = {}
  • 4. 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} Doing anything else doesn't change the sets so we are done!
  • 5. Rules for Follow Sets First put $ (the end of input marker) in Follow(S) (S is the start symbol) If there is a production A → aBb, (where a can be a whole string) then everything in FIRST(b) except for ε is placed in FOLLOW(B). If there is a production A → aB, then everything in FOLLOW(A) is in FOLLOW(B) If there is a production A → aBb, where FIRST(b) contains ε, then everything in FOLLOW(A) is in FOLLOW(B)
  • 6.  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) = {}
  • 7.  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) = {}
  • 8.  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) = {*}
  • 9.  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) = {*,+,$,)}