reglibcpp
1.3.0
(Naïve) C++ implementation of models for regular languages
|
Constructs DFAs step by step. More...
#include <dfa.h>
Classes | |
struct | pImpl |
Private implementation details of DFA builders. More... | |
Public Member Functions | |
builder () | |
Constructs a blank builder object. More... | |
builder (dfa const &dfa) | |
Constructs a builder object with exactly the same states, symbols, transitions, initial state and accept states as a given DFA. More... | |
builder (nfa const &nfa) | |
Constructs a builder object with exactly the same states, symbols, transitions, initial state and accept states as a DFA resulting from a powerset construction. More... | |
builder (builder const &b) | |
Copy-constructs a builder by copying another one's private implementation object. More... | |
builder (builder &&b) | |
Move-constructs a builder by stealing another one's private implementation object. More... | |
builder & | operator= (const builder &b) |
Copy-assigns a builder by copying another one's private implementation object. More... | |
builder & | operator= (builder &&b) |
Move-assigns a builder by stealing another one's private implementation object. More... | |
builder & | addSymbol (char32_t symbol) |
Adds a symbol to the prospective DFA's alphabet. More... | |
builder & | addSymbol (std::string const &utf8Symbol) |
Same as above for a a UTF-8-encoded symbol. More... | |
builder & | setAccepting (std::string const &state, bool accept) |
Sets whether or not a state will be accepting within the prospective DFA. More... | |
builder & | makeInitial (std::string const &state) |
Resets the initial state for the prospective DFA. More... | |
builder & | defineTransition (std::string const &from, std::string const &to, char32_t symbol) |
(Re-)Defines a transition for the prospective DFA. More... | |
builder & | defineTransition (std::string const &from, std::string const &to, std::string const &utf8Symbol) |
Same as above for a UTF-8-encoded symbol. More... | |
builder & | merge () |
Merges the prospective DFA's indistinguishable states, allowing for minimization. More... | |
builder & | purge () |
Purges the prospective DFA of unreachable and non-producing states, allowing for minimization. More... | |
builder & | minimize () |
Convenience method for chaining purge and merge to achieve proper minimization. More... | |
builder & | unite (dfa const &other) |
Makes the prospective DFA also accept every word of another DFA's language. More... | |
builder & | intersect (dfa const &other) |
Makes the prospective DFA accept only words accepted also by another DFA. More... | |
builder & | complement () |
Inverts the prospective DFA's language with respect to all possible strings over its alphabet. More... | |
builder & | normalizeStateNames (std::string const &prefix) |
Reduces the prospective NFA's state names to consecutive numbers, prefixed with a given string. More... | |
dfa | build () |
Builds the DFA, as defined by previous operations, including completion. More... | |
Constructs DFAs step by step.
Any mention of a symbol or state will add them to the alphabet/set of states. The first state mentioned will be designated initial state.
reg::dfa::builder::builder | ( | ) |
reg::dfa::builder::builder | ( | dfa const & | dfa | ) |
Constructs a builder object with exactly the same states, symbols, transitions, initial state and accept states as a given DFA.
Definition at line 503 of file dfa.cpp.
reg::dfa::builder::builder | ( | nfa const & | nfa | ) |
Constructs a builder object with exactly the same states, symbols, transitions, initial state and accept states as a DFA resulting from a powerset construction.
Definition at line 518 of file dfa.cpp.
reg::dfa::builder::builder | ( | builder const & | b | ) |
Copy-constructs a builder by copying another one's private implementation object.
reg::dfa::builder::builder | ( | builder && | b | ) |
Move-constructs a builder by stealing another one's private implementation object.
The other builder will be blank afterwards.
dfa::builder & reg::dfa::builder::addSymbol | ( | char32_t | symbol | ) |
dfa::builder & reg::dfa::builder::addSymbol | ( | std::string const & | utf8Symbol | ) |
Same as above for a 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 593 of file dfa.cpp.
dfa reg::dfa::builder::build | ( | ) |
Builds the DFA, as defined by previous operations, including completion.
Definition at line 964 of file dfa.cpp.
dfa::builder & reg::dfa::builder::complement | ( | ) |
Inverts the prospective DFA's language with respect to all possible strings over its alphabet.
dfa::builder & reg::dfa::builder::defineTransition | ( | std::string const & | from, |
std::string const & | to, | ||
char32_t | symbol | ||
) |
(Re-)Defines a transition for the prospective DFA.
If there's already a transition defined from from
to to
, it will be redefined with the new symbol
.
from | the starting state for the transition |
to | the destination state for the transition |
symbol | the symbol triggering the transition |
Definition at line 637 of file dfa.cpp.
dfa::builder & reg::dfa::builder::defineTransition | ( | std::string const & | from, |
std::string const & | to, | ||
std::string const & | utf8Symbol | ||
) |
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 648 of file dfa.cpp.
dfa::builder & reg::dfa::builder::intersect | ( | dfa const & | other | ) |
Makes the prospective DFA accept only words accepted also by another DFA.
Concatenates the names of states defined so far with the other DFA's state names and resolves conflicts by appending _
.
other | the NFA whose language should also be accepted |
Definition at line 862 of file dfa.cpp.
dfa::builder & reg::dfa::builder::makeInitial | ( | std::string const & | state | ) |
dfa::builder & reg::dfa::builder::merge | ( | ) |
Merges the prospective DFA's indistinguishable states, allowing for minimization.
This method doesn't change the prospective DFA's accepted language, but it will be built with the minimum of reachable states to fulfill that purpose. Unreachable states will be merged since they are indistinguishable, but they won't be removed, hence preventing true minimization; that's what purge is for.
Definition at line 662 of file dfa.cpp.
dfa::builder & reg::dfa::builder::minimize | ( | ) |
Convenience method for chaining purge and merge to achieve proper minimization.
Definition at line 773 of file dfa.cpp.
dfa::builder & reg::dfa::builder::normalizeStateNames | ( | std::string const & | prefix | ) |
Reduces the prospective NFA's state names to consecutive numbers, prefixed with a given string.
Definition at line 930 of file dfa.cpp.
dfa::builder & reg::dfa::builder::operator= | ( | const builder & | b | ) |
Copy-assigns a builder by copying another one's private implementation object.
dfa::builder & reg::dfa::builder::operator= | ( | dfa::builder && | b | ) |
Move-assigns a builder by stealing another one's private implementation object.
The other builder will be blank afterwards.
dfa::builder & reg::dfa::builder::purge | ( | ) |
Purges the prospective DFA of unreachable and non-producing states, allowing for minimization.
This method doesn't change the prospective DFA's accepted language, but it will be built without states that will never be reached.
Definition at line 714 of file dfa.cpp.
dfa::builder & reg::dfa::builder::setAccepting | ( | std::string const & | state, |
bool | accept | ||
) |
Sets whether or not a state will be accepting within the prospective DFA.
state | the state's name |
accept | true if the state should be an accept state afterwards, false else |
dfa::builder & reg::dfa::builder::unite | ( | dfa const & | other | ) |
Makes the prospective DFA also accept every word of another DFA's language.
Concatenates the names of states defined so far with the other DFA's state names and resolves conflicts by appending _
.
other | the DFA whose language should also be accepted |
Definition at line 784 of file dfa.cpp.