The flowchart is on the attachment. Please check it out
I also get this error:
error: cannot convert `__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >' to `char' in assignment|
/***************************************************
The following program will take user's input
and check whether it is in the following language:
<S> ---> a <B> | <A> | b
<A> ---> c <A> | c
<B> ---> d | <A>
****************************************************/
#include<iostream>
#include<string>
using namespace std;
#include<stdlib.h> // for the exit(1) function
char* SProd(char* ThisOne ); // <S> --> a <B> | <A> | b
char* AProd(char* ThisOne ); // <A> --> c <A> | c
char* BProd(char* ThisOne ); // <B> --> d | <A>
char* XProd(char* ThisOne, char x);
int main()
{
string text;
char *ThisOne;
cout<<"Enter a string"<<endl;
cin>>text;
*ThisOne = text.begin();
ThisOne = SProd(ThisOne);
if(*ThisOne== '\0') //Check whether there is an extra character at the end
cout<<"valid"<<endl;
else
cout<<"Invalid"<<endl;
system("pause");
return 0;
}
char* XProd(char* ThisOne, char x)
{
ThisOne = XProd(ThisOne, 'a');
ThisOne = XProd(ThisOne, 'b');
ThisOne = XProd(ThisOne, 'c');
ThisOne = XProd(ThisOne, 'd');
return ThisOne;
}
// <S> --> a <B> | <A> | b
char* SProd(char* ThisOne )
{
if (*ThisOne == 'b')
{
ThisOne++;
return ThisOne;
}
else {
if (*ThisOne == 'a')
{
ThisOne++;
ThisOne = BProd(ThisOne);
return ThisOne;
}
else
{
ThisOne = AProd(ThisOne);
return ThisOne;
}
}
}
// <A> --> c <A> | c
char* AProd(char* ThisOne)
{
if(*ThisOne != 'c')
{
cout<<"Invalid"<<endl;
exit(1);
}
else
{
ThisOne++;
while (*ThisOne == 'c')
ThisOne++;
return ThisOne;
}
}
// <B> --> d | <A>
char* BProd(char* ThisOne)
{
if(*ThisOne = 'd')
{
ThisOne++;
return ThisOne;
}
else
{
AProd(ThisOne);
}
}