reglibcpp  2.1.0
A C++ implementation of models for regular languages
fabuilder.h
Go to the documentation of this file.
1 // Copyright 2017, 2018 Tom Kranz
2 //
3 // This file is part of reglibcpp.
4 //
5 // reglibcpp is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // reglibcpp is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with reglibcpp. If not, see <https://www.gnu.org/licenses/>.
17 
18 #ifndef REG_FABUILDER_H
19 #define REG_FABUILDER_H
20 
22 #include "dfa.h"
23 #include "nfa.h"
24 
25 namespace reg {
27 
31 class fabuilder {
32  public:
33  fabuilder();
34  fabuilder(nfa const& nfa);
35  fabuilder(dfa const& dfa);
36  fabuilder(fabuilder const& b);
37  fabuilder(fabuilder&& b);
38  fabuilder& operator=(fabuilder const& b);
40  virtual ~fabuilder();
41 
42  fabuilder& setAccepting(std::string const& state, bool accept);
43  fabuilder& makeInitial(std::string const& state);
44  fabuilder& addSymbol(std::string const& symbol);
45  fabuilder& addTransition(std::string const& from, std::string const& to,
46  std::string const& symbol = "");
47  fabuilder& addSymbol_(char32_t u32symbol);
48  fabuilder& addTransition_(std::string const& from, std::string const& to,
49  char32_t u32symbol = U'\0');
52  fabuilder& merge(bool force = false);
53  fabuilder& purge();
54  fabuilder& minimize(bool force = false);
55  fabuilder& unite(nfa const& other);
56  fabuilder& intersect(nfa const& other);
57  fabuilder& subtract(nfa const& other, bool force = false);
58  fabuilder& complement(bool force = false);
60  bool isComplete();
61  bool hasNondeterminism();
62  nfa buildNfa();
63  dfa buildDfa(bool force = false);
64 
70  char const* what_arg = "Builder has nondeterministic characteristics.")
71  : std::logic_error(what_arg) {}
73  inline nondeterminism_exception(std::string const& what_arg)
74  : std::logic_error(what_arg) {}
75  };
76 
77  private:
78  struct impl;
80 };
81 } // namespace reg
82 #endif // REG_FABUILDER_H
fabuilder & operator=(fabuilder const &b)
Copy-assigns a builder by copying another one's private implementation object.
Definition: fabuilder.cpp:200
fabuilder & addSymbol(std::string const &symbol)
Adds a symbol to the prospective FA's alphabet.
Definition: fabuilder.cpp:253
Represents nondeterministic finite automata with ε-moves.
Definition: nfa.h:38
Represents deterministic finite automata.
Definition: dfa.h:43
fabuilder & subtract(nfa const &other, bool force=false)
Makes the prospective FA reject all words accepted by another FA.
Definition: fabuilder.cpp:770
bool isComplete()
Reports whether the prospective FA has at least one transition defined for every state-symbol combina...
Definition: fabuilder.cpp:871
fabuilder & intersect(nfa const &other)
Makes the prospective FA accept only words accepted also by another FA.
Definition: fabuilder.cpp:672
fabuilder & addTransition(std::string const &from, std::string const &to, std::string const &symbol="")
Adds a transition to the prospective FA's state transition function.
Definition: fabuilder.cpp:268
bool hasNondeterminism()
Checks whether any nondeterministic transitions have been defined.
Definition: fabuilder.cpp:887
fabuilder & complete()
Totalizes a partial transition function by pointing any undefined transitions towards a trash state...
Definition: fabuilder.cpp:363
fabuilder & purge()
Purges the prospective FA of unreachable and non-producing states, possibly completing minimization...
Definition: fabuilder.cpp:489
Contains the reg::nfa class definition.
fabuilder & minimize(bool force=false)
Convenience method for chaining purge and merge to achieve proper DFA minimization.
Definition: fabuilder.cpp:559
dfa buildDfa(bool force=false)
Builds a DFA as defined by previous operations, including completion.
Definition: fabuilder.cpp:965
nondeterminism_exception(std::string const &what_arg)
Definition: fabuilder.h:73
fabuilder & addSymbol_(char32_t u32symbol)
Adds a symbol to the prospective FA's alphabet.
Definition: fabuilder.cpp:279
fabuilder & unite(nfa const &other)
Makes the prospective FA also accept every word of another FA's language.
Definition: fabuilder.cpp:571
fabuilder & normalizeStateNames(std::string const &prefix)
Reduces the prospective FA's state names to consecutive numbers, prefixed with a given string...
Definition: fabuilder.cpp:822
fabuilder & setAccepting(std::string const &state, bool accept)
Sets whether or not a state will be accepting within the prospective FA.
Definition: fabuilder.cpp:225
Signals that an operation requires full determinism and that no powerset construction was forced...
Definition: fabuilder.h:67
fabuilder()
Constructs a blank builder object.
Definition: fabuilder.cpp:173
Constructs finite automata step by step.
Definition: fabuilder.h:31
fabuilder & powerset()
Converts the builder's prospective NFA into a DFA via powerset construction.
Definition: fabuilder.cpp:316
fabuilder & merge(bool force=false)
Merges the prospective DFA's indistinguishable states, allowing for minimization. ...
Definition: fabuilder.cpp:421
Where this library lives.
Definition: dfa.cpp:48
fabuilder & makeInitial(std::string const &state)
Resets the initial state for the prospective FA.
Definition: fabuilder.cpp:243
nondeterminism_exception(char const *what_arg="Builder has nondeterministic characteristics.")
Constructs an exception object with the given message.
Definition: fabuilder.h:69
fabuilder & addTransition_(std::string const &from, std::string const &to, char32_t u32symbol=U'\0')
Adds a transition to the prospective FA's state transition function.
Definition: fabuilder.cpp:295
nfa buildNfa()
Builds an NFA as defined by previous operations.
Definition: fabuilder.cpp:904
Contains the reg::dfa class definition.
fabuilder & complement(bool force=false)
Inverts the prospective DFA's language with respect to all possible strings over its alphabet...
Definition: fabuilder.cpp:795