Abstract Finite State Machine

Take a look on Wikipedia state machine description: http://en.wikipedia.org/wiki/Finite_state_machine

Any type of Transducers (Moore machine or Mealy machine) also may be implemented by using this abstract FSM. process() methods invokes a specified actions which may construct FSM output. Actions may be also used to signal, that we have reached Accept State

category Zend
package Zend_Search_Lucene
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Finite State machine constructor

__construct(array $states = array(), array $inputAphabet = array(), array $rules = array()

$states is an array of integers or strings with a list of possible machine states constructor treats fist list element as a sturt state (assignes it to $_current state). It may be reassigned by setState() call. States list may be empty and can be extended later by addState() or addStates() calls.

$inputAphabet is the same as $states, but represents input alphabet it also may be extended later by addInputSymbols() or addInputSymbol() calls.

$rules parameter describes FSM transitions and has a structure: array( array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), ... ) Rules also can be added later by addRules() and addRule() calls.

FSM actions are very flexible and may be defined by addEntryAction(), addExitAction(), addInputAction() and addTransitionAction() calls.

Parameters

$states

array

$inputAphabet

array

$rules

array

Add state entry action.

addEntryAction(integer|string $state, \Zend_Search_Lucene_FSMAction $action) 

Several entry actions are allowed. Action execution order is defined by addEntryAction() calls

Parameters

$state

integerstring

$action

\Zend_Search_Lucene_FSMAction

Add state exit action.

addExitAction(integer|string $state, \Zend_Search_Lucene_FSMAction $action) 

Several exit actions are allowed. Action execution order is defined by addEntryAction() calls

Parameters

$state

integerstring

$action

\Zend_Search_Lucene_FSMAction

Add input action (defined by {state, input} pair).

addInputAction(integer|string $state, $inputSymbol, \Zend_Search_Lucene_FSMAction $action) 

Several input actions are allowed. Action execution order is defined by addInputAction() calls

Parameters

$state

integerstring

$inputSymbol

$action

\Zend_Search_Lucene_FSMAction

Add symbol to the input alphabet

addInputSymbol(integer|string $inputSymbol) 

Parameters

$inputSymbol

integerstring

Add symbols to the input alphabet

addInputSymbols(array $inputAphabet) 

Parameters

$inputAphabet

array

Add symbol to the input alphabet

addRule(integer|string $sourceState, integer|string $input, integer|string $targetState, \Zend_Search_Lucene_FSMAction|null $inputAction = null

Parameters

$sourceState

integerstring

$input

integerstring

$targetState

integerstring

$inputAction

\Zend_Search_Lucene_FSMActionnull

Exceptions

\Zend_Search_Exception

Add transition rules

addRules(array $rules) 

array structure: array( array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), array(sourseState, input, targetState[, inputAction]), ... )

Parameters

$rules

array

Add state to the state machine

addState(integer|string $state) 

Parameters

$state

integerstring

Add states to the state machine

addStates(array $states) 

Parameters

$states

array

Add transition action (defined by {state, input} pair).

addTransitionAction(integer|string $sourceState, integer|string $targetState, \Zend_Search_Lucene_FSMAction $action) 

Several transition actions are allowed. Action execution order is defined by addTransitionAction() calls

Parameters

$sourceState

integerstring

$targetState

integerstring

$action

\Zend_Search_Lucene_FSMAction

Get FSM state.

getState() : integer | string

Returns

integerstring$state|null

Process an input

process(mixed $input) 

Parameters

$input

mixed

Exceptions

\Zend_Search_Exception

reset()

reset() 

Set FSM state.

setState(integer|string $state) 

No any action is invoked

Parameters

$state

integerstring

Exceptions

\Zend_Search_Exception

 Properties

 

Current state

$_currentState : integer | string

Default

null
 

List of entry actions Each action executes when entering the state

$_entryActions : array

Default

array()

[state] => action

 

List of exit actions Each action executes when exiting the state

$_exitActions : array

Default

array()

[state] => action

 

List of input actions Each action executes when entering the state

$_inputActions : array

Default

array()

[state][input] => action

 

Input alphabet

$_inputAphabet : array

Default

array()
 

State transition table

$_rules : array

Default

array()

[sourceState][input] => targetState

 

Machine States alphabet

$_states : array

Default

array()
 

List of input actions Each action executes when entering the state

$_transitionActions : array

Default

array()

[state1][state2] => action