#include #include #include void getInputs(); void defineGroups(int); int isGroupDefined(char); int isInitialState(char); int isFinalState(char); void removeFromDFA(char,char); int posofstate(char); void DFAOutput(); char G[]="({A,B,C,D,E,F,G,H},{a,b},{A},{E})",DFA_initial[50],DFA_final [50]; char *DFA_NT[50], *DFA_T[50], *DFA_Tab[50][50]; char groups[50][50], groupedStates[50]; int DFA_NTlen,DFA_Tlen,totalGrouped,totalGroup,GSlen; int main(void) { int i; totalGrouped=0; totalGroup=0; GSlen=0; getInputs(); for(i=0;i
{ defineGroups(i); } } for(i=0;i
DFAOutput(); getch(); } void getInputs() { int i=0,j=0,ct=0; char c,str[100][100]; DFA_NTlen=0; DFA_Tlen=0; //printf("Enter Grammar Definition"); //gets(G); j=2; i=0; c=' '; while(c!='}') //N-Terminal { c=G[j]; if( c!=',' && c!='}') {
str[ct][0]=G[j]; str[ct][1]='\0'; DFA_NT[i++]=str[ct++]; DFA_NTlen++; } j++; } j=j+2; i=0; c=' '; while(c!='}') //Terminal { c=G[j]; if( c!=',' && c!='}') { str[ct][0]=G[j]; str[ct][1]='\0'; DFA_T[i++]=str[ct++]; DFA_Tlen++; } j++; } j=j+2; i=0; c=' '; while(c!='}') //initial state { c=G[j]; if( c!=',' && c!='}') { c=G[j];
DFA_initial[i++]=c; } j++; } DFA_initial[i]='\0'; j=j+2; i=0; c=' '; while(c!='}') //initial state { c=G[j]; if( c!=',' && c!='}') { c=G[j]; DFA_final[i++]=c; } j++; } DFA_final[i]='\0'; i=0; printf("Input DFA Table:"); printf("\n\n\t %s",DFA_T[i++]); while(i
str[ct][1]='\0'; DFA_Tab[i][j]=str[ct++]; printf("\t\t"); } } }
void defineGroups(int i) { int j,m,n=i+1,k=0,t=0; for(m=i;m
printf("\nGrouped %s", groupedStates); } int isGroupDefined(char c) { if(strchr(groupedStates,c)==NULL) return 0; return 1; } int isInitialState(char c) { if(c == DFA_initial[0]) { return 1; } return 0; } int isFinalState(char c) { if(c == DFA_final[0]) { return 1; } return 0; } void DFAOutput() { int i,j; printf("\n\nOutput\n"); for(i=0;i
{ printf("\t%c",DFA_T[i][0]); } for(i=0;i
}
} int posofstate(char state) { int i; for(i=0;i