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

Represents deterministic finite automata. More...

#include <dfa.h>

Classes

class  builder
 Constructs DFAs step by step. More...
 
struct  pImpl
 Private implementation details of DFAs. More...
 

Public Member Functions

 dfa ()
 Constructs a DFA accepting the empty language ∅. More...
 
 dfa (dfa const &d)
 Copy-constructs a DFA by copying another one's private implementation object. More...
 
 dfa (dfa &&d)
 Move-constructs a DFA by stealing another one's private implementation object. More...
 
 dfa (nfa const &n)
 Constructs a DFA from an NFA via powerset construction. More...
 
 dfa (builder &b)
 Constructs a DFA from a builder. More...
 
dfaoperator= (const dfa &d)
 Copy-assigns this DFA by copying another one's private implementation object. More...
 
dfaoperator= (dfa &&d)
 Move-assigns this DFA by stealing another one's private implementation object. More...
 
bool operator== (const dfa &d) const
 Tests whether this DFA accepts exactly the same language as another one. More...
 
bool operator!= (const dfa &d) const
 Tests whether this DFA doesn't accept the same language as another one. More...
 
size_t delta (size_t qi, size_t si) const
 Computes this DFA's transition function for a state index and a symbol index. More...
 
size_t delta (size_t qi, char32_t symbol) const
 Computes this DFA's transition function for a state index and a symbol. More...
 
size_t delta (size_t qi, std::string const &utf8Symbol) const
 Same as above for a UTF-8-encoded symbol. More...
 
std::string const & delta (std::string const &q, char32_t symbol) const
 Computes this DFA's transition function for a state label and a symbol. More...
 
std::string const & delta (std::string const &q, std::string const &utf8Symbol) const
 Same as above for a UTF-8-encoded symbol. More...
 
size_t deltaHat (size_t qi, std::u32string const &word) const
 Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its index. More...
 
size_t deltaHat (size_t qi, std::string const &utf8Word) const
 Same as above for a string of UTF-8-encoded symbols. More...
 
std::string const & deltaHat (std::string const &q, std::u32string const &word) const
 Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its name. More...
 
std::string const & deltaHat (std::string const &q, std::string const &utf8Word) const
 Same as above for a string of UTF-8-encoded symbols. More...
 
std::u32string getShortestWord () const
 Searches the shortest UTF-32-encoded word accepted by this DFA. More...
 
std::string getShortestUtf8Word () const
 Same as above for a UTF-8-encoded word. More...
 
std::string const & getLabelOf (size_t qi) const
 Puts a name to an index. More...
 
std::string const & getInitialState () const
 Names this DFA's initial state. More...
 
std::vector< std::string > const & getStates () const
 Fetches this DFA's set of states. More...
 
std::vector< char32_t > const & getAlphabet () const
 Fetches this DFA's set of processable symbols. More...
 
std::vector< std::string > const & getUtf8Alphabet () const
 Fetches this DFA's set of processable symbols as UTF-8-encoded strings. More...
 
size_t getNumberOfStates () const
 Counts this DFA's states. More...
 
size_t getNumberOfSymbols () const
 Counts this DFA's alphabet symbols. More...
 
bool isAccepting (size_t qi) const
 Tests whether a state is an accept state within this DFA. More...
 
bool isAccepting (std::string const &q) const
 Tests whether a state is an accept state within this DFA. More...
 

Static Public Member Functions

static dfa::builder unite (dfa const &d1, dfa const &d2)
 Creates a builder for a DFA accepting the union of the languages of two DFAs. More...
 
static dfa::builder intersect (dfa const &d1, dfa const &d2)
 Creates a builder for a DFA accepting the intersection of the languages of two DFAs. More...
 
static dfa::builder subtract (dfa const &d1, dfa const &d2)
 Creates a builder for a DFA accepting the set difference of the languages of two DFAs. More...
 
static dfa::builder complement (dfa const &d)
 Creates a builder for a DFA accepting the complement of the language of a DFA. More...
 

Detailed Description

Represents deterministic finite automata.

Instances of this class are completely immutable. The builder class is the preferred way of constructing DFAs.

By convention, the state with index 0 is the initial state.

Definition at line 27 of file dfa.h.

Constructor & Destructor Documentation

◆ dfa() [1/5]

reg::dfa::dfa ( )

Constructs a DFA accepting the empty language ∅.

Definition at line 126 of file dfa.cpp.

126 : p(new pImpl) {}

◆ dfa() [2/5]

reg::dfa::dfa ( dfa const &  d)

Copy-constructs a DFA by copying another one's private implementation object.

Definition at line 136 of file dfa.cpp.

136 : p(new pImpl(*(d.p))) {}

◆ dfa() [3/5]

reg::dfa::dfa ( dfa &&  d)

Move-constructs a DFA by stealing another one's private implementation object.

The other DFA will be accepting the empty language ∅ afterwards.

Definition at line 140 of file dfa.cpp.

140 : p(new pImpl) {p.swap(d.p);}

◆ dfa() [4/5]

reg::dfa::dfa ( nfa const &  n)

Constructs a DFA from an NFA via powerset construction.

Definition at line 143 of file dfa.cpp.

143 : dfa(builder(n).build()) {}
dfa()
Constructs a DFA accepting the empty language ∅.
Definition: dfa.cpp:126

◆ dfa() [5/5]

reg::dfa::dfa ( dfa::builder b)

Constructs a DFA from a builder.

Definition at line 146 of file dfa.cpp.

146 : dfa(b.build()) {}
dfa()
Constructs a DFA accepting the empty language ∅.
Definition: dfa.cpp:126

Member Function Documentation

◆ complement()

dfa::builder reg::dfa::complement ( dfa const &  d)
static

Creates a builder for a DFA accepting the complement of the language of a DFA.

The input DFAs' state names will be retained in the created DFA.

Parameters
dthe DFA
Returns
builder fo a DFA accepting all words not accepted by the input DFA (provided they can be built from symbols of that DFA's alphabet)

Definition at line 499 of file dfa.cpp.

499  {
500  return dfa::builder(d).complement();
501 }

◆ delta() [1/5]

size_t reg::dfa::delta ( size_t  qi,
size_t  si 
) const

Computes this DFA's transition function for a state index and a symbol index.

Parameters
qithe state's index (< getNumberOfStates)
siindex of the symbol to process (< getNumberOfSymbols)
Returns
the reached state's index
Exceptions
std::out_of_rangeif qigetNumberOfStates
std::domain_errorif sigetAlphabet

Definition at line 227 of file dfa.cpp.

227  {
228  if (si >= p->alphabet.size()) {
229  throw std::domain_error("There is no symbol with index " + to_string(si));
230  }
231  if (qi >= p->labels.size()) {
232  throw std::out_of_range("There is no state with index " + to_string(qi));
233  }
234  return p->transitions[qi][si];
235 }
T to_string(T... args)

◆ delta() [2/5]

size_t reg::dfa::delta ( size_t  qi,
char32_t  symbol 
) const

Computes this DFA's transition function for a state index and a symbol.

Parameters
qithe state's index (< getNumberOfStates)
symbolthe symbol to process (∈ getAlphabet)
Returns
the reached state's index
Exceptions
std::out_of_rangeif qigetNumberOfStates
std::domain_errorif symbolgetAlphabet

Definition at line 245 of file dfa.cpp.

245  {
246  try {
247  return delta(qi, index_of(p->alphabet, symbol));
248  } catch (std::domain_error e) {
249  throw std::domain_error(u8"δ is not defined for symbol " + converter.to_bytes(symbol));
250  }
251 }
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
size_t delta(size_t qi, size_t si) const
Computes this DFA's transition function for a state index and a symbol index.
Definition: dfa.cpp:227
size_t index_of(vector< T > const &vec, T const &element)
Basically Java&#39;s List interface&#39;s indexOf, but as a non-member function and returning the container&#39;s...
Definition: dfa.cpp:1080

◆ delta() [3/5]

size_t reg::dfa::delta ( size_t  qi,
std::string const &  utf8Symbol 
) const

Same as above for a UTF-8-encoded symbol.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 254 of file dfa.cpp.

254  {
255  return delta(qi, converter.from_bytes(utf8Symbol)[0]);
256 }
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
size_t delta(size_t qi, size_t si) const
Computes this DFA's transition function for a state index and a symbol index.
Definition: dfa.cpp:227

◆ delta() [4/5]

string const & reg::dfa::delta ( std::string const &  q,
char32_t  symbol 
) const

Computes this DFA's transition function for a state label and a symbol.

Parameters
qthe state's label (∈ getStates)
symbolthe symbol to process (∈ getAlphabet)
Returns
the reached state's label
Exceptions
std::out_of_rangeif qgetStates
std::domain_errorif symbolgetAlphabet

Definition at line 266 of file dfa.cpp.

266  {
267  try {
268  return getStates()[delta(index_of(getStates(), q), symbol)];
269  } catch (std::out_of_range e) {
270  throw std::out_of_range("There is no state named " + q);
271  }
272 }
size_t delta(size_t qi, size_t si) const
Computes this DFA's transition function for a state index and a symbol index.
Definition: dfa.cpp:227
size_t index_of(vector< T > const &vec, T const &element)
Basically Java&#39;s List interface&#39;s indexOf, but as a non-member function and returning the container&#39;s...
Definition: dfa.cpp:1080
std::vector< std::string > const & getStates() const
Fetches this DFA's set of states.
Definition: dfa.cpp:373

◆ delta() [5/5]

string const & reg::dfa::delta ( std::string const &  q,
std::string const &  utf8Symbol 
) const

Same as above for a UTF-8-encoded symbol.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 275 of file dfa.cpp.

275  {
276  return delta(q, converter.from_bytes(utf8Symbol)[0]);
277 }
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
size_t delta(size_t qi, size_t si) const
Computes this DFA's transition function for a state index and a symbol index.
Definition: dfa.cpp:227

◆ deltaHat() [1/4]

size_t reg::dfa::deltaHat ( size_t  qi,
std::u32string const &  word 
) const

Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its index.

Parameters
qithe starting state's index (< getNumberOfStates)
wordthe string of symbols to process (all of which ∈ getAlphabet)
Returns
the reached state's index
Exceptions
std::out_of_rangeif qigetNumberOfStates
std::domain_errorif one of the word symbols ∉ getAlphabet

Definition at line 287 of file dfa.cpp.

287  {
288  for (char32_t symbol : word) {
289  qi = delta(qi, symbol);
290  }
291  return qi;
292 }
size_t delta(size_t qi, size_t si) const
Computes this DFA's transition function for a state index and a symbol index.
Definition: dfa.cpp:227

◆ deltaHat() [2/4]

size_t reg::dfa::deltaHat ( size_t  q,
std::string const &  utf8Word 
) const

Same as above for a string of UTF-8-encoded symbols.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 295 of file dfa.cpp.

295  {
296  return deltaHat(q, converter.from_bytes(utf8Word));
297 }
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
size_t deltaHat(size_t qi, std::u32string const &word) const
Computes this DFA's transition function recursively for a string of symbols, starting in a state spec...
Definition: dfa.cpp:287

◆ deltaHat() [3/4]

string const & reg::dfa::deltaHat ( std::string const &  q,
std::u32string const &  word 
) const

Computes this DFA's transition function recursively for a string of symbols, starting in a state specified by its name.

Parameters
qthe starting state's label (∈ getStates)
wordthe string of symbols to process (all of which ∈ getAlphabet)
Returns
the reached state's index
Exceptions
std::out_of_rangeif qgetStates
std::domain_errorif one of the word symbols ∉ getAlphabet

Definition at line 307 of file dfa.cpp.

307  {
308  return p->labels[deltaHat(index_of(getStates(), q), word)];
309 }
size_t deltaHat(size_t qi, std::u32string const &word) const
Computes this DFA's transition function recursively for a string of symbols, starting in a state spec...
Definition: dfa.cpp:287
size_t index_of(vector< T > const &vec, T const &element)
Basically Java&#39;s List interface&#39;s indexOf, but as a non-member function and returning the container&#39;s...
Definition: dfa.cpp:1080
std::vector< std::string > const & getStates() const
Fetches this DFA's set of states.
Definition: dfa.cpp:373

◆ deltaHat() [4/4]

string const & reg::dfa::deltaHat ( std::string const &  q,
std::string const &  utf8Word 
) const

Same as above for a string of UTF-8-encoded symbols.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 312 of file dfa.cpp.

312  {
313  return deltaHat(q, converter.from_bytes(utf8Word));
314 }
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
size_t deltaHat(size_t qi, std::u32string const &word) const
Computes this DFA's transition function recursively for a string of symbols, starting in a state spec...
Definition: dfa.cpp:287

◆ getAlphabet()

vector< char32_t > const & reg::dfa::getAlphabet ( ) const

Fetches this DFA's set of processable symbols.

Returns
a vector containing all the valid symbol inputs for delta and deltaHat

Definition at line 381 of file dfa.cpp.

381  {
382  return p->alphabet;
383 }

◆ getInitialState()

string const & reg::dfa::getInitialState ( ) const

Names this DFA's initial state.

Returns
the initial state's name

Definition at line 365 of file dfa.cpp.

365  {
366  return getStates()[0];
367 }
std::vector< std::string > const & getStates() const
Fetches this DFA's set of states.
Definition: dfa.cpp:373

◆ getLabelOf()

string const & reg::dfa::getLabelOf ( size_t  q) const

Puts a name to an index.

Parameters
qthe state's index (< getNumberOfStates)
Returns
the state's name
Exceptions
std::out_of_rangeif qgetNumberOfStates

Definition at line 357 of file dfa.cpp.

357  {
358  return getStates().at(q);
359 }
std::vector< std::string > const & getStates() const
Fetches this DFA's set of states.
Definition: dfa.cpp:373

◆ getNumberOfStates()

size_t reg::dfa::getNumberOfStates ( ) const

Counts this DFA's states.

Returns
the number of states this DFA has

Definition at line 397 of file dfa.cpp.

397  {
398  return getStates().size();
399 }
std::vector< std::string > const & getStates() const
Fetches this DFA's set of states.
Definition: dfa.cpp:373

◆ getNumberOfSymbols()

size_t reg::dfa::getNumberOfSymbols ( ) const

Counts this DFA's alphabet symbols.

Returns
the number of symbols this DFA can process

Definition at line 405 of file dfa.cpp.

405  {
406  return getAlphabet().size();
407 }
std::vector< char32_t > const & getAlphabet() const
Fetches this DFA's set of processable symbols.
Definition: dfa.cpp:381

◆ getShortestUtf8Word()

string reg::dfa::getShortestUtf8Word ( ) const

Same as above for a UTF-8-encoded word.

Definition at line 347 of file dfa.cpp.

347  {
348  return converter.to_bytes(getShortestWord());
349 }
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
std::u32string getShortestWord() const
Searches the shortest UTF-32-encoded word accepted by this DFA.
Definition: dfa.cpp:321

◆ getShortestWord()

u32string reg::dfa::getShortestWord ( ) const

Searches the shortest UTF-32-encoded word accepted by this DFA.

Returns
the shortest word leading to one of this DFA's accept states
Exceptions
std::logic_errorif the DFA doesn't accept any words

Definition at line 321 of file dfa.cpp.

321  {
322  if (p->accepting[0]) {
323  return U"";
324  }
325  unordered_map<size_t, u32string> shortestWords(p->labels.size());
326  size_t oldSize = 0;
327  shortestWords.emplace(0, U"");
328  while (shortestWords.size() > oldSize) {
329  oldSize = shortestWords.size();
330  for (auto const& stateWord : shortestWords) {
331  for (auto symbol : p->alphabet) {
332  size_t reached = delta(stateWord.first, symbol);
333  u32string shWord = stateWord.second + symbol;
334  if (p->accepting[reached]) {
335  return shWord;
336  }
337  if (shortestWords.find(reached) == shortestWords.end()) {
338  shortestWords.emplace(reached, shWord);
339  }
340  }
341  }
342  }
343  throw std::logic_error("This DFA doesn't accept any words!");
344 }
size_t delta(size_t qi, size_t si) const
Computes this DFA's transition function for a state index and a symbol index.
Definition: dfa.cpp:227

◆ getStates()

vector< string > const & reg::dfa::getStates ( ) const

Fetches this DFA's set of states.

Returns
a vector containing the names of states that can be used as input for delta and deltaHat

Definition at line 373 of file dfa.cpp.

373  {
374  return p->labels;
375 }

◆ getUtf8Alphabet()

vector< string > const & reg::dfa::getUtf8Alphabet ( ) const

Fetches this DFA's set of processable symbols as UTF-8-encoded strings.

Returns
a vector containing all the valid symbol inputs for delta and deltaHat

Definition at line 389 of file dfa.cpp.

389  {
390  return p->utf8Alphabet;
391 }

◆ intersect()

dfa::builder reg::dfa::intersect ( dfa const &  d1,
dfa const &  d2 
)
static

Creates a builder for a DFA accepting the intersection of the languages of two DFAs.

The input DFAs' state names will be concatenated and collisions resolved by appending _ in the created DFA.

Parameters
d1the first DFA
d2the other DFA
Returns
builder for a DFA accepting all the words accepted by both of the input DFAs

Definition at line 471 of file dfa.cpp.

471  {
472  return builder(d1).intersect(d2);
473 }

◆ isAccepting() [1/2]

bool reg::dfa::isAccepting ( size_t  qi) const

Tests whether a state is an accept state within this DFA.

Parameters
qithe state's index (< getNumberOfStates)
Returns
true if the state is in the set of accept states, false else
Exceptions
std::out_of_rangeif qigetNumberOfStates

Definition at line 415 of file dfa.cpp.

415  {
416  if (qi >= p->labels.size()) {
417  throw std::out_of_range("There is no state with index " + to_string(qi));
418  }
419  return p->accepting[qi];
420 }
T to_string(T... args)

◆ isAccepting() [2/2]

bool reg::dfa::isAccepting ( std::string const &  q) const

Tests whether a state is an accept state within this DFA.

Parameters
qthe state's label (∈ getStates)
Returns
true if the state is in the set of accept states, false else
Exceptions
std::out_of_rangeif qgetStates

Definition at line 428 of file dfa.cpp.

428  {
429  try {
430  return isAccepting(index_of(getStates(), q));
431  } catch (std::out_of_range e) {
432  throw std::out_of_range("There is no state named " + q);
433  }
434 }
bool isAccepting(size_t qi) const
Tests whether a state is an accept state within this DFA.
Definition: dfa.cpp:415
size_t index_of(vector< T > const &vec, T const &element)
Basically Java&#39;s List interface&#39;s indexOf, but as a non-member function and returning the container&#39;s...
Definition: dfa.cpp:1080
std::vector< std::string > const & getStates() const
Fetches this DFA's set of states.
Definition: dfa.cpp:373

◆ operator!=()

bool reg::dfa::operator!= ( const dfa d) const

Tests whether this DFA doesn't accept the same language as another one.

Definition at line 217 of file dfa.cpp.

217 {return !operator==(d);}
bool operator==(const dfa &d) const
Tests whether this DFA accepts exactly the same language as another one.
Definition: dfa.cpp:173

◆ operator=() [1/2]

dfa & reg::dfa::operator= ( const dfa d)

Copy-assigns this DFA by copying another one's private implementation object.

Definition at line 149 of file dfa.cpp.

149  {
150  if (this != &d) {
151  p.reset(new pImpl(*(d.p)));
152  }
153  return *this;
154 }

◆ operator=() [2/2]

dfa & reg::dfa::operator= ( dfa &&  d)

Move-assigns this DFA by stealing another one's private implementation object.

The other DFA will be accepting the empty language ∅ afterwards.

Definition at line 158 of file dfa.cpp.

158  {
159  if (this != &d) {
160  p.reset(new pImpl);
161  p.swap(d.p);
162  }
163  return *this;
164 }

◆ operator==()

bool reg::dfa::operator== ( const dfa d) const

Tests whether this DFA accepts exactly the same language as another one.

More specifically, checks whether this DFA's initial state is indistinguishable from the other one's.

Definition at line 173 of file dfa.cpp.

173  {
174  forward_list<char32_t> unitedAlphabet(p->alphabet.begin(), p->alphabet.end());
175  size_t unitedAlphabetSize(p->alphabet.size());
176  for (char32_t symbol : d.getAlphabet()) {
177  if (find(p->alphabet.begin(), p->alphabet.end(), symbol) == p->alphabet.end()) {
178  unitedAlphabet.push_front(symbol);
179  unitedAlphabetSize++;
180  }
181  }
182  vector<vector<size_t>> tTable(getNumberOfStates()+d.getNumberOfStates()+1, vector<size_t>(unitedAlphabetSize));
183  valarray<bool> accepting(false, getNumberOfStates()+d.getNumberOfStates()+1);
184  for (size_t q(0); q < getNumberOfStates(); q++) {
185  size_t s(0);
186  vector<size_t>& row = tTable[q];
187  for (char32_t symbol : unitedAlphabet) {
188  try {
189  row[s] = delta(q, symbol);
190  } catch (std::domain_error e) {
191  row[s] = getNumberOfStates()+d.getNumberOfStates();
192  }
193  s++;
194  }
195  accepting[q] = isAccepting(q);
196  }
197  for (size_t q(0); q < d.getNumberOfStates(); q++) {
198  size_t s(0);
199  vector<size_t>& row = tTable[q+getNumberOfStates()];
200  for (char32_t symbol : unitedAlphabet) {
201  try {
202  row[s] = getNumberOfStates()+d.delta(q, symbol);
203  } catch (std::domain_error e) {
204  row[s] = getNumberOfStates()+d.getNumberOfStates();
205  }
206  s++;
207  }
208  accepting[q+getNumberOfStates()] = d.isAccepting(q);
209  }
210  for (size_t s(0); s < unitedAlphabetSize; s++) {
211  tTable[getNumberOfStates()+d.getNumberOfStates()][s] = getNumberOfStates()+d.getNumberOfStates();
212  }
213  return pImpl::indistinguishableStates(tTable, accepting)[0][getNumberOfStates()];
214 }
bool isAccepting(size_t qi) const
Tests whether a state is an accept state within this DFA.
Definition: dfa.cpp:415
size_t delta(size_t qi, size_t si) const
Computes this DFA's transition function for a state index and a symbol index.
Definition: dfa.cpp:227
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.
Definition: dfa.cpp:83
size_t getNumberOfStates() const
Counts this DFA's states.
Definition: dfa.cpp:397
T find(T... args)

◆ subtract()

dfa::builder reg::dfa::subtract ( dfa const &  d1,
dfa const &  d2 
)
static

Creates a builder for a DFA accepting the set difference of the languages of two DFAs.

The input DFAs' state names will be concatenated and collisions resolved by appending _ in the created DFA.

Parameters
d1the first DFA
d2the other DFA
Returns
builder for a DFA accepting all the words accepted by the first but not the other input DFA

Definition at line 483 of file dfa.cpp.

483  {
484  builder b1(d1);
485  for (auto symbol : d2.getAlphabet()) {
486  b1.addSymbol(symbol);
487  }
488  return b1.complement().unite(d2).complement();
489 }

◆ unite()

dfa::builder reg::dfa::unite ( dfa const &  d1,
dfa const &  d2 
)
static

Creates a builder for a DFA accepting the union of the languages of two DFAs.

The input DFAs' state names will be concatenated and collisions resolved by appending _ in the created DFA.

Parameters
d1the first DFA
d2the other DFA
Returns
builder for a DFA accepting all the words accepted by any of the input DFAs

Definition at line 459 of file dfa.cpp.

459  {
460  return builder(d1).unite(d2);
461 }

The documentation for this class was generated from the following files: