Lecture 4
Lecture 4
Finite Automata
s0 s1
Finite Automata
Automaton that accepts any number of “1”s followed by single “0”
as input 1 0
s0 s1
Finite Automata
Regular language that this automaton recognizes
1
0 0 0, 1
s0 s1 s2
(0|1)*00(0|1)*
Finite Automata
Regular language that this automaton recognizes
1
0 0 0
s0 s1 s2
1
1
(0|1)*00
Finite Automata - ε
● Automata may accept “ε” as input
● Can move from one state to another without consuming input
s0 s1
1
Finite Automata - NFA
● Non-deterministic Finite Automata
○ Multiple transitions from one state for the same input character
○ Can be in set of states after every input
○ Can have ε moves 1
s0 s1 s2
1
Finite Automata - DFA
● Deterministic Finite Automata
○ One transition from one state for an input character
○ Cannot have ε moves
1
s0 s1 s2
0
DFA vs. NFA
● DFA takes only one path per input through the automaton while
NFA can choose out of multiple paths
● NFA accepts if one or more of the multiple paths lead to an
accepting state
● Every DFA is also an NFA (but not vice-versa)
● Both recognize the same set of languages but DFAs are faster
● NFAs may be simpler/smaller than the DFAs
● Space-time tradeoff!
DFA vs. NFA
1
0 0
s0 s1 s2
0
DFA vs. NFA
1
0 0
s0 s1 s2
1
0 0 0
0
s0 s1 s2
1
1
Implementing
Lexical
Specifications
Steps in Conversion
Lexical Regular
Specification Expressions
Non-deterministic
Finite Automata
Lookup Deterministic
Table Finite Automata
NFA for RE
ε ε
c c
NFA for RE
ε ε
c c
R1R2
R1 ε R2
NFA for RE
R1
ε ε
R1 | R2
ε R2 ε
NFA for RE
R1
ε ε
R1 | R2
ε R2 ε
* ε R ε
R
ε
NFA for RE
((ab)*|c)*
NFA for RE
((ab)*|c)*
a ε b
c
NFA for RE
((ab)*|c)*
ε
ε a ε b ε
c
NFA for RE
((ab)*|c)*
ε
ε a ε b ε
ε ε
ε
ε ε
c
NFA for RE
((ab)*|c)*
ε
ε a ε b ε
ε ε
ε
ε ε ε
c
ε
ε