-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfa.hpp
35 lines (28 loc) · 998 Bytes
/
nfa.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef __NFA_HPP__
#define __NFA_HPP__
#include "dfa.hpp"
#include "fa.hpp"
#include "nfa-state.hpp"
#include <map>
#include <vector>
class NFA : public FA {
using State = std::shared_ptr<NFAState>;
static char constexpr nullTransition = '^';
private:
std::map<std::string, State> states;
std::vector<State> init;
std::ostream &print(std::ostream &) const override;
bool process(State cur, String input, int i = 0) const;
bool isStartState(String label) const;
std::string epsilonClosure(std::shared_ptr<NFAState> state);
void epsilon(std::set<std::string> &soFar, std::shared_ptr<NFAState> state);
public:
void addState(String label, bool accept) override;
void addInitialState(String label, bool accept) override;
void addTransition(String from, String to, char input) override;
bool process(String input) const override;
void unifyInitial();
void dfaHelper(DFA &dfa, String curLabel);
DFA toDFA();
};
#endif // __NFA_HPP__