Finite State Machines State Transition Diagrams - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Finite State Machines State Transition Diagrams

Description:

Explain the FSM concept. Represent an FSM. as a diagram & as a ... GREP find files containing a pattern. LEX generate a recogniser. 16. Reasoning about FSM ... – PowerPoint PPT presentation

Number of Views:1012
Avg rating:3.0/5.0
Slides: 19
Provided by: julie57
Category:

less

Transcript and Presenter's Notes

Title: Finite State Machines State Transition Diagrams


1
Finite State Machines(State Transition Diagrams)
  • Explain the FSM concept
  • Represent an FSM
  • as a diagram as a table
  • Discuss uses of FSMs
  • Create an FSM from a description

2
What is a finite state machine?
  • A system with
  • A limited number of internal "states" (modes)
  • These control its response to an input.
  • In different states it may react differently to
    an input
  • Describe an FSM by defining for each state
  • the response (action) and next state (state
    transition) generated by an input (event
  • Representing an FSM
  • State transition diagram
  • Table

3
Coffee Machine Specification
  • Behaviour
  • Accepts 5, 10, 20p coins
  • Coffee costs 25p
  • Is this enough for a specification?

4
Diagram Representation
20p/Issue
Total0
Total0
Total0
5, 10, 20p/Issue
20p
10p
5p
10, 20p/Issue
20p/Issue
Total20
Total15
Total10
Total5
Total20
Total10
5p
5p
5p
10p
10p
5
Table Representation
Current Event
Action
Current State
Next State
6
Why use an FSM?
  • Clear description of behaviour
  • Diagram
  • Can be easier to understand than text
  • Simple clear semantics (meaning)
  • Allow checking for desirable properties
  • E.g. deadlocks
  • System trapped in a group of states
  • See reasoning about protocol in tutorial

7
Applications of FSM
  • Digital logic
  • Specifying data communication protocols
  • Specifying user dialogues
  • Defining class behaviour in UML
  • But
  • All computers are finite state machines but
    because of large amount of memory usually dont
    treat as finite state machines
  • Too complex

A useful technique but can be overwhelmed by
complexity
8
FSM User Interfaces
  • Used to define interaction
  • States
  • Permitted user actions (FSM events)
  • Responses (FSM actions)
  • Identical input may give different outputs
  • E.g. Word
  • Close empty file, modified file, saved file
  • Typing insert/overtype, Caps lock/shift
  • Design FSM to represent these situations

9
Word
New
Close
No file
Empty file
New/ Create file
No
New/ Create file
Close
type
Clean file
Yes/ Save
Save
type
Dirty file
Displaying Save Dialogue
Close/ Display Dialogue
  • Is it correct?
  • Is it complete?

Cancel
10
Calculator
  • Is it complete?
  • Is it correct?

11
Workflow Applications
  • An employee creates a purchase order.
  • The employee can modify and save this draft order
    as many times as required.
  • The employee can submit an order to a manager for
    approval or rejection.
  • If the manager rejects it, the purchase order
    returns to the draft state.
  • Approved or draft items can be deleted.
  • Items waiting for approval cant be deleted.

12
Workflow Applications
reject
Draft
Awaiting Approval
approve
create

submit
modify
delete
Approved
delete
13
FSM Languages Identifiers
?
non-letter
other
any
letter
?
?
letter
digit
  • Is this correct?
  • How would you allow _

14
FSM Languages Numbers
Integer
digit
,-
?
digit
digit
  • This uses a different convention for errors
  • Describe this convention
  • Is this definition of integers correct?
  • Can you define floating point numbers?

15
FSM Languages
  • FSM can recognise sets of words
  • e.g. identifiers, numbers, filenames (.txt)
  • But not every possible set
  • e.g. cant recognise matching brackets
  • Why not?
  • Uses
  • Editor (global search and replace)
  • g/ / /p replace two or more spaces by a space
  • Pattern matching in JavaScript
  • Unix utilities
  • GREP find files containing a pattern
  • LEX generate a recogniser

16
Reasoning about FSM
Validated
PIN
Not validated
Remove card / deliver cash
Remove card
Card inserted
Receipt not wanted
Want receipt / Print receipt
  • Can a receipt be given with no valid PIN?
  • Can the system be stuck in a small set of states?
  • Is the specification complete?

17
Problems with FSM
  • Complexity
  • They can have many states and transitions
  • Allow variables and conditions
  • Modify the notation
  • Allow nested states
  • Allow actions that occur when a state is entered
    or left
  • Limited expressiveness
  • Cant define some behaviours
  • E.g. correct matching of brackets
  • Imagine you have 10 states in your FSM
  • Input 10 ( - system goes through all states why?
  • Input a ( - must go into an existing state so?

18
Summary
  • FSM can model many systems
  • Digital hardware
  • User interface
  • Communication Protocols
  • Systems with modes
  • Clear specification
  • Allow reasoning
  • Checking consistency completeness
  • Complexity theoretical limitations
Write a Comment
User Comments (0)
About PowerShow.com