next next up down toc toc mail

9.2.  Finite State Machines

Definition 8.1 (Finite State Machine)

A FSM consists of a set of states S, a set of input symbols I, a set of end states E, a set of error states F, a action function A and a transaction function T.
S
a set of states and # of members of S < ∞, [equation] start state, and [equation] [isin] S
I
a set of input symbols and # of members of I < ∞
E
a set of end states and E [sube] S
F
a set of error states and F [sube] S and E [cap] F = Ø
A
a action function A with A: S × I [larr] ``actions'' A( state, input symbol ) [larr] action
T
a function T with T: S × I [larr] S new_state = T( state, input symbol )

The tuple (S, I, E, F, T, A) is called a FSM.

FSM can be used to recognize patterns.

For example:

@ s sub 0 @    = 0
S             = { 0, 1, 2, 3, 4, 5, 6 }
I             = { , '0'-'9', 'a'-'z',  'A'-'Z', whiteSpace }
E             = { 6 }
F             =
A             A(6,  )        = 'print "I found ``plan 9'' and exit
              A(?, ? )       = do nothing for other input symbols and states
T             T(0, 'p' )     = 1
              T(1, 'l' )     = 2
              T(2, 'a' )     = 3
              T(3, 'n' )     = 4
              T(4,' ')       = 5
              T(5, '9' )     = 6
              for all other input symbols and states:
              T(i, s )       = 0

A graphical representation:

The FSM detects also ``grumbleplan 9''!

Next iteration:

[equation] = -1

The FSM doesn't detect ``[Dagger] [Dagger] plan 9[Dagger] . [Dagger] [isin] wordSeperator.

Next iteration:

[equation] = -1

The FSM detects ``[Dagger] plxplan 9[Dagger] . [Dagger] [isin] wordSeperator. Next iteration:

[equation] = -1

The FSM detects only ``[Dagger] plan 9[Dagger] . [Dagger] [isin] wordSeperator.

The definition ot the FSM:

S             = { -1, 0, 1, 2, 3, 4, 5, 6, 7 }
@ s sub 0 @   = -1
I             { x | x is a character }
E             { 7 }
F
A             A(7,  }        = print Heuraka and exit.
              A(?, ? }       = do nothing
T             T(-1, WS)      = 0
              T(-1, x)       = -1      for x  wordSeperator
              T(0, WS)       = 0
              T(0, 'p')      = 1
              T(1, 'l')      = 2
              T(1, x)        = -1      for x  I \ { 'l' }
              T(2, 'a')      = 3
              T(2, x)        = -1      for x  I \ { 'a' }
              T(3, 'n')      = 4
              T(3, x)        = -1      for x  I \ { 'n' }
              T(4, ' ')      = 5
              T(4, x)        = -1      for x  I \ { ' ' }
              T(5, '9')      = 6
              T(5, x)        = 0       for x  I \ wordSeperator
              T(5, x)        = -1      for x  I \ { '9' }
              T(6, WS)       = 7
              T(6, x)        = -1      for x  I \ wordSeperator

Define a FSM which recognizes sequences of letters that have subsequences

aeiou.

For example:

--   adventitious
--   facetious
--   sacrilegious

A graphical representation:

The definition:

@ s sub 0 @   = 0
S             = { 0, 1, 2, 3, 4, 5, 7, 8 }
I             = { x | x is a character }
E             = { 7 }
F             = { 8 }
A             A(7,  }        = print the word
              A(8,  }        = exit
              A(1, x )       = store x,          for x  I \ { 'a' }  wordSeperator
              A(2, x )       = store x,          for x  I \ { 'e' }  wordSeperator
              A(3, x )       = store x,          for x  I \ { 'i' }  wordSeperator
              A(4, x )       = store x,          for x  I \ { 'o' }  wordSeperator
              A(5, x )       = store x,          for x  I \ { 'u' }  wordSeperator
              A(6, x )       = store x,          for x  I \ wordSeperator
T             T(0, WS)       = 0
              T(0, x)        = 1       for x  I \ { 'a' }
              T(0, 'a')      = 2
              T(1, 'a')      = 2
              T(1, x)        = 1       for x  I \ { 'a' }
              T(1, x)        = 8       for x  wordSeperator
              T(2, 'e')      = 3
              T(2, x)        = 1       for x  I \ { 'e' }
              T(2, x)        = 8       for x  wordSeperator
              T(3, 'i')      = 4
              T(3, x)        = 1       for x  I \ { 'i' }
              T(3, x)        = 8       for x  wordSeperator
              T(4, 'o')      = 5
              T(4, x)        = 1       for x  I \ { 'o' }
              T(4, x)        = 8       for x  wordSeperator
              T(5, 'u')      = 6
              T(5, x)        = 1       for x  I \ { 'u' }
              T(5, x)        = 8       for x  wordSeperator
              T(6, x)        = 7       for x  wordSeperator
              T(6, x)        = 1       for x  I \ wordSeperator

Find the words

--   Kenya
--   Kansas
--   Kauder
--   Kunta Kinte
in an input stream.

Find the words with

--   the first letter must be an 'p'
--   the second letter must be an 'r'
--   the third letter can be an 'o' or 'e'
--   the rest ot the word is 'klap'

in an input stream.

Find the words with the substring

--   Yps and
--   Ilon

in an input stream.


back next up down toc toc mail


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 27/July/98 (12:14)