reglibcpp  1.0.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< string > utf8Alphabet
 Represents the set of processable symbols as UTF-8-encoded strings. More...
 
vector< string > labels
 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 35 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 43 of file dfa.cpp.

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

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

47  :
48  accepting(move(accepting)),
49  alphabet(move(alphabet)),
50  labels(move(labels)),
51  transitions(move(transitions)) {
52  utf8Alphabet.reserve(this->alphabet.size());
53  for (char32_t symbol : this->alphabet) {
54  utf8Alphabet.push_back(expression::converter->to_bytes(symbol));
55  }
56  }
static std::unique_ptr< std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t > > const converter
Converts between UTF-8-encoded and UTF-32-encoded strings.
Definition: expression.h:97
vector< char32_t > alphabet
Represents the set of processable symbols.
Definition: dfa.cpp:37
valarray< bool > accepting
A true value marks an index as belonging to an accept state.
Definition: dfa.cpp:36
vector< string > utf8Alphabet
Represents the set of processable symbols as UTF-8-encoded strings.
Definition: dfa.cpp:38
vector< string > labels
Stores the names of states.
Definition: dfa.cpp:39
vector< vector< size_t > > transitions
Stores the transition function as a table viz state index × symbol index → state index...
Definition: dfa.cpp:40

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

65  {
66  vector<valarray<bool>> distinguishable;
67  distinguishable.reserve(transitions.size());
68  for (size_t q(0); q < transitions.size(); q++) {
69  bool qAcc(accepting[q]);
70  distinguishable.push_back(valarray<bool>(false, transitions.size()));
71  for (size_t p(0); p < q; p++) {
72  bool pAcc(accepting[p]);
73  distinguishable[q][p] = (qAcc != pAcc);
74  distinguishable[p][q] = (qAcc != pAcc);
75  }
76  }
77  bool changes(true);
78  while (changes) {
79  changes = false;
80  for (size_t q(0); q < transitions.size(); q++) {
81  for (size_t p(0); p < q; p++) {
82  if (distinguishable[q][p]) {
83  continue;
84  }
85  for (size_t s(0); s < transitions[q].size(); s++) {
86  size_t qS(transitions[q][s]);
87  size_t pS(transitions[p][s]);
88  if (distinguishable[qS][pS]) {
89  changes = true;
90  distinguishable[q][p] = true;
91  distinguishable[p][q] = true;
92  break;
93  }
94  }
95  }
96  }
97  }
98  valarray<bool> allTrue(true, transitions.size());
99  for (size_t i(0); i < distinguishable.size(); i++) {
100  distinguishable[i] ^= allTrue;
101  }
102  return distinguishable;
103  }
valarray< bool > accepting
A true value marks an index as belonging to an accept state.
Definition: dfa.cpp:36
vector< vector< size_t > > transitions
Stores the transition function as a table viz state index × symbol index → state index...
Definition: dfa.cpp:40

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

◆ alphabet

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

Represents the set of processable symbols.

Definition at line 37 of file dfa.cpp.

◆ labels

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

Stores the names of states.

Definition at line 39 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 40 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 38 of file dfa.cpp.


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