reglibcpp  2.0.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& complement(bool force = false);
59  nfa buildNfa();
60  dfa buildDfa(bool force = false);
61 
67  char const* what_arg = "Builder has nondeterministic characteristics.")
68  : std::logic_error(what_arg) {}
70  inline nondeterminism_exception(std::string const& what_arg)
71  : std::logic_error(what_arg) {}
72  };
73 
74  private:
75  struct impl;
77 };
78 } // namespace reg
79 #endif // REG_FABUILDER_H
fabuilder & operator=(fabuilder const &b)
Copy-assigns a builder by copying another one's private implementation object.
Definition: fabuilder.cpp:213
fabuilder & addSymbol(std::string const &symbol)
Adds a symbol to the prospective FA's alphabet.
Definition: fabuilder.cpp:266
Represents nondeterministic finite automata with ε-moves.
Definition: nfa.h:38
Represents deterministic finite automata.
Definition: dfa.h:41
fabuilder & intersect(nfa const &other)
Makes the prospective FA accept only words accepted also by another FA.
Definition: fabuilder.cpp:683
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:281
fabuilder & complete()
Totalizes a partial transition function by pointing any undefined transitions towards a trash state...
Definition: fabuilder.cpp:376
fabuilder & purge()
Purges the prospective FA of unreachable and non-producing states, possibly completing minimization...
Definition: fabuilder.cpp:500
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:570
dfa buildDfa(bool force=false)
Builds a DFA as defined by previous operations, including completion.
Definition: fabuilder.cpp:920
nondeterminism_exception(std::string const &what_arg)
Definition: fabuilder.h:70
fabuilder & addSymbol_(char32_t u32symbol)
Adds a symbol to the prospective FA's alphabet.
Definition: fabuilder.cpp:292
fabuilder & unite(nfa const &other)
Makes the prospective FA also accept every word of another FA&#39;s language.
Definition: fabuilder.cpp:582
fabuilder & normalizeStateNames(std::string const &prefix)
Reduces the prospective FA&#39;s state names to consecutive numbers, prefixed with a given string...
Definition: fabuilder.cpp:807
fabuilder & setAccepting(std::string const &state, bool accept)
Sets whether or not a state will be accepting within the prospective FA.
Definition: fabuilder.cpp:238
Signals that an operation requires full determinism and that no powerset construction was forced...
Definition: fabuilder.h:64
fabuilder()
Constructs a blank builder object.
Definition: fabuilder.cpp:186
Constructs NFAs step by step.
Definition: fabuilder.h:31
fabuilder & powerset()
Converts the builder's prospective NFA into a DFA via powerset construction.
Definition: fabuilder.cpp:329
fabuilder & merge(bool force=false)
Merges the prospective DFA's indistinguishable states, allowing for minimization. ...
Definition: fabuilder.cpp:432
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:256
nondeterminism_exception(char const *what_arg="Builder has nondeterministic characteristics.")
Constructs an exception object with the given message.
Definition: fabuilder.h:66
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:308
nfa buildNfa()
Builds an NFA as defined by previous operations.
Definition: fabuilder.cpp:859
Contains the reg::dfa class definition.
fabuilder & complement(bool force=false)
Inverts the prospective DFA&#39;s language with respect to all possible strings over its alphabet...
Definition: fabuilder.cpp:780