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

PPTX
Regular Expression to Finite Automata
PDF
Regular Expression to Non-Deterministic Finite Automata Converter
PPTX
inbound6417574391896884649.pptx
PDF
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
PDF
Regular Expression to Deterministic Finite Automata
PPTX
NFA & DFA
PDF
Compiler lec 9
PPTX
Unit2 Toc.pptx
Regular Expression to Finite Automata
Regular Expression to Non-Deterministic Finite Automata Converter
inbound6417574391896884649.pptx
Automata_Theory_and_compiler_design_UNIT-1.pptx.pdf
Regular Expression to Deterministic Finite Automata
NFA & DFA
Compiler lec 9
Unit2 Toc.pptx

Similar to finite_automata.ppt (20)

PDF
Finite Automata
PPTX
A Lecture of Compiler Design Subject.pptx
PPTX
Compiler Design_Lexical Analysis phase.pptx
PPTX
The Theory of Finite Automata.pptx
PPTX
TOC Introduction
PPTX
TCS MUBAI UNIVERSITY ATHARVA COLLEGE OF ENGINEERING.pptx
PDF
TCS GOLDEN NOTES THEORY OF COMPUTATION .pdf
PPTX
03-FiniteAutomata.pptx
PDF
5. NFA & DFA.pdf
PPTX
Finite Automata in compiler design
PPTX
TheoryOfComputaionNonDeterministic1.pptx
PPTX
Theory of computation Unit 1 Lecute 2.pptx
PPTX
FiniteAutomata_anim.pptx
PPTX
FiniteAutomata_anim.pptx
PPTX
INTRODUTION Formal Language and Automatic Theory.pptx
PPTX
AUTOMATA THEORY AUTOMATA THEORYAutomata3Chapter2.pptx
PPT
Finite automata(For college Seminars)
PPTX
Chapter-twoChapter-three automata and complexity theory .pptx
PPT
2_4 Finite Automata.ppt
PPTX
chapter 1 automata and complexity theory lecture note.pptx
Finite Automata
A Lecture of Compiler Design Subject.pptx
Compiler Design_Lexical Analysis phase.pptx
The Theory of Finite Automata.pptx
TOC Introduction
TCS MUBAI UNIVERSITY ATHARVA COLLEGE OF ENGINEERING.pptx
TCS GOLDEN NOTES THEORY OF COMPUTATION .pdf
03-FiniteAutomata.pptx
5. NFA & DFA.pdf
Finite Automata in compiler design
TheoryOfComputaionNonDeterministic1.pptx
Theory of computation Unit 1 Lecute 2.pptx
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
INTRODUTION Formal Language and Automatic Theory.pptx
AUTOMATA THEORY AUTOMATA THEORYAutomata3Chapter2.pptx
Finite automata(For college Seminars)
Chapter-twoChapter-three automata and complexity theory .pptx
2_4 Finite Automata.ppt
chapter 1 automata and complexity theory lecture note.pptx
Ad

Recently uploaded (20)

PPTX
Fundamental Principles of Visual Graphic Design.pptx
PPTX
Media And Information Literacy for Grade 12
PPTX
Special finishes, classification and types, explanation
PPTX
mahatma gandhi bus terminal in india Case Study.pptx
PDF
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
PDF
SEVA- Fashion designing-Presentation.pdf
PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
PPT
Machine printing techniques and plangi dyeing
PPTX
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
PPTX
building Planning Overview for step wise design.pptx
PDF
YOW2022-BNE-MinimalViableArchitecture.pdf
PPTX
joggers park landscape assignment bandra
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PDF
Urban Design Final Project-Context
PDF
The Advantages of Working With a Design-Build Studio
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PPTX
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
PPTX
An introduction to AI in research and reference management
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PDF
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
Fundamental Principles of Visual Graphic Design.pptx
Media And Information Literacy for Grade 12
Special finishes, classification and types, explanation
mahatma gandhi bus terminal in india Case Study.pptx
Skskkxiixijsjsnwkwkaksixindndndjdjdjsjjssk
SEVA- Fashion designing-Presentation.pdf
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
Machine printing techniques and plangi dyeing
AC-Unit1.pptx CRYPTOGRAPHIC NNNNFOR ALL
building Planning Overview for step wise design.pptx
YOW2022-BNE-MinimalViableArchitecture.pdf
joggers park landscape assignment bandra
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
Urban Design Final Project-Context
The Advantages of Working With a Design-Build Studio
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Complete Guide to Microsoft PowerPoint 2019 – Features, Tools, and Tips"
An introduction to AI in research and reference management
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
Ad

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 )*