am I doing the right thing here?
I am making a simple lexical analyzer and in the code below, I am trying to check if there is a valid "relational operator" in the input.
The code's parameters: input stream, the position of the current pointer, the success (initialized to zero).
it is supposed to return the 'x' position where it stopped checking and the 'success' equivalent, and the string/character.
My problem is, it did not showed that it was able to detect the valid "relational operator/s".
char* Lexical::validRelOp(wxString a, int* x, int* s)
{
static char temp[100];
if (a[*x]=='<' || a[*x]=='>' ||a[*x]=='!' ||a[*x]=='=')
{
*(x++);
if (a[*x]=='=')
{
*(x++);
if (isspace(a[*x]) || isalnum(a[*x])||isOperator(a[*x])==1 || isDelimiter(a[*x])==1)
{
temp[0]=a[*x-2];
temp[1]=a[*x-1];
temp[2]='\0';
*s=1;
return temp;
}
else
{
*s=3;
return 0;
}
}
else if (isspace(a[*x]) || isalnum(a[*x]) || isOperator (a[*x]) || isDelimiter(a[*x]))
{
if (a[*(x-1)]=='<' || a[*(x-1)]=='>')
{
temp[0]=a[*x-1];
temp[1]='\0';
*s=1;
return temp;
}
if (a[*(x-1)]=='=')
{
temp[0]=a[*(x-1)];
temp[1]='\0';
*s=2;
return temp;
}
}
}
*s=0;
return 0;
}