[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/annotation/ -> WactFSM.php (summary)

(no description)

File Size: 320 lines (11 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WactFSM:: (10 methods):
  __construct()
  reset()
  addTransition()
  addTransitions()
  addTransitionsArray()
  addTransitionAny()
  setDefaultTransition()
  getTransition()
  process()
  processList()


Class: WactFSM  - X-Ref

This class implements a Finite State Machine (FSM).

In addition to maintaining state, this FSM also maintains a user-defined
payload, therefore effectively making the machine a Push-Down Automata
(a finite state machine with memory).

This code is based on Noah Spurrier's Finite State Machine (FSM) submission
to the Python Cookbook:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146262

__construct($initialState, $payload)   X-Ref
This method constructs a new Finite State Machine (FSM) object.

In addition to defining the machine's initial state, a "payload" may
also be specified.  The payload represents a variable that will be
passed along to each of the action functions.  If the FSM is being used
for parsing, the payload is often a array that is used as a stack.

param: string  $initialState   The initial state of the FSM.
param: mixed   $payload        A payload that will be passed to each

reset()   X-Ref
This method resets the FSM by setting the current state back to the
initial state (set by the constructor).


addTransition($symbol, $state, $nextState, $action = null)   X-Ref
This method adds a new transition that associates:

(symbol, currentState) --> (nextState, action)

The action may be set to NULL, in which case the processing routine
will ignore the action and just set the next state.

param: string  $symbol         The input symbol.
param: string  $state          This transition's starting state.
param: string  $nextState      This transition's ending state.
param: string  $action         The name of the function to invoke

addTransitions($symbols, $state, $nextState, $action = null)   X-Ref
This method adds the same transition for multiple different symbols.

param: array   $symbols        A list of input symbols.
param: string  $state          This transition's starting state.
param: string  $nextState      This transition's ending state.
param: string  $action         The name of the function to invoke

addTransitionsArray($transitions)   X-Ref
This method adds an array of transitions.  Each transition is itself
defined as an array of values which will be passed to addTransition()
as parameters.

param: array   $transitions    An array of transitions.

addTransitionAny($state, $nextState, $action = null)   X-Ref
This method adds a new transition that associates:

(currentState) --> (nextState, action)

The processing routine checks these associations if it cannot first
find a match for (symbol, currentState).

param: string  $state          This transition's starting state.
param: string  $nextState      This transition's ending state.
param: string  $action         The name of the function to invoke

setDefaultTransition($nextState, $action)   X-Ref
This method sets the default transition.  This defines an action and
next state that will be used if the processing routine cannot find a
suitable match in either transition list.  This is useful for catching
errors caused by undefined states.

The default transition can be removed by setting $nextState to NULL.

param: string  $nextState      The transition's ending state.
param: string  $action         The name of the function to invoke

getTransition($symbol)   X-Ref
This method returns (nextState, action) given an input symbol and
state.  The FSM is not modified in any way.  This method is rarely
called directly (generally only for informational purposes).

If the transition cannot be found in either of the transitions lists,
the default transition will be returned.  Note that it is possible for
the default transition to be set to NULL.

param: string  $symbol         The input symbol.
return: mixed   Array representing (nextState, action), or NULL if the

process($symbol)   X-Ref
This method is the main processing routine.  It causes the FSM to
change states and execute actions.

The transition is determined by calling getTransition() with the
provided symbol and the current state.  If no valid transition is found,
process() returns immediately.

The action callback may return the name of a new state.  If one is
returned, the current state will be updated to the new value.

If no action is defined for the transition, only the state will be
changed.

param: string  $symbol         The input symbol.

processList($symbols)   X-Ref
This method processes a list of symbols.  Each symbol in the list is
sent to process().

param: array   $symbols        List of input symbols to process.



Generated: Sat Aug 30 04:38:32 2008 Cross-referenced by PHPXref 0.7