-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdfa.h
57 lines (49 loc) · 1.53 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
#ifndef _DFA_H
#define _DFA_H
#include "nfa.h"
#include <vector>
#include<queue>
#include<set>
using namespace std;
class DFA_Status
{
public:
DFA_Status():IsFinal(false){}
DFA_Status(Status* status):IsFinal(false){ add_nfa(status); } //�Ե���NFA״̬����DFA״̬
set<Status*> status_set; //��ӦNFA��״̬
void add_nfa(Status* status){ status_set.insert(status); if (status->IsFinal)IsFinal = true; } //����NFA״̬
bool IsFinal;
};
class DFA_Edge
{
public:
DFA_Edge(DFA_Status* b, _MatchContent content, DFA_Status* e) :Begin(b), MatchContent(content), End(e){}
_MatchContent MatchContent;
DFA_Status* Begin;
DFA_Status* End;
};
class StateSet
{
public:
StateSet(){}
StateSet(const StateSet& _set){ Set.insert(Set.end(), _set.Set.begin(), _set.Set.end()); }
~StateSet(){}
public:
vector<Status*> Set;
void add_state(Status* state){ Set.push_back(state); }
bool operator==(const StateSet& _set);
};
class DFA
{
public:
DFA(NFA& nfa){ constructDFA(nfa); }
~DFA(){}
void _test(){ cout << AllEdges.size() <<endl<< AllStatus.size(); }
void constructDFA(NFA& nfa);
vector<DFA_Edge*> AllEdges;
vector<DFA_Status*> AllStatus;
};
DFA_Edge* make_edge(DFA_Status* b, _MatchContent content, DFA_Status* e);
int is_status_exist(DFA_Status* dfa_status, vector<DFA_Status*>& d); //��d����Ѱ�Ƿ���dfa_status�Ĵ��ڣ�ע��DFA״̬�������ָ���������е�NFA״̬һ�£�
bool is_dfa_status_equal(const DFA_Status* status1,const DFA_Status* status2);
#endif