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

Private implementation details of NFAs. More...

Public Member Functions

 pImpl ()
 Constructs private implementation object for an NFA accepting the empty language ∅. More...
 
 pImpl (vector< char32_t > &alphabet, vector< vector< valarray< bool >>> &transitions, vector< string > &labels, valarray< bool > &acceptingStates)
 Constructs private implementation object with provided members and empty ε-closure cache. More...
 
dfa const & getEquivalentDfa (nfa const *owner)
 Returns the equivalent DFA safely, constructing it if it wasn't already. More...
 

Public Attributes

shared_ptr< dfa const > equivalent
 Stores a minimal DFA accepting the same language as this object's NFA. 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< string > utf8Alphabet
 Represents the set of processable symbols as UTF-8-encoded strings. More...
 
vector< valarray< bool > > epsClosures
 Cache for every state's ε-closures. More...
 
vector< string > labels
 Stores the names of states. More...
 
vector< vector< valarray< bool > > > transitions
 Stores the transition function as a table viz state index × symbol index → list of bools with true at reached state indices. More...
 

Detailed Description

Private implementation details of NFAs.

Definition at line 31 of file nfa.cpp.

Constructor & Destructor Documentation

◆ pImpl() [1/2]

reg::nfa::pImpl::pImpl ( )
inline

Constructs private implementation object for an NFA accepting the empty language ∅.

Definition at line 41 of file nfa.cpp.

41  :
42  equivalent(),
43  accepting(),
44  alphabet(1, U'\0'),
45  utf8Alphabet(1, ""),
46  epsClosures(),
47  labels(),
48  transitions() {}
vector< vector< valarray< bool > > > transitions
Stores the transition function as a table viz state index × symbol index → list of bools with true a...
Definition: nfa.cpp:38
vector< string > labels
Stores the names of states.
Definition: nfa.cpp:37
valarray< bool > accepting
A true value marks an index as belonging to an accept state.
Definition: nfa.cpp:33
vector< char32_t > alphabet
Represents the set of processable symbols.
Definition: nfa.cpp:34
vector< valarray< bool > > epsClosures
Cache for every state&#39;s ε-closures.
Definition: nfa.cpp:36
vector< string > utf8Alphabet
Represents the set of processable symbols as UTF-8-encoded strings.
Definition: nfa.cpp:35
shared_ptr< dfa const > equivalent
Stores a minimal DFA accepting the same language as this object&#39;s NFA.
Definition: nfa.cpp:32

◆ pImpl() [2/2]

reg::nfa::pImpl::pImpl ( vector< char32_t > &  alphabet,
vector< vector< valarray< bool >>> &  transitions,
vector< string > &  labels,
valarray< bool > &  acceptingStates 
)
inline

Constructs private implementation object with provided members and empty ε-closure cache.

Definition at line 51 of file nfa.cpp.

52  :
53  accepting(move(acceptingStates)),
54  alphabet(move(alphabet)),
55  labels(move(labels)),
56  transitions(move(transitions)) {
57  utf8Alphabet.reserve(this->alphabet.size());
58  for (char32_t symbol : this->alphabet) {
59  if (symbol == U'\0') {
60  utf8Alphabet.push_back("");
61  } else {
62  utf8Alphabet.push_back(expression::converter->to_bytes(symbol));
63  }
64  }
65  epsClosures = vector<valarray<bool>>(pImpl::labels.size());
66  }
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< vector< valarray< bool > > > transitions
Stores the transition function as a table viz state index × symbol index → list of bools with true a...
Definition: nfa.cpp:38
vector< string > labels
Stores the names of states.
Definition: nfa.cpp:37
valarray< bool > accepting
A true value marks an index as belonging to an accept state.
Definition: nfa.cpp:33
vector< char32_t > alphabet
Represents the set of processable symbols.
Definition: nfa.cpp:34
vector< valarray< bool > > epsClosures
Cache for every state&#39;s ε-closures.
Definition: nfa.cpp:36
vector< string > utf8Alphabet
Represents the set of processable symbols as UTF-8-encoded strings.
Definition: nfa.cpp:35

Member Function Documentation

◆ getEquivalentDfa()

dfa const& reg::nfa::pImpl::getEquivalentDfa ( nfa const *  owner)
inline

Returns the equivalent DFA safely, constructing it if it wasn't already.

Parameters
ownerpointer to the NFA calling the method

Definition at line 73 of file nfa.cpp.

73  {
74  if (!equivalent) {
75  equivalent.reset(new dfa::dfa(dfa::builder(*owner).purge().merge()));
76  }
77  return *equivalent;
78  }
dfa()
Constructs a DFA accepting the empty language ∅.
Definition: dfa.cpp:107
shared_ptr< dfa const > equivalent
Stores a minimal DFA accepting the same language as this object&#39;s NFA.
Definition: nfa.cpp:32

Member Data Documentation

◆ accepting

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

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

Definition at line 33 of file nfa.cpp.

◆ alphabet

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

Represents the set of processable symbols.

Definition at line 34 of file nfa.cpp.

◆ epsClosures

vector<valarray<bool> > reg::nfa::pImpl::epsClosures
mutable

Cache for every state's ε-closures.

Definition at line 36 of file nfa.cpp.

◆ equivalent

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

Stores a minimal DFA accepting the same language as this object's NFA.

Definition at line 32 of file nfa.cpp.

◆ labels

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

Stores the names of states.

Definition at line 37 of file nfa.cpp.

◆ transitions

vector<vector<valarray<bool> > > reg::nfa::pImpl::transitions

Stores the transition function as a table viz state index × symbol index → list of bools with true at reached state indices.

Definition at line 38 of file nfa.cpp.

◆ utf8Alphabet

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

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

Definition at line 35 of file nfa.cpp.


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