-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdfa_unittest.cc
More file actions
38 lines (31 loc) · 1.1 KB
/
Copy pathdfa_unittest.cc
File metadata and controls
38 lines (31 loc) · 1.1 KB
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
// dfa_unittest.cc : The test for DFA project.
// Author:jinsong.van@gmail.com.
#include <iostream>
#include <string>
#include "DFA.h"
#include "Node.h"
#include "TreeConstructer.h"
int main(int argc, char* argv[]) {
// Print Lex tree.
TreeConstructer m_TreeConstructer;
Node* m_pSyntaxNode = NULL;
m_TreeConstructer.ReleaseNode(m_pSyntaxNode);
m_TreeConstructer.SetPattern("a(a|b)*c");
m_TreeConstructer.ConstructSyntaxTree(&m_pSyntaxNode);
std::cout << m_pSyntaxNode->ShowAllNode();
m_TreeConstructer.ReleaseNode(m_pSyntaxNode);
// Test DFA.
DFA dfa;
std::string reg("a(a|b)*");
std::string pat1("aadac");
std::string pat2("abad");
std::string pat3("aadadq");
dfa.RegExpToDFA(reg);
std::cout << "Regex " << reg << std::endl;
std::cout << " Match " << (dfa.Match(pat1) ? "successed! " : "failed! ") << pat1 << std::endl;
std::cout << " Match " << (dfa.Match(pat2) ? "successed! " : "failed! ") << pat2 << std::endl;
std::cout << " Match " << (dfa.Match(pat3) ? "successed! " : "failed! ") << pat3 << std::endl;
std::cout << std::endl;
std::cout << dfa.GetTreeString();
return 0;
}