hi, I coded nfa to dfa program
Code:
#include <iostream>
using namespace std;
int main()
{
char **dfa_trans = 0;
dfa_trans = new char *[3];
for (int i=0;i<3;i++)
{
dfa_trans[i]=new char[2];
}
char **nfa_trans=0;
nfa_trans=new char *[3];
for (int i=0;i<3;i++)
{
nfa_trans[i]=new char[2];
}
char *dfa_state=0;
dfa_state=new char [3];
char *nfa_state=0;
nfa_state=new char [3];
char *dfa_start=0;
dfa_start=new char [3];
char *Alphabet=0;
Alphabet=new char [3];
int i,j,k,n_alphabet,n_nfastate,e=0,c=0,temp=0;
char nfa_start;
cout<<"please enter the number of alphabes you wish to use: "<<end1;
cin>>n_alphabet;
cout<<"please enter alphabets.Note: e stands for ebsilon" <<end1;
for (i=0;i<n_alphabet;i++)
cin>>Alphabet[i];
cout<<"please enter the number of states you need to use: "<<end1;
cin>>n_nfastate;
cout<<"enter name of states" <<end1;
for (i=0;i<n_alphabet;i++)
cin>>nfa_state[i];
cout<<"please enter your start state: "<<end1;
cin>>nfa_start;
cout<<"enter * if you don't wish to use an alphabet" <<end1;
for (j=0;j<n_nfastate;j++)
{
cout<<"at state "<<nfa_state[j];
for(i=0;i<n_alphabet;i++)
{
cout<<" if alphabet "<<" ' "<<alphabet[i]<<" ' "<<" go to: "
;
cin>>nfa_trans[i] [j];
if (Alphabet[i]=='e' && nfa_trans[i] [j] ! = '*')
{
e++;
dfa_start[e-1]=nfa_state[j];
}
}
}
cout<<"****************e= "<<e<<end1;
for(k=0;k<e;k++)
{
if(dfa_start[k]!=nfa_start)
{
c++;
}
}
if(c==e)
}
dfa_start[e]=nfa_start;
e++;
}
for(k=0;k<e;k++)
if(dfa_start[e-1]<dfa_start[k])
{
temp=dfa_start[k];
dfa_start[k]=dfa_start[e-1];
dfa_start[e-1]=temp;
}
cout<<"e= "<<e<<end1;
cout<<Dfa states:"<<end1;
for(k=0;k<e;k++)
{
cout<<dfa_start[k]<<end1;
}
cout<<"your nfa transition function is the following:"<<end1;
for(j=0 ; j<n_nfastate ; j++)
{
cout<<end1;
for(i=0;i<n_alphabet;i++)
{
cout<<nfa_trans[i] [j]<<" ";
}
cout<<end1;
}
cout<<"Dfa transition function:"<<end1;
for(k=0;k<e;k++)
{
for(i=0;i<n_alphabet-1;i++)
{
if(Alphabet[i]!='e' && nfa_trans[i][k]=='*')
{
nfa_trans[i][k]=dfa_start[k];
}
cout<<"at state "<<" "<<dfa_start[k]<<" at alphabet "<<" ' "<<Alphabet[i]<<" ' "<<" go to: "<<nfa_trans[i][k]<<end1;
}
}
cout<<end1;
return 0;
}
but this have errors, please debug this code and make true the bugs, thank you my friends