reglibcpp
1.5.0
(Naïve) C++ implementation of models for regular languages
|
Represents deterministic finite automata. More...
#include <dfa.h>
Classes | |
class | builder |
Constructs DFAs step by step. More... | |
struct | pImpl |
Private implementation details of DFAs. More... | |
Public Member Functions | |
dfa () | |
Constructs a DFA accepting the empty language ∅. More... | |
dfa (dfa const &d) | |
Copy-constructs a DFA by copying another one's private implementation object. More... | |
dfa (dfa &&d) | |
Move-constructs a DFA by stealing another one's private implementation object. More... | |
dfa (nfa const &n) | |
Constructs a DFA from an NFA via powerset construction. More... | |
dfa (builder &b) | |
Constructs a DFA from a builder. More... | |
dfa & | operator= (const dfa &d) |
Copy-assigns this DFA by copying another one's private implementation object. More... | |
dfa & | operator= (dfa &&d) |
Move-assigns this DFA by stealing another one's private implementation object. More... | |
bool | operator== (const dfa &d) const |
Tests whether this DFA accepts exactly the same language as another one. More... | |
bool | operator!= (const dfa &d) const |
Tests whether this DFA doesn't accept the same language as another one. More... | |
size_t | delta (size_t qi, size_t si) const |
Computes this DFA's transition function for a state index and a symbol index. More... | |
size_t | delta (size_t qi, char32_t symbol) const |
Computes this DFA's transition function for a state index and a symbol. More... | |
size_t | delta (size_t qi, std::string const &utf8Symbol) const |
Same as above for a UTF-8-encoded symbol. More... | |
std::string const & | delta (std::string const &q, char32_t symbol) const |
Computes this DFA's transition function for a state label and a symbol. More... | |
std::string const & | delta (std::string const &q, std::string const &utf8Symbol) const |
Same as above for a UTF-8-encoded symbol. More... | |
size_t | deltaHat (size_t qi, std::u32string const &word) const |
Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its index. More... | |
size_t | deltaHat (size_t qi, std::string const &utf8Word) const |
Same as above for a string of UTF-8-encoded symbols. More... | |
std::string const & | deltaHat (std::string const &q, std::u32string const &word) const |
Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its name. More... | |
std::string const & | deltaHat (std::string const &q, std::string const &utf8Word) const |
Same as above for a string of UTF-8-encoded symbols. More... | |
std::u32string | getShortestWord () const |
Searches the shortest UTF-32-encoded word accepted by this DFA. More... | |
std::string | getShortestUtf8Word () const |
Same as above for a UTF-8-encoded word. More... | |
std::string const & | getLabelOf (size_t qi) const |
Puts a name to an index. More... | |
std::string const & | getInitialState () const |
Names this DFA's initial state. More... | |
std::vector< std::string > const & | getStates () const |
Fetches this DFA's set of states. More... | |
std::vector< char32_t > const & | getAlphabet () const |
Fetches this DFA's set of processable symbols. More... | |
std::vector< std::string > const & | getUtf8Alphabet () const |
Fetches this DFA's set of processable symbols as UTF-8-encoded strings. More... | |
size_t | getNumberOfStates () const |
Counts this DFA's states. More... | |
size_t | getNumberOfSymbols () const |
Counts this DFA's alphabet symbols. More... | |
bool | isAccepting (size_t qi) const |
Tests whether a state is an accept state within this DFA. More... | |
bool | isAccepting (std::string const &q) const |
Tests whether a state is an accept state within this DFA. More... | |
Static Public Member Functions | |
static dfa::builder | unite (dfa const &d1, dfa const &d2) |
Creates a builder for a DFA accepting the union of the languages of two DFAs. More... | |
static dfa::builder | intersect (dfa const &d1, dfa const &d2) |
Creates a builder for a DFA accepting the intersection of the languages of two DFAs. More... | |
static dfa::builder | subtract (dfa const &d1, dfa const &d2) |
Creates a builder for a DFA accepting the set difference of the languages of two DFAs. More... | |
static dfa::builder | complement (dfa const &d) |
Creates a builder for a DFA accepting the complement of the language of a DFA. More... | |
Represents deterministic finite automata.
Instances of this class are completely immutable. The builder class is the preferred way of constructing DFAs.
By convention, the state with index 0 is the initial state.
reg::dfa::dfa | ( | ) |
reg::dfa::dfa | ( | dfa const & | d | ) |
Copy-constructs a DFA by copying another one's private implementation object.
reg::dfa::dfa | ( | dfa && | d | ) |
Move-constructs a DFA by stealing another one's private implementation object.
The other DFA will be accepting the empty language ∅ afterwards.
reg::dfa::dfa | ( | nfa const & | n | ) |
reg::dfa::dfa | ( | dfa::builder & | b | ) |
|
static |
Creates a builder for a DFA accepting the complement of the language of a DFA.
The input DFAs' state names will be retained in the created DFA.
d | the DFA |
size_t reg::dfa::delta | ( | size_t | qi, |
size_t | si | ||
) | const |
Computes this DFA's transition function for a state index and a symbol index.
qi | the state's index (< getNumberOfStates) |
si | index of the symbol to process (< getNumberOfSymbols) |
std::out_of_range | if qi ≥ getNumberOfStates |
std::domain_error | if si ∉ getAlphabet |
Definition at line 227 of file dfa.cpp.
size_t reg::dfa::delta | ( | size_t | qi, |
char32_t | symbol | ||
) | const |
Computes this DFA's transition function for a state index and a symbol.
qi | the state's index (< getNumberOfStates) |
symbol | the symbol to process (∈ getAlphabet) |
std::out_of_range | if qi ≥ getNumberOfStates |
std::domain_error | if symbol ∉ getAlphabet |
Definition at line 245 of file dfa.cpp.
size_t reg::dfa::delta | ( | size_t | qi, |
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 254 of file dfa.cpp.
string const & reg::dfa::delta | ( | std::string const & | q, |
char32_t | symbol | ||
) | const |
Computes this DFA's transition function for a state label and a symbol.
q | the state's label (∈ getStates) |
symbol | the symbol to process (∈ getAlphabet) |
std::out_of_range | if q ∉ getStates |
std::domain_error | if symbol ∉ getAlphabet |
Definition at line 266 of file dfa.cpp.
string const & reg::dfa::delta | ( | std::string const & | 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 275 of file dfa.cpp.
size_t reg::dfa::deltaHat | ( | size_t | qi, |
std::u32string const & | word | ||
) | const |
Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its index.
qi | the starting state's index (< getNumberOfStates) |
word | the string of symbols to process (all of which ∈ getAlphabet) |
std::out_of_range | if qi ≥ getNumberOfStates |
std::domain_error | if one of the word symbols ∉ getAlphabet |
Definition at line 287 of file dfa.cpp.
size_t reg::dfa::deltaHat | ( | size_t | q, |
std::string const & | utf8Word | ||
) | const |
Same as above for a string of UTF-8-encoded 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 295 of file dfa.cpp.
string const & reg::dfa::deltaHat | ( | std::string const & | q, |
std::u32string const & | word | ||
) | const |
Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its name.
q | the starting state's label (∈ getStates) |
word | the string of symbols to process (all of which ∈ getAlphabet) |
std::out_of_range | if q ∉ getStates |
std::domain_error | if one of the word symbols ∉ getAlphabet |
Definition at line 307 of file dfa.cpp.
string const & reg::dfa::deltaHat | ( | std::string const & | q, |
std::string const & | utf8Word | ||
) | const |
Same as above for a string of UTF-8-encoded 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 312 of file dfa.cpp.
vector< char32_t > const & reg::dfa::getAlphabet | ( | ) | const |
string const & reg::dfa::getInitialState | ( | ) | const |
Names this DFA's initial state.
Definition at line 365 of file dfa.cpp.
string const & reg::dfa::getLabelOf | ( | size_t | q | ) | const |
Puts a name to an index.
q | the state's index (< getNumberOfStates) |
std::out_of_range | if q ≥ getNumberOfStates |
Definition at line 357 of file dfa.cpp.
size_t reg::dfa::getNumberOfStates | ( | ) | const |
Counts this DFA's states.
Definition at line 397 of file dfa.cpp.
size_t reg::dfa::getNumberOfSymbols | ( | ) | const |
Counts this DFA's alphabet symbols.
Definition at line 405 of file dfa.cpp.
string reg::dfa::getShortestUtf8Word | ( | ) | const |
Same as above for a UTF-8-encoded word.
Definition at line 347 of file dfa.cpp.
u32string reg::dfa::getShortestWord | ( | ) | const |
Searches the shortest UTF-32-encoded word accepted by this DFA.
std::logic_error | if the DFA doesn't accept any words |
Definition at line 321 of file dfa.cpp.
|
static |
Creates a builder for a DFA accepting the intersection of the languages of two DFAs.
The input DFAs' state names will be concatenated and collisions resolved by appending _
in the created DFA.
d1 | the first DFA |
d2 | the other DFA |
bool reg::dfa::isAccepting | ( | size_t | qi | ) | const |
Tests whether a state is an accept state within this DFA.
qi | the state's index (< getNumberOfStates) |
true
if the state is in the set of accept states, false
else std::out_of_range | if qi ≥ getNumberOfStates |
Definition at line 415 of file dfa.cpp.
bool reg::dfa::isAccepting | ( | std::string const & | q | ) | const |
Tests whether a state is an accept state within this DFA.
q | the state's label (∈ getStates) |
true
if the state is in the set of accept states, false
else std::out_of_range | if q ∉ getStates |
Definition at line 428 of file dfa.cpp.
bool reg::dfa::operator!= | ( | const dfa & | d | ) | const |
Tests whether this DFA doesn't accept the same language as another one.
Definition at line 217 of file dfa.cpp.
Copy-assigns this DFA by copying another one's private implementation object.
Move-assigns this DFA by stealing another one's private implementation object.
The other DFA will be accepting the empty language ∅ afterwards.
bool reg::dfa::operator== | ( | const dfa & | d | ) | const |
Tests whether this DFA accepts exactly the same language as another one.
More specifically, checks whether this DFA's initial state is indistinguishable from the other one's.
Definition at line 173 of file dfa.cpp.
|
static |
Creates a builder for a DFA accepting the set difference of the languages of two DFAs.
The input DFAs' state names will be concatenated and collisions resolved by appending _
in the created DFA.
d1 | the first DFA |
d2 | the other DFA |
|
static |
Creates a builder for a DFA accepting the union of the languages of two DFAs.
The input DFAs' state names will be concatenated and collisions resolved by appending _
in the created DFA.
d1 | the first DFA |
d2 | the other DFA |