Friday 29 June 2007

Variable Conversion in program conversion from Natural to JAVA

Natural programs have different types of variables,
namely
Local Variables,
Global Variables,
Database Table field names.

Local and global variable definitions have to be
converted and kept in new files. There has to be
a dedicated conversion program to convert variable
definitions.

Once variable definitions are converted, the output
files of this conversion process can be used to
convert the variable names in the natural program.
It is not enough to convert the instructions in the
Natural program. The variable names have to be
converted also…

An important problem in variable conversion is
DataRedefine statements in the original Natural
Programs’ variable definitions… I will write a
seperate note on this subject matter.

The programs listed below uses ready JAVA
Data structure definitions to convert Natural
programs’ var names and get their variable
lengths to be used for WRITE statements…


string convertLocalVarName(string inpToken);
string convertGlobVarName(string inpGlobalStr);


string convertVarNames(string inpStr)
{
… //convert array names
}
string convertVarNamesBody(string tokenVal)
{
… //convert var names
}
string convertLocalVarName(string inpToken)
{

}
string getLocVarLength(string lineStr, string inpToken)
{

}
string getLocRedefVarLength(string lineStr, string inpToken)
{

}
string convertGlobVarName(string inpToken)
{

}
string prepNameForTableVar(string inpStr)
{

}
string prepNameForTableVarAlternate(string inpStr)
{

}

string convertSimpleGlobalVarName(string inpToken)
{

}

--------------------------------------------------------------------------
string convertLocalVarName(string inpToken)
{
string inputFile="";
FILE *varFILE;
string progNameVar="";
string dumStr="";
string searchNameVar="";
int loc=0;
int locBeg=0;
int locEnd=0;
string varName="";
int locRedefine=0;
int locRedefineEnd=0;
string strRedefine="";
string strRedefinePrev="";
string progNameTag="";
string retVarName="";

int locLeftBracket=0;
int locRightBracket=0;
int countNest=0;
int locStaticClass=0;
string redef[10] = {"","","","","","","","","",""};
int locTablesView=0;
int locRedefineBeg=0;
string varLengthStr="";
string ThirdTokenofLineStr="";
int endInpToken=0;

string initialChar="";
int numPos=0;
int operatorPos=0;
string numbersStr = "0123456789";
string operatorStr="";

cout << "convertLocalVarName inpToken=" << inpToken << endl;
//if (inpToken.substr(0,1) != "#")
// return("");

initialChar = inpToken.substr(0,1);
numPos = numbersStr.find(initialChar,0);

if (numPos != -1) return("");

trim(inpToken);
operatorStr = toUpper(inpToken);
//cout << "inpToken=(" << operatorStr << ")" << endl;
operatorPos = operatorList_find(operatorStr, 0);
//cout << "operatorPos=" << operatorPos << endl;
if ((operatorPos > -1) (inpToken == ""))
return("");

string VAR_REF_DIR_NAME = getSetupParamVal("VAR_REF_DIR_NAME");
//Hrdb301.java --> Local_Hrdl301b.java
//Hrdp001.java --> Local_Hrdl001.java


progNameVar = progName;
progNameVar = StringToUpper(progNameVar);

if (progNameVar.substr(3,1) == "B")
{
progNameVar = "LOCAL_HRDL" + progNameVar.substr(4,3) + "B.JAVA";
}
else
{
progNameVar = "LOCAL_HRDL" + progNameVar.substr(4,3) + ".JAVA";
}

inputFile = VAR_REF_DIR_NAME + "\\" + progNameVar;
//cout << inputFile<
char line[200] = "";
string lineStr="";

if( (varFILE = fopen(inputFile.c_str(), "r" )) != NULL )
{

while( !feof( varFILE ))
{
if (fgets( line, 199, varFILE) == NULL) break;

//lineStr = StringToUpper(line);
lineStr = ConvertToString(line);
locLeftBracket = lineStr.find("{",0);
locRightBracket = lineStr.find("}",0);
if (locLeftBracket > -1) countNest = countNest + 1;
if (locRightBracket > -1) countNest = countNest - 1;
locRightBracket = lineStr.find("}",locRightBracket + 1);
if (locRightBracket > -1) {countNest = countNest - 1;}
//cout << "countNest =" << countNest << " " << lineStr;

if (countNest > 0)
{
for (int ii=countNest - 1; ii < 9; ii++) {redef[ii] = "";}
strRedefinePrev ="";
for (int jj=0; jj < 9; jj++)
{
if (redef[jj] != "") strRedefinePrev= strRedefinePrev + "." + redef[jj];
if (strRedefinePrev.substr(0,1) == ".") strRedefinePrev = strRedefinePrev.substr(1);
}
}
loc = lineStr.find(inpToken,0);

if (loc > -1)
{
//cout << "loc = " << loc << lineStr << endl;
endInpToken = lineStr.find(" ", loc + 1 );

if (endInpToken == -1) endInpToken = lineStr.find("=", loc + 1 );
if (endInpToken == -1) endInpToken = lineStr.find(";", loc + 1 );
if (endInpToken == -1) endInpToken = lineStr.find("\n", loc + 1 );
//cout << endInpToken << endl;
if ((endInpToken - loc) > 0)
//cout << "inpToken=" << lineStr.substr(loc, endInpToken - loc)<< endl;
//cout << inpToken.length()<< endl;
if ((endInpToken - loc) > inpToken.length()) loc = -1;
}
//loc = lineStr.find(inpToken,0);
//cout << line ;
if (loc > -1)
{
if (inpToken.substr(0,1) == "#")
{
varLengthStr = getLocVarLength(lineStr,inpToken);
cout << " varLengthStr=" << varLengthStr << endl;
VarLengthValueStr = varLengthStr;
fgets( line, 199, varFILE);
lineStr = ConvertToString(line);
locBeg = lineStr.find("_",0);
locEnd = lineStr.find("=",0);
if (locEnd == -1) locEnd = lineStr.find(";",0);
varName = lineStr.substr(locBeg, (locEnd - locBeg));
}
else
{
varLengthStr = getLocRedefVarLength(lineStr,inpToken);
ThirdTokenofLineStr = get_ith_token_of_string(lineStr, 3 );
locBeg = ThirdTokenofLineStr.find(inpToken, 0);

if (locBeg > -1) varName = inpToken;
else
{
varName = "";
varLengthStr = "";
}
}

if ((progName.substr(3,1) == "B") (progName.substr(3,1) == "b"))
progNameTag = "hrdl" + progName.substr(4,3) + "b";
else
progNameTag = "hrdl" + progName.substr(4,3);

//cout << "progNameTag=" << progNameTag<< endl;
//cout << "strRedefinePrev=" << strRedefinePrev<< endl;
if (varName!="")
{
if (strRedefinePrev == "")
retVarName = progNameTag + "." + varName;
else
retVarName = progNameTag + "." + strRedefinePrev + "." + varName;
}
trim(retVarName);
return(retVarName);
}

lineStr = ConvertToString(line);
locRedefine = lineStr.find("DataRedefine", 0);
if (locRedefine == -1) locRedefine = lineStr.find("TablesView", 0);
locTablesView = lineStr.find("TablesView", 0);

if (locRedefine > 0)
{
locStaticClass = lineStr.find("static class", 0);
if (locStaticClass == -1) locStaticClass = lineStr.find("public class", 0);

if (locTablesView == -1)
{
locRedefineEnd = lineStr.find(" ", locRedefine);
strRedefine = lineStr.substr(locRedefine + 4,(locRedefineEnd - locRedefine -4));
strRedefine = toLower(strRedefine);

}
else
{
locRedefineEnd = lineStr.find(" ", locTablesView);
locRedefineBeg = lineStr.find_last_of(" ", locRedefine - 1);
strRedefine = lineStr.substr(locRedefineBeg + 5,(locRedefineEnd - locRedefineBeg -4));
//strRedefine = toLower(strRedefine);
strRedefine = toLower(strRedefine.substr(0,1)) + strRedefine.substr(1);
trim(strRedefine);
};

if ((countNest > 0) && (locStaticClass > -1))
{
//cout << "countNest =" << countNest << "++++++++++++++++++++++++++++++++++++++++" << endl;
//cout << "lineStr" << lineStr << endl;
redef[countNest - 2] = strRedefine;
for (int ii=countNest - 1; ii < 9; ii++) {redef[ii] = "";}
strRedefinePrev ="";
for (int jj=0; jj < 9; jj++)
{
if (redef[jj] != "") strRedefinePrev= strRedefinePrev + "." + redef[jj];
if (strRedefinePrev.substr(0,1) == ".") strRedefinePrev = strRedefinePrev.substr(1);
//cout << jj << "=" << redef[jj] << endl;
}
//cout << "strRedefinePrev=" << strRedefinePrev << endl;
}

if (countNest == 1) strRedefinePrev ="";
}
}
fclose( varFILE );
}
return(varName);
}