reglibcpp
1.0.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 & | 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::string const & | getLabelOf (size_t q) const |
Puts a name to an index. More... | |
std::string | getLabelOf (std::valarray< bool > 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... | |
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.
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 106 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 129 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 140 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 147 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 158 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 175 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 185 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 220 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 > | 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 246 of file nfa.cpp.
size_t reg::nfa::getNumberOfStates | ( | ) | const |
vector< string > const & reg::nfa::getUtf8Alphabet | ( | ) | const |
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 |