Ask Experts Questions for FREE Help !
Ask

C++ code to convert nfa to dfa

Asked Jan 18, 2009, 12:25 AM — 2 Answers
I am looking for a c++ code to convert nfa to dfa and minimizing dfa..
Please if you have it mail me.
yesmahaa@gmail.com

2 Answers
lukymoon's Avatar
lukymoon Posts: 2, Reputation: 10
New Member
 
#2

Mar 28, 2010, 04:46 AM
I need it can help me pl z
Helpful
midophone's Avatar
midophone Posts: 1, Reputation: 1
New Member
 
#3

Jun 20, 2012, 05:44 PM
Hello, i have a home work in converting this following code of DFA to an NFA ,can any body help me??
--------------------------------------------------------------------------------------------
this program reads from a file called "dfa" contains:
q0 q1 q2
0 1
q0
q1
q1 q0
q1 q2
q2 q2
---------------------------------------------------------------------------------------------
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>


struct stt
{
char s[20];
}st;
stt a[50],del[50],seg[50],fs[50],tt[25][25];
int position(char [],stt [],int );
int main()
{

int delc,segc,fsc,ttc;
char q0[20];
int i=0,c=0,t=0;
char buf[50],bufer[100],path[20];
puts("Enter the File Path with its name");
gets(path);
fstream f;
f.open(path,ios::in);
while(f.eof!=NULL)
{
f.getline(bufer,100,'\n');
if(strcmp(bufer,"")==0) break;
i=0;int ta=0;
for(int x=0;bufer[x]!='\0';x++)
{
if (bufer[x]!=' ')
{
buf[ta]=bufer[x];
ta=ta++;
}
if ((bufer[x]==' ') || (bufer[x+1]=='\0'))
{
buf[ta]='\0';
strcpy(a[i].s,buf);
i++;
strcpy(buf,"");
ta=0;
}
}
if (c==0)
{
for(int k=0;k<=i-1;k++)
strcpy(del[k].s,a[k].s);
delc=i-1;
c=1;
}
else if (c==1)
{
for(int k=0;k<=i-1;k++)
strcpy(seg[k].s,a[k].s);
segc=i-1;
c=2;
}
else if (c==2)
{
strcpy(q0,a[i-1].s);
c=3;
}
else if (c==3)
{
for(int k=0;k<=i-1;k++)
strcpy(fs[k].s,a[k].s);
fsc=i-1;
c=4;
}
else if (c==4)
{
for(int k=0;k<=i-1;k++)
strcpy(tt[t][k].s,a[k].s);
ttc=i-1;
t=t+1;
}
}
printf("________\n");
int j;
for( j=0;j<=delc;j++)
printf("%s ",del[j].s);

printf("\n________\n");

for(j=0;j<=segc;j++)
printf("%s ",seg[j].s);

printf("\n________\n%s",q0);

printf("\n________\n");

for(j=0;j<=fsc;j++)
printf("%s ",fs[j].s);

printf("\n__***______\n");

for(i=0;i<t;i++)
{
for(j=0;j<=delc;j++)
printf("%s ",tt[i][j].s);
printf("\n");
}
f.close();

char w[50],cs[10];
strcpy(cs,q0);
puts("Enter the string w:");
gets(w);
int fl,z,ip,sp;
for( i=0;w[i]!='\0';i++)
{
fl=0;
j=0;
z=i;
while(fl==0)
{
buf[j]=w[z];
buf[++j]='\0';
for(int x=0;x<=segc&&fl==0;x++)
if (strcmp(buf,seg[x].s)==0)
{
fl=1;
// cout<<buf<<endl;
ip=position(buf,seg,segc);
sp=position(cs,del,delc);

if (strcmp(tt[sp][ip].s,"_")!=0)
strcpy(cs,(tt[sp][ip].s));

/////================================================== ========== P A T H ================================================
cout<<cs<<" ";
}
if (fl==0) z=z+1;

}
i=z;
strset(buf,NULL);
}
puts("current state is ");puts(cs);
puts("path is ");



//================================check acc/not

for(int d=0;d<=fsc;d++)
if(strcmp(fs[d].s,cs)==0)
cout<<"\nAccepted <Even>\n";
else
cout<<"\nRejected <odd>\n";
return 0;
}

int position(char x[50],stt array[50],int l )
{
int p,f=0;
for(int z=0;z<=l&&f==0;z++)
if (strcmp(x,array[z].s)==0)
{
p=z;
f=1;
}
return p;
}
Helpful

Not your question? Ask your question View similar questions

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Add your answer here.

Remove Text Formatting

Undo
Redo
 
Decrease Size
Increase Size
Bold
Italic
Underline
Align Left
Align Center
Align Right
Ordered List
Unordered List
Decrease Indent
Increase Indent
Insert Email Link
Wrap [QUOTE] tags around selected text
Wrap [CODE] tags around selected text
Wrap [HTML] tags around selected text
Wrap [PHP] tags around selected text
Wrap [YOUTUBE] tags around selected text
Notification Type:



Check out some similar questions!

Convert .MDB to .exe [ 7 Answers ]

access 97 has option to convert .MDB TO .exe Now I am using Access 2000 and using access run time Please help to find way to convert .MDB to .exe or any other ways

1989 honda civic. (code 4)crank angle sensor.(code 8) tdc position sensor [ 0 Answers ]

The car idles randomly after warm up.I check the ecu for codes and it gives 4 crank angle sensor and 8 tdc position sensor. I did a search and one of the ad posted by a guy in Canada says that he had to get part from different vehicles until he got all of them to work properly. Will I be able to...

Convert ra. To mp3. [ 1 Answers ]

Can any one tell me how to convert ra. Files to mp3. Files so that I can acess them on my i-pod?

Convert nfa to dfa [ 1 Answers ]

Please tell me how to convert nfa to dfa?

Convert .rar file to MPEG or AVI to play on DVD [ 3 Answers ]

I downloaded a file from internet in .rar format and I want to burn it and play on dvd, but for that I have to convert .rar format into MPEG or AVI format. Does anybody know how to convert .rar format into other formats. Please help me


View more C questions Search