reglibcpp
1.0.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 &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... | |
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 440 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 460 of file dfa.cpp.
reg::dfa::builder::builder | ( | builder & | 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 541 of file dfa.cpp.
dfa reg::dfa::builder::build | ( | ) |
Builds the DFA, as defined by previous operations, including completion.
Definition at line 726 of file dfa.cpp.
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 587 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 598 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 611 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 663 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 |