WAP to convert regular expression
into nfa .
#include<iostream.h>
#include<conio.h>
#include<string.h>
struct
state
{
int out0;
int out1;
int oute[5];
}state[20];
void
main()
{
char c[20];
int n=0;
clrscr();
cout<<"enter the RE:";
cin>>c;
int l=strlen(c);
for(int i=0; i<=l;i++)
{
switch(c[i])
{
case '0':
{
if(c[i+1]=='+')
{
state[n].out0=n+1;
state[n+1].out0=n+1;
n++;
i++;
}
else if(c[i+1]=='*')
{
state[n].out0=n;
i++;
}
else if(c[i+1]=='0')
{
state[n].out0=n+1;
n++;
}
else if(c[i+1]=='1')
{
state[n].out1=n+1;
n++;
}
break;
}
case '1':
{
if(c[i+1]=='+')
{
state[n].out1=++n;
i++;
}
else if(c[i+1]=='*')
{
state[n].out1=n;
i++;
}
else if(c[i+1]=='0')
{
state[n].out0=++n;
break;
}
else if(c[i+1]=='1')
{
state[n].out1=++n;
break;
}
}
}//end of switch
}//end of loop
cout<<" state | 0 | 1 | E ";
for(int j=0;j<=n;j++)
{
cout<<"\n "<<j<<" | "<<state[j].out0<<"
| "<<state[j].out1;
}
getch();
}
OUTPUT: