-
Notifications
You must be signed in to change notification settings - Fork 0
/
DFA.h
62 lines (54 loc) · 1.38 KB
/
DFA.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef _DFA_H_
#define _DFA_H_
#define DOT '.'
#include <string>
#include <vector>
#include <set>
#include <map>
using std::string;
using std::vector;
using std::map;
using std::set;
class State {
public:
map<string,int> transitions;
bool accepting;
State() {}
State(bool a): accepting(a) {}
State(const State &o): transitions(o.transitions),
accepting(o.accepting) {}
~State() {}
};
class DFA {
public:
int start;
int active;
set<string> alphabet;
vector<State> states;
DFA(set<string> a, int s): start(0),
active(0),
alphabet(a),
states(s) {}
DFA(const DFA &o): start(o.start),
active(o.active),
alphabet(o.alphabet),
states(o.states) {}
~DFA() {}
/* swaps final states */
void complement();
/* define the start state */
void set_start(int);
/* choose whether a state is accepting */
void set_accept(int, bool);
/* reset for reading a new string */
void reset();
/* adds a new (accepting?) state and returns its index */
int add_state(bool);
/* x --str--> y */
void updateTransition(int, string, int);
/* reads character or string */
void read(string);
bool accept();
string print();
};
#endif