Finite State Machines
Lecture 3
1
Finite State Machines Lecture 3 1 Recall a Language is Regular if - - PowerPoint PPT Presentation
Finite State Machines Lecture 3 1 Recall a Language is Regular if L is empty L contains a single string (could be the empty string) If L 1 , L 2 are regular, then L = L 1 L 2 is regular If L 1 , L 2 are regular, then L= L 1 L
1
CS 374
2
CS 374
3
CS 374
Finite State Machines -Deterministic Finite Automata (FSM- DFA) DFAs around us: Vending machines, Elevators, Digital watch logic, Calculators, Lexical analyzers (part of program compilation), …
4
CS 374
5
string I read so far when I divided by 5.
spend that much memory!
CS 374
6
m0=2m if I see “0” next m1=2m+1 if I see “1” next
then line 3 tells me what the new remainder is (either m0 or m1)
CS 374
7
CS 374
finite writable memory (state)
next input symbol fed here
for the input so far store x mod 5 here (initial value “null”).
it is 0.
next-state look-up table
calculate x’ mod 5 from x mod 5 and input bit b, where x’ = 2x + b
8
CS 374
a number between 1 and 4). Unbounded, not infinite!
state with function called delta (δ).
when I finish reading the string, I output the value of the array.
CS 374
10
Instead of doing arithmetic at all, I could just hard code this lookup table into the code and simply do a lookup
accepting state!
CS 374
11
CS 374
12
1
1 3
1 1 1
2 4
1 1
CS 374
input bit current state next state 1 1 2 1 2 1 1 1 2 1 2
13
1
1 3
1 1 1
2 4
1 1
CS 374
input bit current state next state 1 1 2 1 2 1 1 1 2 1 2
14
CS 374
15
1) 2) 3) 1
1 3
1 1 1
2 4
1 1
Together with a description of what are the states and what are the accepting states
CS 374
16
CS 374
17
recursion!
CS 374
18
1
1 3
1 1 1
2 4
1 1
CS 374
19
1
1 3
1 1 1
2 4
1 1 1
1 2 4
1
4
CS 374
20
1 s t 1
CS 374
21
CS 374
22
CS 374
23
CS 374 Reject state
1 0,1 1 1 2 abbreviation B 1 A 2 B B B A 4 A 3 A B A
A AB ABB ABBA
1 3 1 2 1 1 1
0*11* (A+B)*ABBA
24
25
CS 374
26
CS 374
27
s a
CS 374
28
1
s a
CS 374
29
1 1
s a
CS 374
30
1 1
b s a
CS 374
31
1 1
b s a 0,1
CS 374
32
1 1 b s a 0,1