#include<iostream.h>
#include<conio.h>
#include<string.h>
enum position{true,false};
int main()
{
clrscr();
enum position postn=true;
char*str;
cout<<"Place an input string:: ";
cin>>str;
int lng=strlen(str);
for(int
count=0;count<lng-1;count++)
{
if(*str=='a'
&& count%2==0)
{
postn=true;
}
else
if(*str=='b' && count%2==1)
{
postn=true;
}
else
if(*str=='a' && count%2==1)
{
postn=false;
break;
}
str++;
}
if(*str=='b'
&& postn==true)
{
cout<<"\nInput string belongs to the given grammar";
}
else
cout<<"\nInput
string does not belong to given grammar";
getch();
return 0;
0 Comments