-
Notifications
You must be signed in to change notification settings - Fork 1
/
regex_parser.h
48 lines (36 loc) · 1.2 KB
/
regex_parser.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
//
// Created by xvvx on 18-4-1.
//
#ifndef REGEXENGINE_PARSER_H
#define REGEXENGINE_PARSER_H
#include <sstream>
#include "nfa.h"
#include "dfa.h"
using std::string;
using std::stringstream;
class RegexParser {
public:
Nfa *ParseToNfa(const string ®ex){
stringstream regex_stream(regex);
NfaComponent *component = ParseRegex(regex_stream);
Nfa *nfa = new Nfa(component);
return nfa;
}
Dfa *ParseToDfa(const string ®ex) {
auto nfa = ParseToNfa(regex);
auto beg_node = dfa_constructor::ConvertNfaToDfa(nfa);
auto dfa = new Dfa(beg_node);
return dfa;
}
public:
NfaComponent *ParseRegex(stringstream ®ex_stream);
NfaComponent *ParseSimpleRegex(stringstream ®ex_stream);
NfaComponent *ParseBasicRegex(stringstream ®ex_stream);
NfaComponent *ParseElementary(stringstream ®ex_stream);
NfaComponent *ParseGroup(stringstream ®ex_stream);
NfaComponent *ParseSet(stringstream ®ex_stream);
NfaComponent *ParseSetItems(stringstream ®ex_stream);
NfaComponent *ParseSetItem(stringstream ®ex_stream);
NfaComponent *ParseEscape(stringstream ®ex_stream);
};
#endif //REGEXENGINE_PARSER_H