-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
99 lines (85 loc) · 2.89 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
88
89
90
91
92
93
94
95
96
97
98
99
#include "internal/glushkov-automaton.hpp"
#include "internal/powerset-construction.hpp"
#include "internal/dfa-minimization.hpp"
// function that prints the instructions for using the tool
void print_help(char** argv) {
std::cout << std::endl <<
"Usage: " << argv[0] << " [regexp] [options]" << std::endl
<< "Tool to compute an automaton out of a regexp." << std::endl << std::endl
<< " -n, --NFA" << std::endl
<< " Compute the Glushkov automaton (NFA eps-free)." << std::endl
<< " -d, --DFA" << std::endl
<< " Compute the Glushkov DFA running the powerset construction algorithm." << std::endl
<< " -m, --DFAmin" << std::endl
<< " Compute the minimized Glushkov DFA." << std::endl
<< " -v, --verbose" << std::endl
<< " Activate the verbose mode." << std::endl
<< std::endl;
}
// function for parsing the input arguments
void parseArgs(int argc, char** argv, Args& arg) {
if(argc < 3){ print_help(argv); exit(1); }
// read regexp
arg.regexp = std::string(argv[1]);
// read and parse input parameters
for(int i=2;i<argc;++i)
{
std::string param = argv[i];
if( param == "-n" or param == "--NFA" )
{
arg.NFA = true;
}
else if( param == "-d" or param == "--DFA" )
{
arg.DFA = true;
}
else if( param == "-m" or param == "--DFAmin" )
{
arg.DFAmin = true;
}
else if( param == "-v" or param == "--verbose" )
{
arg.verbose = true;
}
else if( param == "-h" or param == "--help" )
{
print_help(argv); exit(1);
}
else
{
std::cerr << "Unknown option. Use -h for help." << std::endl;
exit(-1);
}
}
// check mode
uint32_t counter = (int)arg.NFA + (int)arg.DFA + (int)arg.DFAmin;
if(counter != 1)
{
std::cerr << "Please select one option out of NFA|DFA|DFAmin" << std::endl;
exit(1);
}
}
int main(int argc, char *argv[])
{
// read arguments
Args arg;
parseArgs(argc, argv, arg);
if( arg.NFA )
{
compute_glushkov_automaton(arg.regexp,sigma,arg.verbose,true);
}
else if( arg.DFA )
{
NFA* glushkov_automaton = compute_glushkov_automaton(arg.regexp,sigma,arg.verbose,false);
compute_powerset_construction(glushkov_automaton,arg.verbose,true);
}
else if( arg.DFAmin )
{
NFA* glushkov_automaton = compute_glushkov_automaton(arg.regexp,sigma,arg.verbose,false);
NFA* glushkov_dfa = compute_powerset_construction(glushkov_automaton,arg.verbose,false);
delete glushkov_automaton;
if(arg.verbose) std::cout << "###### Minimized DFA to stdout:" << std::endl;
minimize_DFA(glushkov_dfa);
}
return 0;
}