reglibcpp  1.5.0
(Naïve) C++ implementation of models for regular languages
Public Member Functions | Public Attributes | List of all members
reg::dfa::builder::pImpl Struct Reference

Private implementation details of DFA builders. More...

Public Member Functions

 pImpl ()=default
 Constructs empty private implementation object. More...
 
 pImpl (string &initial, unordered_set< char32_t > &alphabet, unordered_set< string > &acceptingStates, Dtransitionmap &transitions)
 Constructs private implementation object with provided members. More...
 
bool isTrashState (string const &q) const
 Tests whether all of a state's outgoing transitions point to itself. More...
 
string const & generateNewState ()
 Generates a uniquely named new state and adds it to the set of states. More...
 
void complete ()
 Totalizes a partial transition function by pointing any undefined transitions towards a trash state. More...
 

Public Attributes

string initial
 Name of the prospective DFA's initial state. More...
 
unordered_set< char32_t > alphabet
 Set of symbols processable by the prospective DFA. More...
 
unordered_set< stringacceptingStates
 Set of names of the prospective DFA's accept states. More...
 
Dtransitionmap transitions
 Transition function (state × symbol → state) of the prospective DFA. More...
 

Detailed Description

Private implementation details of DFA builders.

Definition at line 507 of file dfa.cpp.

Constructor & Destructor Documentation

◆ pImpl() [1/2]

reg::dfa::builder::pImpl::pImpl ( )
default

Constructs empty private implementation object.

◆ pImpl() [2/2]

reg::dfa::builder::pImpl::pImpl ( string initial,
unordered_set< char32_t > &  alphabet,
unordered_set< string > &  acceptingStates,
Dtransitionmap transitions 
)
inline

Constructs private implementation object with provided members.

Definition at line 519 of file dfa.cpp.

524  : initial(move(initial)),
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:511
unordered_set< char32_t > alphabet
Set of symbols processable by the prospective DFA.
Definition: dfa.cpp:509
T move(T... args)
string initial
Name of the prospective DFA&#39;s initial state.
Definition: dfa.cpp:508
unordered_set< string > acceptingStates
Set of names of the prospective DFA&#39;s accept states.
Definition: dfa.cpp:510

Member Function Documentation

◆ complete()

void reg::dfa::builder::pImpl::complete ( )
inline

Totalizes a partial transition function by pointing any undefined transitions towards a trash state.

If there is no state satisfying trashiness, a new one will be generated.

Definition at line 559 of file dfa.cpp.

559  {
560  bool trashUsed(false);
561  string const& trashState = [&]{
562  for (auto const& entry : this->transitions) {
563  if (this->isTrashState(entry.first)) {
564  trashUsed = true;
565  return entry.first;
566  }
567  }
568  return this->generateNewState();
569  }();
570  for (auto& from : transitions) {
571  for (char32_t symbol : alphabet) {
572  if (from.second.find(symbol) == from.second.end()) {
573  from.second[symbol] = trashState;
574  trashUsed |= (from.first != trashState);
575  }
576  }
577  }
578  if (!trashUsed) {
579  transitions.erase(trashState);
580  }
581  }
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:511
bool isTrashState(string const &q) const
Tests whether all of a state's outgoing transitions point to itself.
Definition: dfa.cpp:530
unordered_set< char32_t > alphabet
Set of symbols processable by the prospective DFA.
Definition: dfa.cpp:509
string const & generateNewState()
Generates a uniquely named new state and adds it to the set of states.
Definition: dfa.cpp:545

◆ generateNewState()

string const& reg::dfa::builder::pImpl::generateNewState ( )
inline

Generates a uniquely named new state and adds it to the set of states.

Definition at line 545 of file dfa.cpp.

545  {
546  size_t q(0);
547  string newState;
548  while (transitions.find(newState = "q" + to_string(q)) != transitions.end()) {
549  q++;
550  }
551  if (transitions.empty()) {
552  initial = newState;
553  }
554  return transitions.insert(std::make_pair(newState, unordered_map<char32_t, string>())).first->first;
555  }
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:511
T to_string(T... args)
string initial
Name of the prospective DFA&#39;s initial state.
Definition: dfa.cpp:508

◆ isTrashState()

bool reg::dfa::builder::pImpl::isTrashState ( string const &  q) const
inline

Tests whether all of a state's outgoing transitions point to itself.

Definition at line 530 of file dfa.cpp.

530  {
531  if (acceptingStates.count(q) != 0) {
532  return false;
533  }
534  auto const& from = transitions.at(q);
535  for (char32_t symbol : alphabet) {
536  auto via = from.find(symbol);
537  if (via != from.end() && (*via).second != q) {
538  return false;
539  }
540  }
541  return true;
542  }
Dtransitionmap transitions
Transition function (state × symbol → state) of the prospective DFA.
Definition: dfa.cpp:511
unordered_set< char32_t > alphabet
Set of symbols processable by the prospective DFA.
Definition: dfa.cpp:509
unordered_set< string > acceptingStates
Set of names of the prospective DFA&#39;s accept states.
Definition: dfa.cpp:510

Member Data Documentation

◆ acceptingStates

unordered_set<string> reg::dfa::builder::pImpl::acceptingStates

Set of names of the prospective DFA's accept states.

Definition at line 510 of file dfa.cpp.

◆ alphabet

unordered_set<char32_t> reg::dfa::builder::pImpl::alphabet

Set of symbols processable by the prospective DFA.

Definition at line 509 of file dfa.cpp.

◆ initial

string reg::dfa::builder::pImpl::initial

Name of the prospective DFA's initial state.

Definition at line 508 of file dfa.cpp.

◆ transitions

Dtransitionmap reg::dfa::builder::pImpl::transitions

Transition function (state × symbol → state) of the prospective DFA.

Also encodes the set of states in its set of keys.

Definition at line 511 of file dfa.cpp.


The documentation for this struct was generated from the following file: