reglibcpp
1.3.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 q, char32_t symbol) const |
Computes this DFA's transition function for a state and a symbol. More... | |
size_t | delta (size_t q, std::string const &utf8Symbol) const |
Same as above for a UTF-8-encoded symbol. More... | |
size_t | deltaHat (size_t q, std::u32string const &word) const |
Computes this DFA's transition function recursively for a string of symbols, starting in a specified state. More... | |
size_t | deltaHat (size_t 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, INCLUDING POTENTIAL INFINITE LOOP. More... | |
std::string const & | getLabelOf (size_t q) const |
Puts a name to an index. 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... | |
bool | isAccepting (size_t 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.
n | the DFA |
size_t reg::dfa::delta | ( | size_t | q, |
char32_t | symbol | ||
) | const |
Computes this DFA's transition function for a state and a symbol.
q | the state's index (< getNumberOfStates) |
symbol | the symbol to process (∈ getAlphabet) |
Definition at line 203 of file dfa.cpp.
size_t reg::dfa::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 219 of file dfa.cpp.
size_t reg::dfa::deltaHat | ( | size_t | q, |
std::u32string const & | word | ||
) | const |
Computes this DFA'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) |
Definition at line 229 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 237 of file dfa.cpp.
vector< char32_t > const & reg::dfa::getAlphabet | ( | ) | const |
string const & reg::dfa::getLabelOf | ( | size_t | q | ) | const |
Puts a name to an index.
q | the state's index (< getNumberOfStates) |
size_t reg::dfa::getNumberOfStates | ( | ) | const |
string reg::dfa::getShortestUtf8Word | ( | ) | const |
Same as above for a UTF-8-encoded word, INCLUDING POTENTIAL INFINITE LOOP.
Definition at line 277 of file dfa.cpp.
u32string reg::dfa::getShortestWord | ( | ) | const |
Searches the shortest UTF-32-encoded word accepted by this DFA.
LOOPS INFINITELY FOR DFA WITH AN EMPTY LANGUAGE!
Hint: Compare with the empty-language dfa() before using this method:
dfa empty(); if (myDfa != empty) { myDfa.getShortestWord(); }
Definition at line 254 of file dfa.cpp.
vector< string > const & reg::dfa::getUtf8Alphabet | ( | ) | const |
|
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 | q | ) | const |
Tests whether a state is an accept state within this DFA.
q | the state's index (< getNumberOfStates) |
true
if the state is in the set of accept states, false
else bool reg::dfa::operator!= | ( | const dfa & | d | ) | const |
Tests whether this DFA doesn't accept the same language as another one.
Definition at line 195 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 151 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 |