-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
117 lines (106 loc) · 3.55 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <string>
#include <iostream>
#include "Transition.h"
#include "DFA.h"
using namespace std;
/*
// for Q1
// COPY THAT
string Q0 = "q0"; // start state
string q[] = { "q0", "q1", "q2", "q3", "q4", "q5" }; // the exisiting state
char s[] = { 'a', 'b', 'c' }; // the existing letters
Transition t[] =
{
Transition("q0", 'a', "q1"),
Transition("q0", 'b', "q2"),
Transition("q0", 'c', "q4"),
Transition("q1", 'a', "q1"),
Transition("q1", 'b', "q5"),
Transition("q1", 'c', "q3"),
Transition("q2", 'a', "q5"),
Transition("q2", 'b', "q2"),
Transition("q2", 'c', "q3"),
Transition("q3", 'a', "q5"),
Transition("q3", 'b', "q5"),
Transition("q3", 'c', "q5"),
Transition("q4", 'a', "q5"),
Transition("q4", 'b', "q5"),
Transition("q4", 'c', "q4"),
}; // all exisint transitions
string f[] = { "q3", "q4" }; // the final states
// for Q2
// COPY THAT
string Q0 = "q0"; // start state
string q[] = { "q0", "q1", "q2", "q3" }; // the exisiting state
char s[] = { 'a', 'b' }; // the existing letters
Transition t[] =
{
Transition("q0", 'a', "q1"),
Transition("q0", 'b', "q0"),
Transition("q1", 'a', "q1"),
Transition("q1", 'b', "q2"),
Transition("q2", 'a', "q1"),
Transition("q2", 'b', "q3"),
Transition("q3", 'a', "q1"),
Transition("q3", 'b', "q0")
}; // all exisint transitions
string f[] = { "q3" }; // the final states
*/
void main()
{
// main data decleration
// this part is to be edited in order to change from machine to another
// PASTE HERE
string Q0 = "q0"; // start state
string q[] = { "q0", "q1", "q2", "q3", "q4", "q5" }; // the exisiting state
char s[] = { 'a', 'b', 'c' }; // the existing letters
Transition t[] =
{
Transition("q0", 'a', "q1"),
Transition("q0", 'b', "q2"),
Transition("q0", 'c', "q4"),
Transition("q1", 'a', "q1"),
Transition("q1", 'b', "q5"),
Transition("q1", 'c', "q3"),
Transition("q2", 'a', "q5"),
Transition("q2", 'b', "q2"),
Transition("q2", 'c', "q3"),
Transition("q3", 'a', "q5"),
Transition("q3", 'b', "q5"),
Transition("q3", 'c', "q5"),
Transition("q4", 'a', "q5"),
Transition("q4", 'b', "q5"),
Transition("q4", 'c', "q4"),
}; // all exisint transitions
string f[] = { "q3", "q4" }; // the final states
/*this part don't change no matter what*/
list<string> Q; // list of the states
list<char> Sigma; // list of the letters
list<Transition> Delta; // list of all avilable transitions
list<string> FinalState; // list of all final states
list<string>::iterator it1 = Q.begin(); // an iterator to save the states from the array to the list
for (int i = 0, arraySize = sizeof(q)/sizeof(q[0]); i < arraySize; i++)
{
Q.insert(it1, q[i]); // inserting it into the list
}
list<char>::iterator it2 = Sigma.begin(); // an iterator to save the letters from the array to the list
for (int i = 0, arraySize = sizeof(s) / sizeof(s[0]); i < arraySize; i++)
{
Sigma.insert(it2, s[i]); // inserting it into the list
}
list<Transition>::iterator it3 = Delta.begin(); // an iterator to save the letters from the array to the list
for (int i = 0, arraySize = sizeof(t) / sizeof(t[0]); i < arraySize; i++)
{
Delta.insert(it3, t[i]); // inserting it into the list
}
list<string>::iterator it4 = FinalState.begin();
for (int i = 0, arraySize = sizeof(f) / sizeof(f[0]); i < arraySize; i++)
{
FinalState.insert(it4, f[i]); // inserting it into the list
}
// TEST #1 on the whole system
DFA x = DFA(Q, Sigma, Delta, Q0, FinalState);
// test cases
x.Accepts("aaaabc");
system("PAUSE");
}