Wednesday, May 5, 2010

Write a program to convert Regular Expression to NFA.

#include
#include
#include
#include

void main()
{
clrscr();
char c[20];
int a[10][2];
int l,n=0,s=0,t;
cout<<"Enter the string:";
cin>>c;
l=strlen(c);
for(int f=0;f {
if(c[f]=='+')
{
s++;
}
}
n=s+1;
cout<<"Thus states="< for(int i=0;i {
t=1;
a[i][1]=t;
a[i][2]=(t-1);
t++;
if(i>=1)
{
a[i][2]=n-2;
if(i==2)
{
a[i][1]=n-1;
a[i][2]=n-1;
}
}
}
cout<<"\n\n\tNFA\n\n";
cout<<"state \t"<<"a\t"<<"b\t";
for(int j=0;j {
cout<<"\nq"< if(j==1)
{
cout<<",q"< }
cout<<"\t"<<"q"< }
getch();
}

5 comments: