You are on page 1of 25

Lecture 6

Finite Automata
We need a mechanism to determine if an input string w belongs to L(R)
, the language denoted by regular expression R. Such a mechanism is
called an acceptor.

Input w string Yes, if w ∈ L

acceptor

Language L
No, if w ∉ L
Finite Automata
The acceptor is based on Finite Automata (FA)

Input w string Yes, if w ∈ L

acceptor

Language L
No, if w ∉ L
Finite Automata
A Finite Automaton consists of
An input alphabet Σ
A set of states
A start (initial) state
A set of transitions
A set of accepting (final states)
Finite Automata
A finite automaton accepts a string if we can follow transitions
labeled with characters in the string from start state to some
accepting state.
Finite Automata
A finite automaton accepts a string if we can follow transitions
labeled with characters in the string from start state to some
accepting state.
Finite Automata
A FA that accepts only “1”
1
Finite Automata
A FA that accepts 1’s followed by single 0
1 0
Finite Automata
A FA that accepts ab*a. (Σ : {a,b})
b

a a
Encoding of FA

a a
0 1 2
Encoding of FA

a b
0 1 err
1 2 1
2 err err
Relationship between RE and Finite
Automata
We now have a strategy for building lexical analyzer. The tokens
we want to recognize are encoded using regular expressions. If
we can build a FA for regular expressions, we have our lexical
analyzer.
Nondeterministic Finite Automata (NFA)
An NFA can have multiple transitions for one input in a given
state. In the following NFA, and input of 1 can cause the
automaton to go to state B or C.
1

0 1
A B C
Nondeterministic Finite Automata (NFA)
It can also have ε moves; the automaton machine can move from
state A to state B without consuming input.

ε
A B
Thomson’s Construction
Thompson's construction algorithm, also called the
McNaughton–Yamada–Thompson algorithm,[1] is a method of
transforming a regular expression into an equivalent 
nondeterministic finite automaton (NFA).

(Wikipedia)
Nondeterministic Finite Automata (NFA)
NFA for a

a
S0 S1
Nondeterministic Finite Automata (NFA)
NFA for b

b
S0 S1
NFA for ab (Concatenation)
NFA for a|b (Union)
NFA for a* (Kleen Closure)
NFA for a(b|c)*
Step 1 Recall Union b | c
b

ε ε

c
ε ε
NFA for a(b|c)*
Step 2 Recall Kleen Closure (b | c)*
b

ε ε

ε ε

c
ε ε
NFA for a(b|c)*
Step 3 Recall Concatenation a(b | c)*
b

ε ε
a ε
ε ε

c
ε ε
NFA for a(b|c)*
Name the States
b
S4 S5
ε ε
a ε
ε ε
S0 S1 S2 S3 S8 S9

c
ε S7 ε
S6
Deterministic Finite Automata (DFA)
In Deterministic Finite Automata (DFA), on the other hand, there is only one transition per input per
state. There are no ε -moves. Upon execution of the automaton, a DFA can take only one path through
the state graph and is therefore completely determined by input.

NFAs and DFAs recognize the same set of languages (regular languages). DFAs are easier to
implement – table driven. For a given language, the NFA can be simpler than the DFA. DFA can be
exponentially larger than NFA.

You might also like