Describing Finite State Machines Murray Cole Describing Finite - - PowerPoint PPT Presentation

describing finite state machines
SMART_READER_LITE
LIVE PREVIEW

Describing Finite State Machines Murray Cole Describing Finite - - PowerPoint PPT Presentation

I V N E U R S E I H T Y T O H F G R E U D I B N Describing Finite State Machines Murray Cole Describing Finite State Machines 1 A Notation for FSMs? FSMs are a useful tool (reactive systems are everywhere)


slide-1
SLIDE 1

T H E U N I V E R S I T Y O F E D I N B U R G H

Describing Finite State Machines

Murray Cole

Describing Finite State Machines

slide-2
SLIDE 2

1

A Notation for FSMs?

  • FSMs are a useful tool (reactive systems are everywhere)
  • graphical notation gets cumbersome, so need a “better” notation
  • Regular Expressions do the job for acceptors (with real

applications in Unix commands, text processing, compilers)

Describing Finite State Machines

slide-3
SLIDE 3

2

Regular Expressions

  • ✁✄✂
☎✝✆ ☎✝✞ ☎✠✟ ☎✝✡ ☎✠☛ ☎✠☞ ☎
  • ☎✠✌
☎✠✍ ✎ ✁✄✂ ☎✝✆ ☎ ✞ ☎ ✟ ☎ ✡ ☎✠☛ ☎ ☞ ☎
  • ☎✠✌
☎✠✍ ✎ ✁✠✏ ☎✒✑ ✎✔✓ ✕ ✏ ✓ ✆ ✁ ✂ ☎ ✆ ✎✖✓ ✆

Each of these defines a set of strings corresponding to a language

Describing Finite State Machines

slide-4
SLIDE 4

3

Syntax and Semantics

  • any symbol from the input alphabet stands for itself

(means the set containing just that symbol as a string)

  • the symbol
  • stands for the empty string

(means the set containing just the empty string)

  • the symbol

stands for no strings at all (means the empty set)

  • if

and

are RE’s,

✂ ✄

stands for a sequence of an

then an

(means the set of strings which are formed from a string from

followed by a string from

)

Describing Finite State Machines

slide-5
SLIDE 5

4

Syntax and Semantics

  • if

and

are RE’s,

✂ ☎ ✄

stands for the choice of

  • r an

(means the set of strings which are in the set union of

and

)

  • if

is a RE,

✂ ✓

stands for zero or more repeats

s (means the set closure of the set of strings which are in

)

  • the operators have precedences, repeat
  • sequence
  • choice, and

we can use parentheses ‘(’ and ‘)’ to group expressions (like arithmetic expressions in Java)

Describing Finite State Machines

slide-6
SLIDE 6

5

Examples

Write down all the strings in the language defined by

✁ ✑ ☎ ✕ ✎ ✏ ✁ ✑ ☎ ✕ ✎✁

Write some of the strings in the language defined by

✁ ✂ ✓ ☎ ✆ ✎✄✂ ✁ ✆ ☎ ✂ ✓ ✎

and some strings which aren’t Give an informal description of the language defined by

✁✠✏ ☎ ✑ ✎ ✓ ✑

Write down a regular expression defining the language of As and Bs in which every string contains an odd number of Bs

Describing Finite State Machines

slide-7
SLIDE 7

6

Java Floating Point Numbers

Use italics (

✄✂

etc) to stand for sub-expressions (not symbols)

✄ ☎
  • ☎✝✆
☎✟✞ ✁ ☎ ✂ ☎✝✆ ☎✝✞ ☎ ✟ ☎ ✡ ☎ ☛ ☎ ☞ ☎
✌ ☎✠✍ ✂ ☎ ✁ ✓ ✠ ☎ ✄ ✁ ✁ ✂ ✡ ✂ ☎ ✡ ✁ ✂ ✎ ☛ ☎ ☞ ✄ ✁ ✂ ☎
☎ ✠ ☛

So, +12.01E-34 is a valid constant while -12E+5 is’nt

Describing Finite State Machines

slide-8
SLIDE 8

7

Variable Names

✁ ☎ ✡ ✡ ✡✂ ☎ ✏ ☎ ✡ ✡ ✡✄ ✁ ☎ ✂ ☎✝✆ ☎✝✞ ☎ ✟ ☎✝✡ ☎✠☛ ☎ ☞ ☎
✌ ☎✠✍ ☎ ☎
✁ ✎ ✓

Describing Finite State Machines

slide-9
SLIDE 9

8

Algebraic Laws

Regular expressions are a kind of algebra Like other algebras, there are rules which let us manipulate expressions (usually with the goal of simplifying them)

✁ ☎ ✂ ☎ ✂ ☎ ✂ ☎ ✁

(1)

✂ ☎ ✂ ☎ ✂

(2)

✂ ☎ ✄ ☎ ✄ ☎ ✂

(3)

✁ ✂ ☎ ✄ ✎ ☎✁ ☎ ✂ ☎ ✁ ✄ ☎✁ ✎

(4)

☎ ✂ ☎ ✂
  • (5)
✁ ✂ ☎ ✁ ☎ ✂ ✁

(6)

Describing Finite State Machines

slide-10
SLIDE 10

9

More Algebraic Laws

✁ ✂ ✄ ✎
✂ ✁ ✄

(7)

✂ ✁ ✄ ☎✁ ✎ ☎ ✂ ✄ ☎ ✂
  • (8)
✁ ✂ ☎ ✄ ✎
  • (9)
✁ ✓ ☎
  • (10)
✂ ✂ ✓ ☎ ✂ ✓ ✂

(11)

✂ ✂ ✓ ☎
✂ ✓

(12)

✁ ✂ ☎ ✄ ✎ ✓ ☎ ✁ ✂ ✓ ✄ ✓ ✎ ✓

(13)

✁ ✂ ✄ ✎ ✓ ✂ ☎ ✂ ✁ ✄ ✂ ✎ ✓

(14)

Describing Finite State Machines

slide-11
SLIDE 11

10

An example

Show that

✓ ✂ ☎ ✁
✎ ✓ ☎ ✁
✎ ✓

(This is in the lecture note - you add the rules used)

✓ ✂ ☎ ✁
✎ ✓ ☎
✎ ✓ ☎ ✁
✎ ✓ ☎
✎ ✓ ☎
✎ ✓ ☎
✎ ✓ ☎
✎ ✓

Describing Finite State Machines

slide-12
SLIDE 12

11

Power of Regular Expressions

  • For every regular expression there is an equivalent FSM acceptor
  • For every FSM acceptor there is an equivalent regular expression
  • Even true for acceptors with the “extra” compositions like

interleaving and intersection.

  • Regular expressions are widely used in file and text processing,

and in the definition and compilation of programming languages

Describing Finite State Machines

slide-13
SLIDE 13

12

Summary

  • Regular expressions define sets of strings (languages)

– sequence, choice, repetition

  • We can manipulate them with algebraic rules
  • They have the same power as FSM acceptors

Describing Finite State Machines