-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDFA.cpp
More file actions
41 lines (34 loc) · 1.02 KB
/
DFA.cpp
File metadata and controls
41 lines (34 loc) · 1.02 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
38
39
40
41
#include<iostream>
using namespace std;
int main(void){
int i;
int TransactionTable[3][2] = {
{2, 1},
{2, 1},
{2, 1}
};
int StartingState, AcceptingState, State,x;
StartingState = 0;
AcceptingState = 2;
State = StartingState;
string w = "0111111110";
i = 0;
cout<<"Initial State : S"<< StartingState <<endl;
cout << "\nCurrent State\tSymbol to Process\tNext State"<<endl;
cout << "=============\t=================\t=========="<<endl;
while( i < w.length()){
x=State;
State = TransactionTable[State][(w[i] - '0')];
cout << " S"<< x <<"\t\t\t"<< w[i]-'0' <<"\t\t S"<<State<<endl;
i++;
}
cout<<"=================================================="<<endl;
cout<<"The last state we achieve after processing given string : "<<w <<" is S"<<State<<endl;
if( State == AcceptingState ){
cout <<"\n"<< w <<" is Accepted !!!"<<endl;
}
else{
cout <<"\n" <<w <<" is Rejected !!!"<<endl;
}
return 0;
}