-
Notifications
You must be signed in to change notification settings - Fork 3
/
dfa_state.h
94 lines (65 loc) · 1.95 KB
/
dfa_state.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef LEXGEN_DFASTATE_H
#define LEXGEN_DFASTATE_H
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include "nfa_state.h"
class DFAState {
private:
static int id_counter;
int id_;
std::unordered_map<string, DFAState *> neighbours_;
std::unordered_set<NFAState *> generators_;
string combiningSymbol;
DFAState* equivState;
public:
// Constructor of the class.
DFAState();
explicit DFAState(unordered_set<NFAState *> generators);
// Getters for member variables of instance.
int get_id() const;
const unordered_map<string, DFAState *> &get_neighbours() const;
// Public functions of instance.
void AddNeighbour(const string &input, DFAState *neighbour);
DFAState* GetNeighbour(const string& input);
bool operator==(const DFAState &other) const;
virtual bool IsAcceptingState() {
return false;
};
const unordered_set<NFAState *> &get_generators() const;
string getCombiningsymbol();
void setCombiningsymbol(string& Symbol);
DFAState* getEquivstate();
void setEquivstate(DFAState* state);
void UpdateNeighbours(string symbol, DFAState * state);
virtual bool IsDeadState();
};
class DFANormalState : public DFAState {
public:
explicit DFANormalState(const unordered_set<NFAState *> &generators);
DFANormalState();
bool IsAcceptingState() override {
return false;
}
};
class DFAAcceptanceState : public DFAState {
private:
string token_name;
public:
explicit DFAAcceptanceState(const unordered_set<NFAState *> &generators, string token_name);
DFAAcceptanceState();
string get_token_name();
void set_token_name(string token_name);
bool IsAcceptingState() override {
return true;
}
};
class DFADeadState : public DFAState {
public:
DFADeadState();
bool IsAcceptingState() override {
return false;
}
bool IsDeadState() override;
};
#endif //LEXGEN_DFASTATE_H