-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
87 lines (75 loc) · 2.57 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
83
84
85
86
87
#include <iostream>
#include "regex/regex.h"
#include "bt/binary_tree.h"
#include "automata.h"
#include <cstring>
using namespace std;
int main(int argc, char *argv[]) {
if (argc > 1 && ::strcmp(argv[1],"-match") == 0) {
if (argc > 2 && argv[2][0] != '-'){
run_configuration_examples(argv[2]);
}
else {
bool bnf = false;
bool reverse = false;
bool ssnf = false;
bool use_log = false;
map<string, bool> settings;
for (int i = 2; i < argc; i++) {
settings[argv[i]] = true;
}
if (argc > 2 && ::strcmp(argv[2],"-all") == 0) {
bnf = true;
reverse = true;
ssnf = true;
}
if (settings.find("-bnf") != settings.end())
bnf = true;
if (settings.find("-reverse") != settings.end()) {
reverse = true;
bnf = true;
}
if (settings.find("-ssnf") != settings.end())
ssnf = true;
if (settings.find("-log") != settings.end())
use_log = true;
string regex;
cin >> regex;
match(regex, reverse, bnf, ssnf, use_log);
}
}
else if (argc > 1 && ::strcmp(argv[1],"-test-bnf") == 0) {
run_bnf_test();
}
else {
bool use_log = false;
if (argc > 2 && ::strcmp(argv[2],"-log") == 0)
use_log = true;
string regexp_str;
cin >> regexp_str;
Regexp* regexp = Regexp::parse_regexp(regexp_str);
regexp->is_backref_correct();
auto *bnf_regex = regexp->bnf(use_log);
if (!bnf_regex->is_bad_bnf) {
auto bnf_str = bnf_regex->to_string();
cout << "BNF: " << bnf_str << endl;
auto *reverse_regex = bnf_regex->reverse();
auto reverse_str = reverse_regex->to_string();
cout << "Reverse: " << reverse_str << endl;
}
while (regexp_str != "exit") {
cin >> regexp_str;
regexp = Regexp::parse_regexp(regexp_str);
regexp->is_backref_correct();
bnf_regex = regexp->bnf(use_log);
if (!bnf_regex->is_bad_bnf) {
auto bnf_str =bnf_regex->to_string();
cout << "BNF: " << bnf_str << endl;
auto *reverse_regex = bnf_regex->reverse();
auto reverse_str = reverse_regex->to_string();
cout << "Reverse: " << reverse_str << endl;
}
}
}
return 0;
}