reglibcpp  1.7.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

std::shared_ptr< nfa const > equivalent
 Holds an equivalent NFA in case it is ever needed. More...
 
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 63 of file dfa.cpp.

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

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

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

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

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

◆ alphabet

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

Represents the set of processable symbols.

Definition at line 57 of file dfa.cpp.

◆ equivalent

std::shared_ptr<nfa const> reg::dfa::pImpl::equivalent
mutable

Holds an equivalent NFA in case it is ever needed.

Definition at line 55 of file dfa.cpp.

◆ labels

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

Stores the names of states.

Definition at line 59 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 60 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 58 of file dfa.cpp.


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