-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
82 lines (79 loc) · 2.36 KB
/
main.cpp
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
#include <ctime>
#include "CodeGenComplier.h"
void TestRegex(const char* tPattern, const char* tText, bool Chose)
{
string Pattern(tPattern);
LexParse Lex(Pattern);
RegexParse Parse;
Parse.ParsingRegex(Lex.TokenStream);
DFA DfaMachine(Parse.GetCharMap(), Parse.GetAst(), Parse.GetAstRootIndex(), Parse.GetAstNodeList(), Parse.GetCharEndIndex());
string Text(tText);
if(DfaMachine.RunDfa(Text) == Chose)
{
cout << Pattern << "²âÊÔͨ¹ý" << endl;
}
else
{
cout << Pattern << "²âÊÔ²»Í¨¹ý" << endl;
}
}
void TestRegexTrue(const char* tPattern, const char* tText)
{
TestRegex(tPattern, tText, true);
}
void TestRegexFalse(const char* tPattern, const char* tText)
{
TestRegex(tPattern, tText, false);
}
void GetMatchContent(const char* tPattern, const char* tText)
{
string Pattern(tPattern);
LexParse Lex(Pattern);
RegexParse Parse;
Parse.ParsingRegex(Lex.TokenStream);
DFA DfaMachine(Parse.GetCharMap(), Parse.GetAst(), Parse.GetAstRootIndex(), Parse.GetAstNodeList(), Parse.GetCharEndIndex());
string Text(tText);
auto Info = DfaMachine.Match(Text);
cout << Info.MatchContent << endl;
cout << Info.StartIndex << " " << Info.EndIndex << endl;
}
int main()
{
//[a-znb]*|ab(c[a\\b]|cb+?dd)
// TestRegex("[a-znb]*|ab(c[a\\b]|cb+?dd)", "dsnbs");
//
auto start = clock();
//vector<int> ab({1,2,3,4});
//TestRegexTrue("b|a", "b");
//TestRegexTrue("[a-znb]*|ab(c[a\\b]|cb+dd)", "dsnbs");
//TestRegexTrue("[a-znb]*|1", "1");
//GetMatchContent("[a-znb]*", "ewqabcaerwrw");
// GetMatchContent("ab(c[a\\b]|cb+dd)", "ewqabcaerwrw");
/*
TestRegexTrue("a*", "aaaa");
TestRegexTrue("ba*", "b");
TestRegexTrue("a+", "a");
TestRegexTrue("a+", "aaaa");
TestRegexFalse("[^a-z]", "b");
TestRegexTrue("[a-zAB]{4,5}|ab(c[a\\b]|cb+dd)", "abcbbdd");
TestRegexTrue("a?", "aa");
TestRegexTrue("ba?", "b");
TestRegexTrue("b|a", "b");
TestRegexTrue("[a-zA]", "A");
TestRegexTrue("[a-ze1-4]", "e");
TestRegexTrue("[a-z1-4]", "3");
TestRegexTrue("[a-z1-4]", "1");
TestRegexTrue("[a-ze1-4]+", "ew421dq3");
TestRegexTrue("[a-zA-Z]", "V");
TestRegexTrue("[a-zA]", "A");
TestRegexTrue("[ABVD]", "D");
TestRegexTrue("[a-z]", "b");
TestRegexTrue("[ABVD]", "D");
TestRegexTrue("(c|b)|a", "ba");
TestRegexTrue("(c|b)|a", "ca");
TestRegexTrue("[^a-zA]", "C");*/
auto end = clock();
cout << (double)end - start;
LexCodeGen A(string("LexConfigTemplate.h"), string("LexTemplate.h"));
return 0;
}