Friday 29 June 2007

Operator conversion in a calculation for Natural to JAVA program conversion

condConvert converts all the operators
in a given calculation.


string condConvert(string inpCond)
{

}
string checkSeperatingOperator(string inpToken)
{

}
string convertOperator(string inpToken)
{

}



string checkSeperatingOperator(string inpToken);
string convertOperator(string inpToken);

string condConvert(string inpCond)
{

//inpCond = " A NE 'B'";
//inpCond = "#SITE-A NE AAA";
//inpCond = "NOT A = B";
//inpCond = "A";
//inpCond = "NOT DEVICE = BATCH";

string inpCondToken="AAA";
string seperatingOperator = "";
int tokenSeq =0;
int seperatingOperatorPOS =0;
int notPOS = 0;
string outputCond="";
string begInpCond = "";
string endInpCond = "";
string convertedSeperatingOperator= "";

cout << "inpCond=" << inpCond << endl;
inpCond = eraseNewLine(inpCond);

while (inpCondToken != "")
{
inpCondToken = get_ith_token_of_string(inpCond, tokenSeq);
cout << "inpCondToken=" << inpCondToken << endl;
if (seperatingOperator == "")
{
seperatingOperator = checkSeperatingOperator(inpCondToken);
seperatingOperatorPOS = inpCond.find(seperatingOperator, 0);
}

notPOS = inpCond.find("NOT" , 0);

if (notPOS == -1) notPOS = inpCond.find("not" , 0);

tokenSeq = tokenSeq + 1;
}

cout << "seperatingOperator=" << seperatingOperator << " seperatingOperatorPOS=" << seperatingOperatorPOS << endl;
cout << "notPOS=" << notPOS << endl;

if (notPOS > -1)
{
inpCond = inpCond.substr(notPOS + 3);
cout << "inpCond=" << inpCond << endl;
seperatingOperatorPOS = seperatingOperatorPOS - 4;
}
begInpCond = inpCond.substr(0, seperatingOperatorPOS);
cout << begInpCond << endl;
endInpCond = inpCond.substr(seperatingOperatorPOS + seperatingOperator.length());
cout << endInpCond << endl;
convertedSeperatingOperator = convertOperator(seperatingOperator);
cout << convertedSeperatingOperator << endl;
trim(begInpCond);
trim(endInpCond);
if (notPOS == -1)
outputCond = begInpCond + "." + convertedSeperatingOperator + "(" + endInpCond + ")";
else
outputCond = "!(" + begInpCond + "." + convertedSeperatingOperator + "(" + endInpCond + "))";
outputCond = convertCharInString(outputCond, '\'', '\"');
cout << "outputCond=" << outputCond << endl;


return(outputCond);
}
string checkSeperatingOperator(string inpToken)
{
string seperatingOperatorList[23] = {"%=",
"EQUAL TO", "EQUAL TO", "EQ", "<=", "<>",
"NE", "NOT =", "NOT EQUAL TO", "NOT EQUAL", "EQUAL",
"<", "LT", "LESS THAN", ">", "LE",
"LESS EQUAL", ">=", "GT", "GREATER THAN", "=",
"GE", "GREATER EQUAL"};
int operatorPos = -1;

for (int j =0; j < 23; j++)
{
operatorPos = inpToken.find(seperatingOperatorList[j], 0);
if (operatorPos > -1) return(seperatingOperatorList[j]);
}
return("");
}
string convertOperator(string inpToken)
{
string seperatingOperatorList[23] = {"%=",
"EQUAL TO", "EQUAL TO", "EQ", "<=", "<>",
"NE", "NOT =", "NOT EQUAL TO", "NOT EQUAL", "EQUAL",
"<", "LT", "LESS THAN", ">", "LE",
"LESS EQUAL", ">=", "GT", "GREATER THAN", "=",
"GE", "GREATER EQUAL"};
string convertedOperatorList[23] = {"eq",
"eq", "eq", "eq", "le", "ne",
"ne", "ne", "ne", "ne", "eq",
"lt", "lt", "lt", "gt", "le",
"le", "ge", "gt", "gt", "eq",
"ge", "ge"};
int operatorPos = -1;

for (int j =0; j < 23; j++)
{
operatorPos = inpToken.find(seperatingOperatorList[j], 0);
if (operatorPos > -1) return(convertedOperatorList[j]);
}
return("");
}