Class DFA
In: dfa.rb
Parent: Object

A deterministic finite automata is defined as: (S,E,d,s0,F) where S is the set of states, E is the input alphabet, d is the transition function (d: S x E -> S), s0 is the initial state, and F is the set of final states.

In this implementation, we ignore S and E, and d may have side effects. S and E are implicitly enforced by the transition function, which would probably raise an exception in the case of a bad (state, input) pair (but you can handle it however you like).

Methods

eat   final?   new   transition  

Attributes

d  [RW]  d responds to call(state,input), returning the successive state. It may do anything else that you want it to do; this is how transitional actions are implemented.
finals  [RW]  Final states. Responds to include?(state)
start  [R]  The initial state as provided to the constructor. This is for your reference only (it‘s never used outside of the constructor.)
state  [RW]  The current state.

Public Class methods

Public Instance methods

Given an input symbol, transition the state machine according to the return value of d, and return true if the now-current state is a final state, or false otherwise.

Is the current state a final state?

Syntactic sugar for defining d. The block will be called with the current state and input when eat(a) is called.

[Validate]