SlideShare a Scribd company logo
ICS312 Set 29
Deterministic Finite Automata
Nondeterministic Finite Automata
Deterministic Finite Automata
• A regular expression can be represented (and recognized) by a
machine called a deterministic finite automaton (dfa).
• A dfa can then be used to generate the matrix (or table) used by
the scanner (or lexical analyzer).
• Deterministic finite automata are frequently also called simply
finite automata (fa).
Example of a DFA for Recognizing
Identifiers
Examples
A dfa for regular expressions on the alphabet
S = { a, b, c }
a. Which have exactly one b:
Examples (Cont. 1)
b. Which have 0 or 1 b's:
Examples (Cont. 2)
A dfa for a number with an optional fractional
part (assume S = { 0,1,2,3,4,5,6,7,8,9,+,-,. }:
Constructing DFA
• Regular expressions give us rules for recognizing the
symbols or tokens of a programming language.
• The way a lexical analyzer can recognize the symbols
is to use a DFA (machine) to construct a matrix, or
table, that reports when a particular kind of symbol
has been recognized.
• In order to recognize symbols, we need to know how
to (efficiently) construct a DFA from a regular
expression.
How to Construct a DFA from a
Regular Expression
• Construct a nondeterministic finite automata
(nfa)
• Using the nfa, construct a dfa
• Minimize the number of states in the dfa to get
a smaller dfa
Nondeterministic Finite Automata
• A nondeterministic finite automata (NFA) allows
transitions on a symbol from one state to possibly
more than one other state.
• Allows e-transitions from one state to another
whereby we can move from the first state to the
second without inputting the next character.
• In a NFA, a string is matched if there is any path from
the start state to an accepting state using that string.
NFA Example
This NFA accepts strings such as:
abc
abd
ad
ac
Examples
a f.a. for ab*:
a f.a. for ad
To obtain a f.a. for: ab* | ad We could try:
but this doesn't work, as it matches strings such as abd
Examples (Cont. 1)
So, then we could try:
It's not always easy to construct a f.a. from a regular expression.
It is easier to construct a NFA from a regular expression.
Examples (Cont. 2)
Example of a NFA with epsilon-transitions:
This NFA accepts strings such as ac, abc, ...
Algorithm to employ in getting a
computer program to construct a
NFA for any regular expression
Basic building blocks:
(1) Any letter a of the alphabet is recognized by:
(2) The empty set  is recognized by:
Note: it is possible to avoid including some of the ε-productions
employed by the algorithm, but the increase in speed, if any, is
negligible.
(3) The empty string e is recognized by:
(4) Given a regular expression for R and S, assume these boxes
represent the finite automata for R and S:
(5) To construct a nfa for RS (concatenation):
(6) To construct a nfa for R | S (alternation):
(7) To construct a nfa for R* (closure):
NOTE: In 1-3 above we supply finite automata for
some basic regular expressions, and in 4-6 we
supply 3 methods of composition to form finite
automata for more complicated regular expressions.
These, in particular, provide methods for
constructing finite automata for regular expressions
such as, e.g.:
R+ = RR*
R? = R | ε
[1-3ab] = 1|2|3|a|b
Example
Construct a NFA for an identifier using the above mechanical metho
for the regular expression: letter ( letter | digit )*
First: construct the nfa for an identifier: ( letter | digit )
Example (Cont.1)
Next, construct the closure: ( letter | digit )*
1 2
3
4
5
6
7 8
e
e
e
e
e
e
e
e
letter
digit
Example (Cont.2)
Now, finish the construction for: letter ( letter | digit )*

More Related Content

Similar to finite_automata.ppt

A simple approach of lexical analyzers
A simple approach of lexical analyzersA simple approach of lexical analyzers
A simple approach of lexical analyzers
Archana Gopinath
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
woldu2
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
NderituGichuki1
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
Riazul Islam
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
bolovv
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
raosir123
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
Nitesh Dubey
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
gadisaAdamu
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
Dattatray Gandhmal
 
Lex analysis
Lex analysisLex analysis
Lex analysis
Suhit Kulkarni
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
PRASENJITMORE2
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
Mahesh Kumar Chelimilla
 
Compiler chapter six .ppt course material
Compiler chapter six .ppt course materialCompiler chapter six .ppt course material
Compiler chapter six .ppt course material
gadisaAdamu
 
Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
bolovv
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
Akila Krishnamoorthy
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
Rushabh2428
 
In the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docxIn the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docx
mecklenburgstrelitzh
 
Lecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdfLecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdf
Saravana Kumar
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
MDSayem35
 

Similar to finite_automata.ppt (20)

A simple approach of lexical analyzers
A simple approach of lexical analyzersA simple approach of lexical analyzers
A simple approach of lexical analyzers
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
 
Lecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.pptLecture 1 - Lexical Analysis.ppt
Lecture 1 - Lexical Analysis.ppt
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Lex analysis
Lex analysisLex analysis
Lex analysis
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
 
Lecture4 lexical analysis2
Lecture4 lexical analysis2Lecture4 lexical analysis2
Lecture4 lexical analysis2
 
Compiler chapter six .ppt course material
Compiler chapter six .ppt course materialCompiler chapter six .ppt course material
Compiler chapter six .ppt course material
 
Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
 
Automata theory - CFG and normal forms
Automata theory - CFG and normal formsAutomata theory - CFG and normal forms
Automata theory - CFG and normal forms
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
 
In the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docxIn the Notes on Programming Language Syntax page, an example par.docx
In the Notes on Programming Language Syntax page, an example par.docx
 
Lecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdfLecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdf
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 

Recently uploaded

Graphic Design Tools and Software .pptx
Graphic Design Tools and Software   .pptxGraphic Design Tools and Software   .pptx
Graphic Design Tools and Software .pptx
Virtual Real Design
 
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdfSECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
eloprejohn333
 
Timeless Principles of Good Design
Timeless Principles of Good DesignTimeless Principles of Good Design
Timeless Principles of Good Design
Carolina de Bartolo
 
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdfAHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
talaatahm
 
Practical eLearning Makeovers for Everyone
Practical eLearning Makeovers for EveryonePractical eLearning Makeovers for Everyone
Practical eLearning Makeovers for Everyone
Bianca Woods
 
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
qo1as76n
 
定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样
qo1as76n
 
一比一原版马里兰大学毕业证(UMD毕业证书)如何办理
一比一原版马里兰大学毕业证(UMD毕业证书)如何办理一比一原版马里兰大学毕业证(UMD毕业证书)如何办理
一比一原版马里兰大学毕业证(UMD毕业证书)如何办理
9lq7ultg
 
CocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdfCocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdf
PabloMartelLpez
 
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANEEASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
Febless Hernane
 
一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理
一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理
一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理
21uul8se
 
一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理
一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理
一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理
bo44ban1
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
pmgdscunsri
 
一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样
一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样
一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样
3vgr39kx
 
一比一原版布兰登大学毕业证(BU毕业证书)如何办理
一比一原版布兰登大学毕业证(BU毕业证书)如何办理一比一原版布兰登大学毕业证(BU毕业证书)如何办理
一比一原版布兰登大学毕业证(BU毕业证书)如何办理
wkip62b
 
Impact of Fonts: in Web and Apps Design
Impact of Fonts:  in Web and Apps DesignImpact of Fonts:  in Web and Apps Design
Impact of Fonts: in Web and Apps Design
contactproperweb2014
 
UXpert_Report (UALR Mapping Renewal 2022).pdf
UXpert_Report (UALR Mapping Renewal 2022).pdfUXpert_Report (UALR Mapping Renewal 2022).pdf
UXpert_Report (UALR Mapping Renewal 2022).pdf
anthonylin333
 
一比一原版肯特大学毕业证UKC成绩单一模一样
一比一原版肯特大学毕业证UKC成绩单一模一样一比一原版肯特大学毕业证UKC成绩单一模一样
一比一原版肯特大学毕业证UKC成绩单一模一样
tobbk6s8
 
一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样
一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样
一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样
881evgn0
 
Manual ISH (International Society of Hypertension)
Manual ISH (International Society of Hypertension)Manual ISH (International Society of Hypertension)
Manual ISH (International Society of Hypertension)
bagmai
 

Recently uploaded (20)

Graphic Design Tools and Software .pptx
Graphic Design Tools and Software   .pptxGraphic Design Tools and Software   .pptx
Graphic Design Tools and Software .pptx
 
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdfSECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
SECURING BUILDING PERMIT CITY OF CALOOCAN.pdf
 
Timeless Principles of Good Design
Timeless Principles of Good DesignTimeless Principles of Good Design
Timeless Principles of Good Design
 
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdfAHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
AHMED TALAAT ARCHITECTURE PORTFOLIO .pdf
 
Practical eLearning Makeovers for Everyone
Practical eLearning Makeovers for EveryonePractical eLearning Makeovers for Everyone
Practical eLearning Makeovers for Everyone
 
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
哪里办理美国中央华盛顿大学毕业证双学位证书原版一模一样
 
定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样定制美国西雅图城市大学毕业证学历证书原版一模一样
定制美国西雅图城市大学毕业证学历证书原版一模一样
 
一比一原版马里兰大学毕业证(UMD毕业证书)如何办理
一比一原版马里兰大学毕业证(UMD毕业证书)如何办理一比一原版马里兰大学毕业证(UMD毕业证书)如何办理
一比一原版马里兰大学毕业证(UMD毕业证书)如何办理
 
CocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdfCocaCola_Brand_equity_package_2012__.pdf
CocaCola_Brand_equity_package_2012__.pdf
 
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANEEASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
EASY TUTORIAL OF HOW TO USE CAPCUT BY: FEBLESS HERNANE
 
一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理
一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理
一比一原版亚利桑那大学毕业证(UA毕业证书)如何办理
 
一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理
一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理
一比一原版阿肯色大学毕业证(UCSF毕业证书)如何办理
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
 
一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样
一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样
一比一原版南安普顿索伦特大学毕业证Southampton成绩单一模一样
 
一比一原版布兰登大学毕业证(BU毕业证书)如何办理
一比一原版布兰登大学毕业证(BU毕业证书)如何办理一比一原版布兰登大学毕业证(BU毕业证书)如何办理
一比一原版布兰登大学毕业证(BU毕业证书)如何办理
 
Impact of Fonts: in Web and Apps Design
Impact of Fonts:  in Web and Apps DesignImpact of Fonts:  in Web and Apps Design
Impact of Fonts: in Web and Apps Design
 
UXpert_Report (UALR Mapping Renewal 2022).pdf
UXpert_Report (UALR Mapping Renewal 2022).pdfUXpert_Report (UALR Mapping Renewal 2022).pdf
UXpert_Report (UALR Mapping Renewal 2022).pdf
 
一比一原版肯特大学毕业证UKC成绩单一模一样
一比一原版肯特大学毕业证UKC成绩单一模一样一比一原版肯特大学毕业证UKC成绩单一模一样
一比一原版肯特大学毕业证UKC成绩单一模一样
 
一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样
一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样
一比一原版美国哥伦比亚大学毕业证Columbia成绩单一模一样
 
Manual ISH (International Society of Hypertension)
Manual ISH (International Society of Hypertension)Manual ISH (International Society of Hypertension)
Manual ISH (International Society of Hypertension)
 

finite_automata.ppt

  • 1. ICS312 Set 29 Deterministic Finite Automata Nondeterministic Finite Automata
  • 2. Deterministic Finite Automata • A regular expression can be represented (and recognized) by a machine called a deterministic finite automaton (dfa). • A dfa can then be used to generate the matrix (or table) used by the scanner (or lexical analyzer). • Deterministic finite automata are frequently also called simply finite automata (fa).
  • 3. Example of a DFA for Recognizing Identifiers
  • 4. Examples A dfa for regular expressions on the alphabet S = { a, b, c } a. Which have exactly one b:
  • 5. Examples (Cont. 1) b. Which have 0 or 1 b's:
  • 6. Examples (Cont. 2) A dfa for a number with an optional fractional part (assume S = { 0,1,2,3,4,5,6,7,8,9,+,-,. }:
  • 7. Constructing DFA • Regular expressions give us rules for recognizing the symbols or tokens of a programming language. • The way a lexical analyzer can recognize the symbols is to use a DFA (machine) to construct a matrix, or table, that reports when a particular kind of symbol has been recognized. • In order to recognize symbols, we need to know how to (efficiently) construct a DFA from a regular expression.
  • 8. How to Construct a DFA from a Regular Expression • Construct a nondeterministic finite automata (nfa) • Using the nfa, construct a dfa • Minimize the number of states in the dfa to get a smaller dfa
  • 9. Nondeterministic Finite Automata • A nondeterministic finite automata (NFA) allows transitions on a symbol from one state to possibly more than one other state. • Allows e-transitions from one state to another whereby we can move from the first state to the second without inputting the next character. • In a NFA, a string is matched if there is any path from the start state to an accepting state using that string.
  • 10. NFA Example This NFA accepts strings such as: abc abd ad ac
  • 11. Examples a f.a. for ab*: a f.a. for ad To obtain a f.a. for: ab* | ad We could try: but this doesn't work, as it matches strings such as abd
  • 12. Examples (Cont. 1) So, then we could try: It's not always easy to construct a f.a. from a regular expression. It is easier to construct a NFA from a regular expression.
  • 13. Examples (Cont. 2) Example of a NFA with epsilon-transitions: This NFA accepts strings such as ac, abc, ...
  • 14. Algorithm to employ in getting a computer program to construct a NFA for any regular expression Basic building blocks: (1) Any letter a of the alphabet is recognized by: (2) The empty set  is recognized by:
  • 15. Note: it is possible to avoid including some of the ε-productions employed by the algorithm, but the increase in speed, if any, is negligible. (3) The empty string e is recognized by: (4) Given a regular expression for R and S, assume these boxes represent the finite automata for R and S:
  • 16. (5) To construct a nfa for RS (concatenation): (6) To construct a nfa for R | S (alternation):
  • 17. (7) To construct a nfa for R* (closure):
  • 18. NOTE: In 1-3 above we supply finite automata for some basic regular expressions, and in 4-6 we supply 3 methods of composition to form finite automata for more complicated regular expressions. These, in particular, provide methods for constructing finite automata for regular expressions such as, e.g.: R+ = RR* R? = R | ε [1-3ab] = 1|2|3|a|b
  • 19. Example Construct a NFA for an identifier using the above mechanical metho for the regular expression: letter ( letter | digit )* First: construct the nfa for an identifier: ( letter | digit )
  • 20. Example (Cont.1) Next, construct the closure: ( letter | digit )* 1 2 3 4 5 6 7 8 e e e e e e e e letter digit
  • 21. Example (Cont.2) Now, finish the construction for: letter ( letter | digit )*