reglibcpp
1.3.0
(Naïve) C++ implementation of models for regular languages
|
Represents nondeterministic finite automata with ε-moves. More...
#include <nfa.h>
Classes | |
class | builder |
Constructs NFAs step by step. More... | |
struct | pImpl |
Private implementation details of NFAs. More... | |
Public Member Functions | |
nfa () | |
Constructs an NFA accepting the empty language ∅. More... | |
nfa (nfa const &n) | |
Copy-constructs an NFA by copying another one's private implementation object. More... | |
nfa (nfa &&n) | |
Move-constructs an NFA by stealing another one's private implementation object. More... | |
nfa (dfa const &d) | |
Constructs an NFA from a DFA. More... | |
nfa (builder &b) | |
Constructs an NFA from a builder. More... | |
nfa & | operator= (nfa const &n) |
Copy-assigns this NFA by copying another one's private implementation object. More... | |
nfa & | operator= (nfa &&n) |
Move-assigns this NFA by stealing another one's private implementation object. More... | |
bool | operator== (nfa const &n) const |
Tests whether this NFA accepts exactly the same language as another one. More... | |
bool | operator!= (nfa const &n) const |
Tests whether this NFA doesn't accept the same language as another one. More... | |
std::valarray< bool > const & | delta (size_t q, char32_t symbol) const |
Computes this NFA's transition function for a state and a symbol. More... | |
std::valarray< bool > const & | delta (size_t q, std::string const &utf8Symbol) const |
Same as above for a UTF-8-encoded symbol. More... | |
std::valarray< bool > | deltaHat (size_t q, std::u32string const &word) const |
Computes this NFA's transition function recursively for a string of symbols, starting in a specified state. More... | |
std::valarray< bool > | deltaHat (size_t q, std::string const &utf8Word) const |
Same as above for a UTF-8-encoded string of symbols. More... | |
std::valarray< bool > | deltaHat (std::valarray< bool > const &qs, std::u32string const &word) const |
Computes this NFA's transition function recursively for a string of symbols, starting in multiple specified states. More... | |
std::valarray< bool > | deltaHat (std::valarray< bool > const &qs, std::string const &utf8Word) const |
Same as above for a UTF-8-encoded string of symbols. More... | |
std::valarray< bool > const & | epsilonClosure (size_t q) const |
Computes a state's ε-closure. More... | |
std::valarray< bool > | epsilonClosure (std::valarray< bool > const &qs) const |
Computes the union of multiple states' ε-closures. More... | |
std::u32string | getShortestWord () const |
Searches the shortest UTF-32-encoded word accepted by this NFA. More... | |
std::string | getShortestUtf8Word () const |
Same as above for a UTF-8-encoded word, INCLUDING POTENTIAL INFINITE LOOP. More... | |
std::string const & | getLabelOf (size_t q) const |
Puts a name to an index. More... | |
std::string | getLabelOf (std::valarray< bool > const &qs) const |
Puts a name to a set of indices. More... | |
std::vector< char32_t > const & | getAlphabet () const |
Fetches this NFA's set of processable symbols. More... | |
std::vector< std::string > const & | getUtf8Alphabet () const |
Fetches this NFA's set of processable symbols as UTF-8-encoded strings. More... | |
size_t | getNumberOfStates () const |
Counts this NFA's states. More... | |
bool | isAccepting (size_t q) const |
Tests whether a state is an accept state within this NFA. More... | |
bool | hasAccepting (std::valarray< bool > const &qs) const |
Tests whether a set of states contains an accept state within this NFA. More... | |
Static Public Member Functions | |
static nfa::builder | unite (nfa const &n1, nfa const &n2) |
Creates a builder for an NFA accepting the union of the languages of two NFAs. More... | |
static nfa::builder | intersect (nfa const &n1, nfa const &n2) |
Creates a builder for an NFA accepting the intersection of the languages of two NFAs. More... | |
static nfa::builder | subtract (nfa const &n1, nfa const &n2) |
Creates a builder for an NFA accepting the set difference of the languages of two NFAs. More... | |
static nfa::builder | complement (nfa const &n) |
Creates a builder for an NFA accepting the complement of the language of an NFA. More... | |
Represents nondeterministic finite automata with ε-moves.
Instances of this class are completely immutable. The builder class is the preferred way of constructing NFAs.
By convention, the state with index 0 is the initial state.
reg::nfa::nfa | ( | ) |
reg::nfa::nfa | ( | nfa const & | n | ) |
Copy-constructs an NFA by copying another one's private implementation object.
reg::nfa::nfa | ( | nfa && | n | ) |
Move-constructs an NFA by stealing another one's private implementation object.
The other NFA will be accepting the empty language ∅ afterwards.
reg::nfa::nfa | ( | dfa const & | d | ) |
reg::nfa::nfa | ( | nfa::builder & | b | ) |
|
static |
Creates a builder for an NFA accepting the complement of the language of an NFA.
The input NFAs' state names will probably be mangled in the created NFA.
n | the NFA |
Definition at line 390 of file nfa.cpp.
valarray< bool > const & reg::nfa::delta | ( | size_t | q, |
char32_t | symbol | ||
) | const |
Computes this NFA's transition function for a state and a symbol.
q | the state's index (< getNumberOfStates) |
symbol | the symbol to process (∈ getAlphabet) |
true
at reached states' indices Definition at line 102 of file nfa.cpp.
valarray< bool > const & reg::nfa::delta | ( | size_t | q, |
std::string const & | utf8Symbol | ||
) | const |
Same as above for a UTF-8-encoded symbol.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 122 of file nfa.cpp.
valarray< bool > reg::nfa::deltaHat | ( | size_t | q, |
std::u32string const & | word | ||
) | const |
Computes this NFA's transition function recursively for a string of symbols, starting in a specified state.
q | the starting state's index (< getNumberOfStates) |
word | the string of symbols to process (all of which ∈ getAlphabet) |
true
at reached states' indices Definition at line 132 of file nfa.cpp.
valarray< bool > reg::nfa::deltaHat | ( | size_t | q, |
std::string const & | utf8Word | ||
) | const |
Same as above for a UTF-8-encoded string of symbols.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 139 of file nfa.cpp.
valarray< bool > reg::nfa::deltaHat | ( | std::valarray< bool > const & | qs, |
std::u32string const & | word | ||
) | const |
Computes this NFA's transition function recursively for a string of symbols, starting in multiple specified states.
qs | valarray with true at starting states' indices (the size of which == getNumberOfStates) |
word | the string of symbols to process (all of which ∈ getAlphabet) |
true
at reached states' indices Definition at line 149 of file nfa.cpp.
valarray< bool > reg::nfa::deltaHat | ( | std::valarray< bool > const & | qs, |
std::string const & | utf8Word | ||
) | const |
Same as above for a UTF-8-encoded string of symbols.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 166 of file nfa.cpp.
valarray< bool > const & reg::nfa::epsilonClosure | ( | size_t | q | ) | const |
Computes a state's ε-closure.
q | the state's index (< getNumberOfStates) |
true
at indices of states reachable without actual inputs Definition at line 217 of file nfa.cpp.
valarray< bool > reg::nfa::epsilonClosure | ( | std::valarray< bool > const & | qs | ) | const |
Computes the union of multiple states' ε-closures.
qs | valarray with true at indices of states in question (the size of which == getNumberOfStates) |
true
at indices of states reachable without actual inputs Definition at line 251 of file nfa.cpp.
vector< char32_t > const & reg::nfa::getAlphabet | ( | ) | const |
string const & reg::nfa::getLabelOf | ( | size_t | q | ) | const |
Puts a name to an index.
q | the state's index (< getNumberOfStates) |
string reg::nfa::getLabelOf | ( | std::valarray< bool > const & | qs | ) | const |
Puts a name to a set of indices.
qs | valarray with true at indices of states in question (the size of which == getNumberOfStates) |
Definition at line 277 of file nfa.cpp.
size_t reg::nfa::getNumberOfStates | ( | ) | const |
string reg::nfa::getShortestUtf8Word | ( | ) | const |
Same as above for a UTF-8-encoded word, INCLUDING POTENTIAL INFINITE LOOP.
Definition at line 208 of file nfa.cpp.
u32string reg::nfa::getShortestWord | ( | ) | const |
Searches the shortest UTF-32-encoded word accepted by this NFA.
LOOPS INFINITELY FOR NFA WITH AN EMPTY LANGUAGE!
Hint: Compare with the empty-language nfa() before using this method:
nfa empty(); if (myNfa != empty) { myNfa.getShortestWord(); }
Definition at line 183 of file nfa.cpp.
vector< string > const & reg::nfa::getUtf8Alphabet | ( | ) | const |
bool reg::nfa::hasAccepting | ( | std::valarray< bool > const & | qs | ) | const |
Tests whether a set of states contains an accept state within this NFA.
qs | valarray with true at indices of states in question (the size of which == getNumberOfStates) |
true
if the set of states contains an accept states, false
else Definition at line 332 of file nfa.cpp.
|
static |
Creates a builder for an NFA accepting the intersection of the languages of two NFAs.
The input NFAs' state names will be concatenated and collisions resolved by appending _
in the created NFA.
n1 | the first NFA |
n2 | the other NFA |
bool reg::nfa::isAccepting | ( | size_t | q | ) | const |
Tests whether a state is an accept state within this NFA.
q | the state's index (< getNumberOfStates) |
true
if the state is in the set of accept states, false
else bool reg::nfa::operator!= | ( | nfa const & | n | ) | const |
Copy-assigns this NFA by copying another one's private implementation object.
Move-assigns this NFA by stealing another one's private implementation object.
The other NFA will be accepting the empty language ∅ afterwards.
bool reg::nfa::operator== | ( | nfa const & | n | ) | const |
|
static |
Creates a builder for an NFA accepting the set difference of the languages of two NFAs.
The input NFAs' state names will probably be mangled in the created NFA.
n1 | the first NFA |
n2 | the other NFA |
|
static |
Creates a builder for an NFA accepting the union of the languages of two NFAs.
The input NFAs' state names will be prepended with either 1
or 2
in the created NFA.
n1 | the first NFA |
n2 | the other NFA |