2 Automata: Compiling State Machines
(require unstable/automata) | package: base |
This package provides macros and functions for writing state machines over racket/match patterns (as opposed to concrete characters.)
2.1 Machines
(require unstable/automata/machine) | |
package: unstable-lib |
Each of the subsequent macros compile to instances of the machines provided by this module. This is a documented feature of the modules, so these functions should be used to, for example, determine if the machine is currently accepting.
procedure
(machine-accepts? m i) → boolean?
m : machine? i : (listof any/c)
value
value
value
procedure
(machine-complement m) → machine?
m : machine?
procedure
(machine-star m) → machine?
m : machine?
procedure
(machine-union m0 m1) → machine?
m0 : machine? m1 : machine?
procedure
(machine-intersect m0 m1) → machine?
m0 : machine? m1 : machine?
procedure
(machine-seq m0 m1) → machine?
m0 : machine? m1 : machine?
procedure
(machine-seq* m0 make-m1) → machine?
m0 : machine? make-m1 : (-> machine?)
2.2 Deterministic Finite Automata
(require unstable/automata/dfa) | package: unstable-lib |
This module provides a macro for deterministic finite automata.
syntax
(dfa start (end ...) [state ([evt next-state] ...)] ...)
start : identifier?
end : identifier?
state : identifier?
next-state : identifier?
Examples: | ||||||||||||||||||||||
|
2.3 Non-Deterministic Finite Automata
(require unstable/automata/nfa) | package: unstable-lib |
This module provides a macro for non-deterministic finite automata.
syntax
(nfa (start:id ...) (end:id ...) [state:id ([evt:expr (next-state:id ...)] ...)] ...)
start : identifier?
end : identifier?
state : identifier?
next-state : identifier?
These machines are efficiently compiled to use the smallest possible bit-string as a set representation and unsafe numeric operations where appropriate for inspection and adjusting the sets.
Examples: | ||||||||||||||||||||||||||
|
2.4 Non-Deterministic Finite Automata (with epsilon transitions)
(require unstable/automata/nfa-ep) | |
package: unstable-lib |
This module provides a macro for non-deterministic finite automata with epsilon transitions.
syntax
syntax
(nfa/ep (start:id ...) (end:id ...) [state:id ([epsilon (epsilon-state:id ...)] ... [evt:expr (next-state:id ...)] ...)] ...)
start : identifier?
end : identifier?
state : identifier?
epsilon-state : identifier?
next-state : identifier?
Examples: | ||||||||||||||||||||||||||||
|
2.5 Regular Expressions
(require unstable/automata/re) | package: unstable-lib |
This module provides a macro for regular expression compilation.
syntax
(re re-pat)
re-pat = (rec id re-pat) | ,expr | (complement re-pat) | (seq re-pat ...) | (union re-pat ...) | (star re-pat) | epsilon | nullset | re-transformer | (re-transformer . datum) | (dseq pat re-pat) | pat
The interpretation of the pattern language is mostly intuitive. The pattern language may be extended with define-re-transformer. dseq allows bindings of the match pattern to be used in the rest of the regular expression. (Thus, they are not really regular expressions.) unquote escapes to Racket to evaluate an expression that evaluates to a regular expression (this happens once, at compile time.) rec binds a Racket identifier to a delayed version of the inner expression; even if the expression is initially accepting, this delayed version is never accepting.
The compiler will use an NFA, provided complement and dseq are not used. Otherwise, many NFAs connected with the machine simulation functions from unstable/automata/machine are used.
syntax
(define-re-transformer id expr)
2.5.1 Extensions
(require unstable/automata/re-ext) | |
package: unstable-lib |
This module provides a few transformers that extend the syntax of regular expression patterns.
syntax
(opt re-pat)
syntax
(plus re-pat)
syntax
(rep re-pat num)
syntax
(difference re-pat_0 re-pat_1)
syntax
(intersection re-pat_0 re-pat_1)
syntax
(seq/close re-pat ...)
2.5.2 Examples
Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|