reglibcpp  1.7.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 505 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 517 of file dfa.cpp.

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

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 557 of file dfa.cpp.

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

◆ 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 543 of file dfa.cpp.

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

◆ 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 528 of file dfa.cpp.

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

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 508 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 507 of file dfa.cpp.

◆ initial

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

Name of the prospective DFA's initial state.

Definition at line 506 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 509 of file dfa.cpp.


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