SlideShare a Scribd company logo
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

Division algorithm
Division algorithmDivision algorithm
Division algorithm
SnehalataAgasti
 
Digital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentationDigital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentation
foyez ahammad
 
Error Correction And Hamming Code Ibrar
Error Correction And Hamming Code IbrarError Correction And Hamming Code Ibrar
Error Correction And Hamming Code Ibrar
ibrar562
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
Chamila Fernando
 
Moore and Mealy machines
Moore and Mealy machinesMoore and Mealy machines
Moore and Mealy machines
Irfan Anjum
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
LogsAk
 
Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086
Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086
Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086
samirbharat77
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
Deepmala Sharma
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
LR(1) CLR(1) Parser with Example
LR(1) CLR(1) Parser with ExampleLR(1) CLR(1) Parser with Example
LR(1) CLR(1) Parser with Example
Muhammad Haroon
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
Archana Gopinath
 
Assembly Language and microprocessor
Assembly Language and microprocessorAssembly Language and microprocessor
Assembly Language and microprocessor
Khaled Sany
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unit
abdosaidgkv
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
missstevenson01
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagram
Rahul Sharma
 
Computer Oragnization Flipflops
Computer Oragnization FlipflopsComputer Oragnization Flipflops
Computer Oragnization Flipflops
Vanitha Chandru
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
Vrushali Dhanokar
 
Toy compiler
Toy compilerToy compiler
Toy compiler
home
 

What's hot (20)

Division algorithm
Division algorithmDivision algorithm
Division algorithm
 
Digital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentationDigital Logic & Design (DLD) presentation
Digital Logic & Design (DLD) presentation
 
Error Correction And Hamming Code Ibrar
Error Correction And Hamming Code IbrarError Correction And Hamming Code Ibrar
Error Correction And Hamming Code Ibrar
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Moore and Mealy machines
Moore and Mealy machinesMoore and Mealy machines
Moore and Mealy machines
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
 
Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086
Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086
Addressing modes/Addressing Mode with illustration/ Addressing mode in 8086
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
LR(1) CLR(1) Parser with Example
LR(1) CLR(1) Parser with ExampleLR(1) CLR(1) Parser with Example
LR(1) CLR(1) Parser with Example
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Assembly Language and microprocessor
Assembly Language and microprocessorAssembly Language and microprocessor
Assembly Language and microprocessor
 
Control Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unitControl Units : Microprogrammed and Hardwired:control unit
Control Units : Microprogrammed and Hardwired:control unit
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagram
 
Computer Oragnization Flipflops
Computer Oragnization FlipflopsComputer Oragnization Flipflops
Computer Oragnization Flipflops
 
Algorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structureAlgorithm analysis in fundamentals of data structure
Algorithm analysis in fundamentals of data structure
 
Toy compiler
Toy compilerToy compiler
Toy compiler
 

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.pptx
venkatapranaykumarGa
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
Arab Open University and Cairo University
 
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 Parsing
Gerwin Ocsena
 
EM3 mini project Laplace Transform
EM3 mini project Laplace TransformEM3 mini project Laplace Transform
EM3 mini project Laplace Transform
Aditi523129
 
Fourier Transform
Fourier TransformFourier Transform
Fourier Transform
Aamir Saeed
 
fourier transforms
fourier transformsfourier transforms
fourier transforms
Umang Gupta
 
Advance Engineering Mathematics
Advance Engineering MathematicsAdvance Engineering Mathematics
Advance Engineering Mathematics
PrasenjitRathore
 
Ma2002 1.13 rm
Ma2002 1.13 rmMa2002 1.13 rm
Ma2002 1.13 rm
Ramakrishna Paduchuri
 
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
Stewart29UReesa
 
Ch8b
Ch8bCh8b
Stacks
Stacks Stacks
Stacks
Ashish Sethi
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
syedabdul78662
 
4. cft
4. cft4. 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
IOSR 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 series
safi al amu
 
Fourier transform
Fourier transformFourier transform
Fourier transform
Solo Hermelin
 

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

Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 

Recently uploaded (20)

Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 

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) = {*,+,$,)}