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

Private implementation details of DFAs. More...

Public Member Functions

 pImpl ()
 Constructs private implementation object for a DFA accepting the empty language ∅. More...
 
 pImpl (vector< char32_t > &alphabet, vector< vector< size_t >> &transitions, vector< string > &labels, valarray< bool > &accepting)
 Constructs private implementation object with provided members. More...
 

Static Public Member Functions

static vector< valarray< bool > > indistinguishableStates (vector< vector< size_t >> const &transitions, valarray< bool > const &accepting)
 Builds the table of indistinguishable states w.r.t. a transition function. More...
 

Public Attributes

valarray< bool > accepting
 A true value marks an index as belonging to an accept state. More...
 
vector< char32_t > alphabet
 Represents the set of processable symbols. More...
 
vector< stringutf8Alphabet
 Represents the set of processable symbols as UTF-8-encoded strings. More...
 
vector< stringlabels
 Stores the names of states. More...
 
vector< vector< size_t > > transitions
 Stores the transition function as a table viz state index × symbol index → state index. More...
 

Detailed Description

Private implementation details of DFAs.

Definition at line 54 of file dfa.cpp.

Constructor & Destructor Documentation

◆ pImpl() [1/2]

reg::dfa::pImpl::pImpl ( )
inline

Constructs private implementation object for a DFA accepting the empty language ∅.

Definition at line 62 of file dfa.cpp.

62 : accepting(false, 1), alphabet(0), utf8Alphabet(0), labels(1), transitions(1) {}
vector< char32_t > alphabet
Represents the set of processable symbols.
Definition: dfa.cpp:56
valarray< bool > accepting
A true value marks an index as belonging to an accept state.
Definition: dfa.cpp:55
vector< string > utf8Alphabet
Represents the set of processable symbols as UTF-8-encoded strings.
Definition: dfa.cpp:57
vector< string > labels
Stores the names of states.
Definition: dfa.cpp:58
vector< vector< size_t > > transitions
Stores the transition function as a table viz state index × symbol index → state index...
Definition: dfa.cpp:59

◆ pImpl() [2/2]

reg::dfa::pImpl::pImpl ( vector< char32_t > &  alphabet,
vector< vector< size_t >> &  transitions,
vector< string > &  labels,
valarray< bool > &  accepting 
)
inline

Constructs private implementation object with provided members.

Definition at line 65 of file dfa.cpp.

66  :
69  labels(move(labels)),
71  utf8Alphabet.reserve(this->alphabet.size());
72  for (char32_t symbol : this->alphabet) {
73  utf8Alphabet.push_back(converter.to_bytes(symbol));
74  }
75  }
vector< char32_t > alphabet
Represents the set of processable symbols.
Definition: dfa.cpp:56
valarray< bool > accepting
A true value marks an index as belonging to an accept state.
Definition: dfa.cpp:55
vector< string > utf8Alphabet
Represents the set of processable symbols as UTF-8-encoded strings.
Definition: dfa.cpp:57
std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t > converter
Converts between UTF-8-encoded and UTF-32-encoded strings.
Definition: dfa.cpp:1088
vector< string > labels
Stores the names of states.
Definition: dfa.cpp:58
vector< vector< size_t > > transitions
Stores the transition function as a table viz state index × symbol index → state index...
Definition: dfa.cpp:59
T move(T... args)

Member Function Documentation

◆ indistinguishableStates()

static vector<valarray<bool> > reg::dfa::pImpl::indistinguishableStates ( vector< vector< size_t >> const &  transitions,
valarray< bool > const &  accepting 
)
inlinestatic

Builds the table of indistinguishable states w.r.t. a transition function.

Parameters
transitionsthe transition function to base indistinguishability computation off
acceptingthe set of states that's trivially distinguishable from the rest
Returns
state index × state index table where true values mark indistinguishable states

Definition at line 83 of file dfa.cpp.

84  {
85  vector<valarray<bool>> distinguishable;
86  distinguishable.reserve(transitions.size());
87  for (size_t q(0); q < transitions.size(); q++) {
88  bool qAcc(accepting[q]);
89  distinguishable.push_back(valarray<bool>(false, transitions.size()));
90  for (size_t p(0); p < q; p++) {
91  bool pAcc(accepting[p]);
92  distinguishable[q][p] = (qAcc != pAcc);
93  distinguishable[p][q] = (qAcc != pAcc);
94  }
95  }
96  bool changes(true);
97  while (changes) {
98  changes = false;
99  for (size_t q(0); q < transitions.size(); q++) {
100  for (size_t p(0); p < q; p++) {
101  if (distinguishable[q][p]) {
102  continue;
103  }
104  for (size_t s(0); s < transitions[q].size(); s++) {
105  size_t qS(transitions[q][s]);
106  size_t pS(transitions[p][s]);
107  if (distinguishable[qS][pS]) {
108  changes = true;
109  distinguishable[q][p] = true;
110  distinguishable[p][q] = true;
111  break;
112  }
113  }
114  }
115  }
116  }
117  valarray<bool> allTrue(true, transitions.size());
118  for (size_t i(0); i < distinguishable.size(); i++) {
119  distinguishable[i] ^= allTrue;
120  }
121  return distinguishable;
122  }
valarray< bool > accepting
A true value marks an index as belonging to an accept state.
Definition: dfa.cpp:55
vector< vector< size_t > > transitions
Stores the transition function as a table viz state index × symbol index → state index...
Definition: dfa.cpp:59

Member Data Documentation

◆ accepting

valarray<bool> reg::dfa::pImpl::accepting

A true value marks an index as belonging to an accept state.

Definition at line 55 of file dfa.cpp.

◆ alphabet

vector<char32_t> reg::dfa::pImpl::alphabet

Represents the set of processable symbols.

Definition at line 56 of file dfa.cpp.

◆ labels

vector<string> reg::dfa::pImpl::labels

Stores the names of states.

Definition at line 58 of file dfa.cpp.

◆ transitions

vector<vector<size_t> > reg::dfa::pImpl::transitions

Stores the transition function as a table viz state index × symbol index → state index.

Definition at line 59 of file dfa.cpp.

◆ utf8Alphabet

vector<string> reg::dfa::pImpl::utf8Alphabet

Represents the set of processable symbols as UTF-8-encoded strings.

Definition at line 57 of file dfa.cpp.


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