The final state of the ENFA.
This state may not be reachable from the initial state.
The initial state of the ENFA.
Readonly
maxThe maximum character that is part of the alphabet of the words that this FA can accept.
Returns whether this FA accepts the empty language meaning that it doesn't accept any words.
Returns whether the formal language accepted by this FA contains finitely many words.
Note: Finite does not mean that all words can be iterated in practice. E.g. the set of all Unicode words with 10 or less characters contains 2.6e54 many words and can be accepted by a DFA with only 11 states.
Whether this ENFA is in its normal form.
Modifies this ENFA to accept the concatenation of this ENFA and the given FA.
Modifies this ENFA to accept the concatenation of this ENFA and the other ENFA.
This operation is implemented by moving (not copying) the states from the other ENFA into this ENFA. The other ENFA will be in an invalid state after this operation completes. The initial and final states of the other ENFA will be random nodes of this ENFA. Makes sure that you never use the other ENFA again.
This operation will create at most 4 nodes with the given factory.
Create a mutable copy of this ENFA.
Returns the number of nodes reachable from the initial state including the initial state.
This returns the number of nodes returned by nodes.
Yields all nodes reachable from the initial state including the initial state.
This may include trap states, but it will not include the final states if it is unreachable from the initial state.
The order in which nodes will be returned is implementation defined and may change after any operation that modifies the ENFA.
Modifying the ENFA while iterating will result in implementation-defined behavior. The implementation may stop the iteration or yield an nodes.
This operation runs in O(E + V) where E is the number of nodes reachable from the initial state and V is the number of transitions.
Brings this ENFA is in its normal form.
This operation will create at most 2 nodes with the given factory.
Modifies this ENFA such that all prefixes of all accepted words are also accepted.
If the language of this ENFA is empty, then it will remain empty.
Unreachable states will be removed by this operation.
Modifies this ENFA to accept the concatenation of the given FA and this ENFA.
Modifies this ENFA to accept the concatenation of the other ENFA and this ENFA.
This operation is implemented by moving (not copying) the states from the other ENFA into this ENFA. The other ENFA will be in an invalid state after this operation completes. The initial and final states of the other ENFA will be random nodes of this ENFA. Makes sure that you never use the other ENFA again.
This operation will create at most 4 nodes with the given factory.
Modifies this ENFA to accept at least min
and at most max
concatenations of itself.
Both min
and max
both have to be non-negative integers with min <= max
.
max
is also allowed to be Infinity
.
Modifies this ENFA such that all suffixes of all accepted words are also accepted.
If the language of this ENFA is empty, then it will remain empty.
Unreachable states will be removed by this operation.
Returns whether this FA accepts the given word.
The characters of the word to test.
Returns the string representation of this FA in the DOT format.
The output of this function can passed to any graph visualization program. This can be a local installation or an online editor.
By default, toUnicodeString is used to represent CharSets. It's possible to provide a
custom stringify function using the charSetToString
parameter.
Returns the string representation of this FA in the Mermaid format.
By default, toUnicodeString is used to represent CharSets. It's possible to provide a
custom stringify function using the charSetToString
parameter.
Returns the AST of a regular expression that accepts the same language as this FA.
Optional
options: Readonly<ToRegexOptions>Modifies this ENFA to accept the language of this ENFA and the language of the given FA.
If the union kind is left
, then this ENFA will be modified to accept <other>|<this>
. Otherwise, it will be
modified to accept <this>|<other>
.
Modifies this ENFA to accept the language of this ENFA and the language of the other ENFA.
If the union kind is left
, then this ENFA will be modified to accept <other>|<this>
. Otherwise, it will be
modified to accept <this>|<other>
.
This operation is implemented by moving (not copying) the states from the other ENFA into this ENFA. The other ENFA will be in an invalid state after this operation completes. The initial and final states of the other ENFA will be random nodes of this ENFA. Makes sure that you never use the other ENFA again.
This operation will create at most 6 nodes with the given factory.
Removes the empty word from the accepted languages of this ENFA.
Unreachable states will be removed by this operation.
Returns an iterable that will yield all word sets accepted by this FA. Word sets are yielded by ascending length.
If this FA accepts infinitely many words, the iterable will never end. If this FA is finite, the iterable will
end after at most 2^O(n)
word sets (n
= number of states).
If you analyse the words of an FA, consider using this method instead of words
. If this method yields k
word
sets, then words
will yield up to O(k * m ^ l)
words (m
= number of possible characters, l
= the maximum
length of any of the k
word sets).
Static
allStatic
emptyCreates a new ENFA which matches no words. The language of the returned ENFA is empty.
This operation will create exactly 2 nodes with the given factory.
Static
emptyCreates a new ENFA which matches only the empty word.
This operation will create exactly 1 node with the given factory.
Static
fromStatic
fromCreates a new ENFA which matches the given characters.
This operation will create exactly 2 nodes with the given factory.
Static
fromFAOptional
factory: NodeFactory<ENFA.Node>Static
fromOptional
creationOptions: Readonly<ENFA.FromRegexOptions>Optional
factory: NodeFactory<ENFA.Node>Optional
creationOptions: Readonly<ENFA.FromRegexOptions>Optional
factory: NodeFactory<ENFA.Node>Static
fromStatic
fromCreates a new ENFA which matches all and only all of the given word sets.
Static
fromCreates a new ENFA which matches all and only all of the given words.
A nondeterministic finite automaton with epsilon transitions.
This class implements NFAs with the following properties:
There is exactly one initial state.
There is exactly one final state.
There are epsilon transitions.
A transitions either an epsilon transition or consumes a character.
Epsilon transition are represented using
null
and characters are represented using non-emptyCharSet
s.Transitions are ordered.
As a consequence,
/aa|bb/
and/bb|aa/
have different state machines in this NFA implementation.Order is only guaranteed as long as no transitions are removed. Order is defined by the key order of the JavaScript
Map
class.Between any two states, there can at most be one transition.
Unlike the NFA class, transition cannot be merged. As a consequence,
/a|a/
and/a/
have different state machines in this NFA implementation.Normal form
The normal form of this ENFA implementation has the following restriction:
Non-normalized ENFAs will either be tolerated or normalized by operations.