-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp~
95 lines (94 loc) · 2.39 KB
/
test.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
#include "automaton.h"
#include <fstream>
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
cout << "What do you want to do ? Please input the number." << endl;
cout << "1.Turn an eps-NFA to a NFA" << endl;
cout << "2.Turn an eps-NFA to a DFA" << endl;
cout << "3.Turn a NFA to a DFA" << endl;
cout << "4.Turn a FA to a right grammer" << endl;
cout << "5.Turn a FA to a left grammer ( not allow inputing Z, which keeps for special meaning )" << endl;
cout << "6.Just Draw Picture of FA" << endl;
cout << "7.Turn a FA to its regular expression ( not allow inputing X or Y, which keep for special meaning )" << endl;
cout << "8.Minimalize a DFA" << endl;
cout << "9.Turn a regular expression to a FA" << endl;
int num;
cin >> num;
if (num == 1) {
automaton a;
a.input();
automaton b = a.turn_to_NFA();
b.draw("NFA");
cout << " NFA picture has been saved at NFA.png" << endl;
}
else if (num == 2) {
automaton a;
a.input();
automaton b = a.turn_to_NFA();
automaton c = b.turn_to_DFA();
c.draw("DFA");
cout << " DFA picture has been saved at DFA.png" << endl;
}
else if (num == 3) {
automaton a;
a.input();
automaton b = a.turn_to_DFA();
b.draw("DFA");
cout << " DFA picture has been saved at DFA.png" << endl;
}
else if (num == 4) {
automaton a;
a.input();
a.output_grammer("right","right_grammer");
cout << " right grammer has been saved at right_grammer.txt" << endl;
}
else if (num == 5) {
automaton a;
a.input();
a.output_grammer("left", "left_grammer");
cout << " left grammer has been saved at left_grammer.txt" << endl;
}
else if (num == 6) {
automaton a;
a.input();
a.draw("draw");
}
else if (num == 7) {
automaton a;
a.input();
vector<string> order;
cout << "please input to-delete states in order, you can input # to automaticlly do it" << endl;
string s = "";
while (s == "") getline(cin, s);
if (s != "#") {
stringstream ss(s);
while (ss >> s) {
order.push_back(s);
}
}
a.to_reg("reg",order);
}
else if (num == 8) {
automaton a;
a.input();
a.minimalization();
a.draw("draw");
}
else if (num == 9) {
string s;
cout << "Please input the regular expression:" << endl;
cin >> s;
automaton a;
a = a.to_FA(s);
a.draw("draw");
automaton b = a.turn_to_NFA();
automaton c = b.turn_to_DFA();
c = c.simplify();
c.minimalization();
c.draw("DFA");
}
Sleep(1000);
return 0;
}