Package COM.INFORMATIMAGO.COMMON-LISP.CESARUM.DFA


This package implements a DFA, Deterministic Finite Automaton (or
Deterministic Finite State Machine).

A DFA has a state.

Our DFAs also have a set of slots.

Each DFA is implemented as a class.

Events are represented as generic functions called with the DFA
instance as first argument (and optionnaly other arguments).  They are
specialized on each specific class of DFA they're applicable to.



Example:

    (define-state-machine test-dfa
        :slots ((data :initarg :data :initform nil :accessor data))
        :initial zero
        :states ((zero
                  (:entry () (print `(entering zero)))
                  (:exit  () (print `(exiting zero)))
                  (got-a (sym) (push (cons 'a sym) data))
                  (got-b (sym) (push (cons 'b sym) data) (go-to-state one sym)))
                 (one
                  (:entry (sym) (print `(entering one ,sym)))
                  (:exit  ()    (print `(exiting one)))
                  (got-a (sym) (push (cons 'a sym) data))
                  (got-b (sym) (push (cons 'b sym) data) (go-to-state zero))))
        :documentation "A test DFA")

    (defparameter *d* (make-test-dfa '()))
    prints:
    (entering zero)
    --> *d*

    (got-a *d* 'a)
    --> ((a . a))

    (got-b *d* 'b)
    prints:
    (exiting zero)
    (entering one b)
    --> (entering one b)

    (got-a *d* 'a)
    --> ((a . a) (b . b) (a . a))

    (slot-value *d* 'data)
    --> ((a . a) (b . b) (a . a))


License:

    AGPL3

    Copyright Pascal J. Bourguignon 2012 - 2012

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.
    If not, see <http://www.gnu.org/licenses/>


(define-state-machine name &key slots initial states documentation)
macro
Defines a DFA class named NAME with the given SLOTS.

The CLAUSES define the states and transitions, that are implemented as
generic functions on the DFA class.
dfa
class
A base class for DFAs.

A DFA has a state, and transitions from one state to another can be
performed by event methods.
Class precedence list: DFA STANDARD-OBJECT T
Class init args: STATE
(dfa-state dfa)
generic-function
The state of the DFA.
(on-entry dfa state &rest rest)
generic-function
This generic function is called on entry into the state,
ie. at the end of the transition, when the state has been updated. (Methods
may further change the state).

The REST arguments are those passed to the event.
(on-exit dfa state &rest rest)
generic-function
This generic function is called on exit from the state,
ie. at the beginning of the transition, before the state changes.

The REST arguments are those passed to the event.