reglibcpp  2.0.0
A C++ implementation of models for regular languages
gnfa.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_GNFA_H
19 #define REG_GNFA_H
20 
22 #include <memory>
23 
24 #include <string>
25 
26 #include <vector>
27 
28 #include <functional>
29 
30 #include "expression.h"
31 
32 namespace reg {
35 class gnfa {
36  public:
45  gnfa(dfa const& d);
46  gnfa(nfa const& n);
48  gnfa(gnfa const& n);
49  gnfa(gnfa&& n);
50  gnfa& operator=(gnfa const& n);
51  gnfa& operator=(gnfa&& n);
52  virtual ~gnfa();
53 
55  operator nfa const&() const;
56  bool operator==(nfa const& n) const;
57  bool operator!=(nfa const& n) const;
58  std::string const& getInitialState() const;
59  std::string const& getAcceptingState() const;
62  std::string const& p) const;
66  void bypassTransition(std::string const& q, std::string const& p);
67  void ripState(std::string const& q);
69 
70  private:
71  friend expression::operator nfa const&() const;
72  gnfa(expression const& r);
73  struct impl;
75 };
76 } // namespace reg
77 #endif
void ripState(std::string const &q)
Removes a state, bypassing all its outgoing transitions.
Definition: gnfa.cpp:423
Represents nondeterministic finite automata with ε-moves.
Definition: nfa.h:38
bool operator!=(nfa const &n) const
Checks whether this RE describes a different regular language than another object.
Definition: gnfa.cpp:490
expression::exptr getTransition(std::string const &q, std::string const &p) const
Extracts the RE labelling the transition between two states.
Definition: gnfa.cpp:278
Represents deterministic finite automata.
Definition: dfa.h:41
nfa splitAllTransitions()
Splits all transitions until only ∅, ε, and symbol REs remain and builds the resulting NFA...
Definition: gnfa.cpp:378
expression::exptr ripAllStates()
Removes all active states, constructing an RE semantically equivalent to this GNFA.
Definition: gnfa.cpp:445
std::string const & getAcceptingState() const
Reveals the name of this GNFA's accept state.
Definition: gnfa.cpp:264
Represents formal regular expressions.
Definition: expression.h:46
std::string const & getInitialState() const
Reveals the name of this GNFA's initial state.
Definition: gnfa.cpp:261
bool operator==(nfa const &n) const
Checks whether this RE describes the same regular language as another object.
Definition: gnfa.cpp:480
gnfa & operator=(gnfa const &n)
Copy-assigns this GNFA by copying another one's private implementation object.
Definition: gnfa.cpp:494
Contains the reg::expression class defintion.
state_vector splitTransition(std::string const &q, std::string const &p)
Splits a transition between two states, adding new states if needed.
Definition: gnfa.cpp:312
Represents generalized nondeterministic finite automata.
Definition: gnfa.h:35
state_vector getActiveStates() const
Reveals the names of this GNFA's non-initial, non-accepting states.
Definition: gnfa.cpp:267
Where this library lives.
Definition: dfa.cpp:48
Private implementation details of GNFAs.
Definition: gnfa.cpp:40
gnfa(dfa const &d)
Constructs a GNFA with the same states and transitions as a given DFA.
Definition: gnfa.cpp:156
state_pair_vector getSplittableTransitions() const
Reveals this GNFA's splittable transitions.
Definition: gnfa.cpp:288
std::vector< std::pair< std::reference_wrapper< std::string const >, std::reference_wrapper< std::string const > > > state_pair_vector
Nicer name for arrays of pairs names of states. Should store pairs of references to existing state na...
Definition: gnfa.h:44
void bypassTransition(std::string const &q, std::string const &p)
Removes a transition between two states and replaces it with equivalent ones, bypassing its beginning...
Definition: gnfa.cpp:401
std::vector< std::reference_wrapper< std::string const > > state_vector
Nicer name for arrays of names of states. Should store references to existing state names...
Definition: gnfa.h:39