-
Notifications
You must be signed in to change notification settings - Fork 4
/
NDtoD2.cpp
69 lines (58 loc) · 1.53 KB
/
NDtoD2.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
// Convert NDFA to DFA
#include<stdio.h>
#include<conio.h>
void main(){
char init[3],term[3],final[3],terminal[3]={'a','*','b'},non_term[3]={'S','U','R'},temp,temp1,temp2;
int i,index,j;
clrscr();
for(i=0;i<3;i++){
printf("Enter the values for initial symbols\t");
scanf("%s",&init[i]);
if(init[i]==non_term[0]||init[i]==non_term[1]||init[i]==non_term[2]){}
else{
printf("Enter the values for initial symbols again\t");
scanf("%s",&init[i]);
}
printf("Enter the values for terminal symbols\t");
scanf("%s",&term[i]);
if(term[i]==terminal[0]||term[i]==terminal[1]||term[i]==terminal[2]){}
else{
printf("Enter the values for terminal symbols again\t");
scanf("%s",&term[i]);
}
printf("Enter the values for final symbols\t");
scanf("%s",&final[i]);
if(final[i]==non_term[0]||final[i]==non_term[1]||final[i]==non_term[2]){}
else{
printf("Enter the values for final symbols again\t");
printf("\n");
scanf("%s",&final[i]);
}
printf("\n");
}
for(i=0;i<3;i++){
if(term[i]=='*'){
index=i;
temp=final[i];
}
}
for(i=0;i<3;i++){
if(init[i]==temp){
temp1=term[i];
temp2=final[i];
}
}
term[index]=temp1;
final[index]=temp2;
printf("Terminal Symbols after conversion \n");
for(j=0;j<3;j++){
if(term[j]==term[j+1]){}
else
printf("%c \n",term[j]);
}
printf("\n Non terminal Symbols after conversion \n");
for(i=0;i<3;i++){
printf("%c \n",init[i]);
}
getch();
}