Professional Documents
Culture Documents
Lecture 07
Lecture 07
LECTURE 7
Table Encoding of FA
Transition b
table a a
0 1 2
a b
0 1 err
1 2 1
2 err err
2
Simulating FA 3
trans_table[NSTATES][NCHARS];
accept_states[NSTATES];
state = INITIAL;
while(state != err){
c = input.read();
if(c == EOF ) break;
state=trans_table[state][c];
}
return accept_states[state];
Simulating FA 4
trans_table[NSTATES][NCHARS];
accept_states[NSTATES];
state = INITIAL;
while(state != err){
c = input.read();
if(c == EOF ) break;
state=trans_table[state][c];
}
return accept_states[state];
Simulating FA 5
trans_table[NSTATES][NCHARS];
accept_states[NSTATES];
state = INITIAL;
while(state != err){
c = input.read();
if(c == EOF ) break;
state=trans_table[state][c];
}
return accept_states[state];
Simulating FA 6
trans_table[NSTATES][NCHARS];
accept_states[NSTATES];
state = INITIAL;
while(state != err){
c = input.read();
if(c == EOF ) break;
state=trans_table[state][c];
}
return accept_states[state];
Simulating FA 7
trans_table[NSTATES][NCHARS];
accept_states[NSTATES];
state = INITIAL;
while(state != err){
c = input.read();
if(c == EOF ) break;
state=trans_table[state][c];
}
return accept_states[state];
Simulating FA 8
trans_table[NSTATES][NCHARS];
accept_states[NSTATES];
state = INITIAL;
while(state != err){
c = input.read();
if(c == EOF ) break;
state=trans_table[state][c];
}
return accept_states[state];
RE → Finite Automata 9
Nondeterministic Finite
Automaton (NFA)
Can have multiple transitions
for one input
in a given state
Can have - moves
Epsilon Moves 11
ε – moves
machine can move from state A to state B without consuming input
A B
NFA 12
operation of the automaton is not
completely defined by input
1
0 1
A B C
1
0 1
A B C
0
DFA and NFA 15
A DFA
can take only one path through
the state graph.
Completely determined by input.
NFA vs DFA 17
Subset construction
NFA → DFA
Build the simulation.
Minimize number of states in
DFA (Hopcroft’s algorithm)
RE → NFA Construction 22
Key idea:
NFA pattern for each symbol
and each operator.
Join them with -moves in
precedence order.
RE → NFA Construction 23
a
s0 s1
NFA for a
a b
s0 s1 s3 s4
NFA for ab
RE → NFA Construction 24
a
NFA for a s0 s1
RE → NFA Construction 25
a
NFA for a s0 s1
b
NFA for b s3 s4
RE → NFA Construction 26
a
NFA for a s0 s1
b
NFA for b s3 s4
a b
s0 s1 s3 s4
RE → NFA Construction 27
a
NFA for a s0 s1
b
NFA for b s3 s4
a b
s0 s1 s3 s4
NFA for ab
RE → NFA Construction 28
a
s1 s2
s0 s5
b
s3 s4
NFA for a | b
RE → NFA Construction 29
a
s1 s2
NFA for a
RE → NFA Construction 30
a
s1 s2
b
s3 s4
a
s1 s2
s0 s5
b
s3 s4
NFA for a | b
RE → NFA Construction 32
s1
a
s0 s2 s4
NFA for a*
RE → NFA Construction 33
a
s1 s2
NFA for a
RE → NFA Construction 34
s1
a
s0 s2 s4
NFA for a*
Example RE → NFA 35
b
s4 s5
a
s0 s1 s2 s3 s8 s9
s c
6 s7
Example RE → NFA 36
a
s0 s1
Example RE → NFA 37
b
s4 s5
a
s0 s1
c
s6 s7
Example RE → NFA 38
b
s4 s5
a
s0 s1 s3 s8
s c
6 s7
Example RE → NFA 39
Example RE → NFA 40
b
s4 s5
a
s0 s1 s2 s3 s8 s9
s c
6 s7