Class invariants:
If the states or transitions are manipulated manually, the {@link #restoreInvariant()}and {@link #setDeterministic(boolean)} methods should be used afterwards to restore representation invariants that are assumed by the built-in automata operations. @author Anders Møller <amoeller@cs.au.dk>
Class invariants:
If the states or transitions are manipulated manually, the {@link #restoreInvariant()} and {@link #setDeterministic(boolean)} methodsshould be used afterwards to restore representation invariants that are assumed by the built-in automata operations.
Note: This class has internal mutable state and is not thread safe. It is the caller's responsibility to ensure any necessary synchronization if you wish to use the same Automaton from multiple threads. In general it is instead recommended to use a {@link RunAutomaton} for multithreaded matching: it is immutable, thread safe, and much faster.
@lucene.experimentalIn this simple language, we can express types such as the following:
Not(Or{Int,Bool})
--- the set of values excluding the integers and booleansAnd{Int,Bool}
--- the set of values in both the integers and booleans (i.e. the empty set).Not(Void)
--- this corresponds to an automaton with two states: 1) a term with no child representing Void
; 2) a term representing Not
which has a single child referring to state 1.Or{Int,Bool}
--- corresponds to an automaton with four states: 1) a term with no child representing Int
; 2) a term with no child representing Bool
; 3) a set with two children referring to states 1 and 2; 4) a term representing Or
with a single child referring to state 3.Roots. States can be explicitly marked as roots to provide a way to track them through the various operations that might be performed on an automaton. In particular, as states are rewritten, the roots will be updated accordingly.
Minimisation. An automaton which has the strong equivalence property is said to be minimised. Automata are generally kept in the minimised form, and only use of the set()
method can break this. The strong equivalence property guarantees that there are no two distinct, but equivalent states. In order to restore this property, the minimise()
function must be called explicitly.
Compaction. An automaton which does not contain garbage states is said to be compacted. Automata are generally kept in compacted form, and only use of the set()
method can break this. Garbage states are those not reachable from any marked root state. In order to restore this property, the compact()
function must be called explicitly.
Canonical Form. An automaton which is minimised is not guaranteed to be canonical. This means we can have automata which are effectively equivalent, but which not considered identical (i.e., where equals()
returns false). In some circumstance, it is desirable to move an automaton into canonical form, and this can be achieved with the canonicalise()
function.
Virtual States. In the internal representation of automata, leaf states may be not be represented as actual states. This will occur if the leaf node does not include any supplementary data, and is primarily for space and performance optimisation. In such case, the node is represented as a child node using a negative index.
A finite-state automaton for representing Whiley types. This is a machine for accepting matching inputs of a given language. An automaton is a directed graph whose nodes and edges are referred to as states and transitions. Each state has a "kind" which determines how the state behaves on given inputs. For example, a state with "OR" kind might accept an input if either of its children does; in contrast, and state of "AND" kind might accept an input only if all its children does.
The organisation of children is done according to two approaches: deterministic and non-deterministic. In the deterministic approach, the ordering of children is important; in the non-deterministic approach, the ordering of children is not important. A flag is used to indicate whether a state is deterministic or not.
Aside from having a particular kind, each state may also have supplementary material. This can be used, for example, to effectively provide labelled transitions. Another use of this might be to store a given string which must be matched.
NOTE: In the internal representation of automata, leaf states may be not be represented as actual nodes. This will occur if the leaf node does not include any supplementary data, and is primarily for space and performance optimisation. In such case, the node is represented as a child node using a negative index.
@author David J. Pearce
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|