Monday, 2 July 2007

10 questions that you should ponder on before you enter a program conversion process

10 questions that you should ponder on before you enter a program conversion process
(for ex. from Natural/ADABAS to JAVA-J2EE ORACLE).

1- What is program conversion?
- Program conversion
- Platform conversion
- operating system change (IBM MVS to UNIX)
- hardware change (for ex. from IBM mainframe to distributed workstations)
-Data conversion (for ex. from ADABAS to ORACLE)

2- What are the problems that you may encounter?
- loss of some functions that you had at the previous system
- maintainability
- you have a converted system but the lines of code has increased
three times the original, low readibility, few documentation
- you do not have the ability to create new versions by changing the
converted programs
- you can not create new versions, you are totally dependent on the program converting company on this matter
- the converted system works but very slow

3- Is program conversion an easy process?
- The realization of the conversion process may be too cumbersome.
- The conversion process may be done at sites geographically far etc…
- Using Internet may not be an option by the customer even for testing or demo purposes.
- If the process is not managed properly, you may get tangled to millions of lines of code, something missing somewhere etc…

4- What is the cost?
- You should carefully estimate the cost of having your programs converted
in comparison to rewriting them with a labor based approach… If not you may come
to questioning this point down the road anyway…
- Payments should be clear… How much you will pay for what? It should be clear how the new versions after conversion, before conversion will be payed? Some times the customer can not finalize its bottom line for the software…
- Who is going to pay for the maintenance?
- WWWill you be able to change the converted programs?

5- References of the conversion company?
-The team size?
- The qualifications of the team members etc…

6- What does the contract include?
-How will the two sides decide that the job is done?
-How many versions will be produced? Which one will be considered the first?
-What will happen to the forgotten or missing programs?
-Will you have the program development environment and be able to do small corrections?
-What is the measuring unit? How will the work done be measured and payed for?
-How will subsequent program development be done after the conversion process is finished?

7- Do you have an upto date inventory of your programs?
-How many programs, screens, tables etc. exist in your system to be converted?
-Do you have an inventory system that lists the LOC for each of these easily?
-Which programs in your inventory are redundant or out of use?
-Do you have the source code for all the active programs that you have? Are they easily manageable or are they some where that you guess you know?

8- Does your system use special character sets, calendar etc?

9 – Are you ready for a labourous testing process?
- Do you have a functional inventory?
- Do you have a minimal test plan which includes only the ‘linearly independent’ test cases in your system?…
- Have you documented critical test paths, which are crucial for your system.
- How are you planning to catch side-effects caused by moving 2-3 million lines of code from one platform to an other?

10- You may enjoy the expertise of an outsource for conversion but are you ready for handling related problems such as communication, etc?..

Friday, 29 June 2007

Notes on the use of REDUCTION in program conversion from Natural to JAVA

This is an explanation of reduction in complex statements.

There have to be two stacks. One holds the
instructions that are being processed. The other
holds the tokens in the statement.
The stack leaves are composed of two fields.

For ex:

MOVE A TO B

Requires

instruction stack:
MOVE, MOVE
Token stack:
B, MOVE-PARM2 -> TO, MOVE-TO -> A, MOVE-PARM1 -> MOVE, MOVE


This is simple as it is.
Let’s take a complex statement:

IF X = Y
MOVE A TO B
END-IF

instruction stack at first line:
IF, IF
Token stack:
X = Y, CALC -> IF, IF

instruction stack at second line:
MOVE, MOVE -> IF, IF
Token stack:
B, MOVE-PARM2 -> TO, MOVE-TO -> A, MOVE-PARM1 -> MOVE, MOVE
-> X = Y, CALC -> IF, IF

The problem here is, how are we going to convert this parsing information to
a logical meaning?

The solution is at the end of the move statement a REDUCTION should be
Made so that the token stack holds the pith of the MOVE statement, namely the
Natural statement converted to JAVA.

The solution follows:
instruction stack at the end of second line:
IF, IF
Token stack:
B = A; , MOVE-STATEMENT -> X = Y, CALC -> IF, IF

In this case, the stacks will be as below:
instruction stack at the end of third line:
nill
Token stack:
Nill

Output:
If (X==Y) {
B = A;
}


Things are not that neat though. There is a diference between a simple
MOVE statement

MOVE A TO B

And a MOVE statement in a complex statement

IF X = Y
MOVE A TO B
END-IF

The simple MOVE statement does not upush its reduction output
into the token stack but the the MOVE statement in the complex statement
does. So, just after the reduction the program checks if there are any
leaves in the instruction stack. If yes then it pushes its reduced and converted
output into the token stack.

One more note, as you may have noticed there is a need to write a pretty
Printer for the outputs.

PROBLEM: While this redduction approach feels very sensible,
it is difficult to print the source Natural lines and output JAVA lines
in sequence with this approach. The output lists the input
complex Natural statement with all its lines and then the output
complex JAVA statement as bunch…











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("");
}

Data Redefine problem in program conversion from Natural to JAVA

*S****DF 0000A 44 1#APPL-TYP-VAL
*S****DRR 0000 R1#APPL-TYP-VAL
*S****DFR 0000A 8 2#APPLID
*S****DFR 0000A 20 2#TYPE
*S****DFR 0000A 16 2#VALUE

The conversion process has to find a solution for how to
Convert the data redefines…

One open source solution from an established
IT conversion company is given below. Please
note that this solution requires a total approach
defining variable types as classes etc. This
means a large amount of substructure code
and home-keeping.


// 0000A 44 1#APPL-TYP-VAL
public final AValMem _applTypVal=newAValMem(44);

// 0000 R1#APPL-TYP-VAL
public static class DataRedefine_1 extends AValMem {

// 0000A 8 2#APPLID
public final AValMem _applid;

// 0000A 20 2#TYPE
public final AValMem _type;

// 0000A 16 2#VALUE
public final AValMem _value;

public DataRedefine_1() {
this(new AValMem(44),0);
}

public DataRedefine_1(MemoryBlock PARENT,int OFFSET) {
this(PARENT,OFFSET,true);
}

public DataRedefine_1(MemoryBlock PARENT,int OFFSET,boolean MUST_INITIALIZE) {
super(PARENT,OFFSET,44);
_applid=newAValMem(this,0,8);
_type=newAValMem(this,8,20);
_value=newAValMem(this,28,16);
}

}

public final DataRedefine_1 redefine_1=new DataRedefine_1(_applTypVal,0);

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);
}

Thursday, 28 June 2007

Actual Conversion in Converting Natural Programs to JAVA

Add statement without giving key word is chosen
to demonstrate the conversion process… The parts
related to parsing and other keyword options are
omitted.

In the conversion process, the tokens are popped
from the token stack and placed in param vars
according to their spatial positions. The JAVA
statement is assembled from these variables.
The JAVA statement is written into the output
file.

The instruction stack and the token stack are
cleaned.


void beginADDstatement()
{
…
}

void continueADDstatement(std::string tokenVal)
{
if (tokenVal == "END")
{
endADDstatementWithoutGiving();
return;
}

if (object.last(head)->meaning == "ADD")
{
…
else
//if parm2
if (object.last(head)->meaning == "ADD-TO")
{
head=object.push(head, tokenVal, "ADD-PARM2");
cout << "ADDprocessss tokenVal=" << nexttokenval=" << nextTokenVal << endl; if (objTOKEN.is_characteristic(nextTokenVal) nextTokenVal == " statement_text = "\n" statement_text =" object.last(head)-">element + statement_text;
PARM2_text = object.last(head)->element;
PARM2_text = convertVarNames(PARM2_text);

if (object.pop(head) == NULL) head = NULL;
else statement_text = object.last(head)->element + " " + statement_text;
if (object.pop(head) == NULL) head = NULL;
else
{
statement_text = object.last(head)->element + " " + statement_text;
PARM1_text = object.last(head)->element;
PARM1_text = convertVarNames(PARM1_text);
}
if (object.pop(head) == NULL) head = NULL;
else statement_text = object.last(head)->element + " " + statement_text;
if (object.pop(head) == NULL) head = NULL;

JAVA_statement_text = PARM2_text + ".add(" + PARM1_text + ");\n";

if (opened_output_file == true)
{
fputs( JAVA_statement_text.c_str(), outFile);
}

if (instrObject.pop(instrHead) == NULL) instrHead = NULL;

if (instrHead == NULL) object.stack_delete();
instrObject.stack_display(instrHead);
object.stack_display(head);
}

Calculation Parser for a Parser/Converter from Natural to JAVA

Calculation Parser
calcParse processes each token that is passed to it.
For
MOVE A + 1 TO B
Calc variable is A + 1
A + 1 is divided to
A
+
1
And these values are passed to calcParse
each time.

calcParse evaluates the value of the token first.
(It parses the calculation to parantshesis,
Operators and variable names…)
Then it pushes the token into a calcStack.

At the end the calling program pulls the evaluated calculation
Variable value from the calcStack.

int operatorList_find(string calcStatement, int i);
std::string CH;

void calcPARSE(string calcStatement)
{
…
string alphabet = "ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZ0123456789#*'-/=_%<>()";
…

calcStatement = StringToUpper(calcStatement);

for (int i=0; i < calcStatement.length(); i++)
{
CH = calcStatement.substr(i,1);

if (CH == " ") continue;
//delete all spaces in the input string
…
// first character***********************************************
if ((i==0) && (CH == "("))
{
//write OPERATOR to token stack
tokenSTACK = tokenSTACK + CH;
calcHead=calcObject.push(calcHead, "(", "LPRNTHSS");
continue;
}

//first character is right paranthesis
if ((i==0) && (CH == ")"))
{…

operatorLNGTH = operatorList_find(calcStatement, i);

//first char is alphanum
if ((i == 0) && ((CH != "(") && (operatorLNGTH == -1)))
{
//if CH is A-Z and BEG ---beg char
alphabetPOS = alphabet.find(CH,0);

if (alphabetPOS > -1)
{
charSTACK = charSTACK + CH;
}

if (i == calcStatement.length() - 1)
{
calcHead=calcObject.push(calcHead, charSTACK, "PARM");
}
continue;
}

// OPERATOR **************************************

operatorLNGTH = operatorList_find(calcStatement, i);

if (operatorLNGTH > -1)
{
i = i + operatorLNGTH - 1;
operatorLNGTH = -1;

tokenSTACK = tokenSTACK + charSTACK + CH;

if (calcObject.last(calcHead) != NULL)
{
if ( calcObject.last(calcHead)->element == ")" )
{
}
else //write previous PARM to token stack
calcHead=calcObject.push(calcHead, charSTACK, "PARM");
} //write previous PARM to token stack
else if ((i > 0) && charSTACK.length() > 0) calcHead=calcObject.push(calcHead, charSTACK, "PARM");

charSTACK = "";

//write operator to token stack
calcHead=calcObject.push(calcHead, CH, "OPERATOR");
charSTACK = "";
continue;
}

// NOT **************************************
if ( calcStatement.substr(i,3) == "NOT")
{…

//if CH is A-Z and BEG continue char*************************
alphanumPOS = alphanum.find(CH,0);

if (alphanumPOS > -1)
{
charSTACK = charSTACK + CH;

if (i == (calcStatement.length() - 1))
{ //write previous PARM to token stack
calcHead=calcObject.push(calcHead, charSTACK, "PARM");
}
continue;
}

// ( **************************************
if (CH == "(")
{…

// ) **************************************
if (CH == ")")
{…

// EOS **************************************

if (i == calcStatement.length() - 1)
{
calcHead=calcObject.push(calcHead, charSTACK, "PARM");
charSTACK = "";
continue;
}
}
//cout << "calcStatement=[" << calcStatement << "]" << endl;
//calcObject.stack_display(calcHead);
}

operatorList_find(string calcStatement, int operator_pos)
function checks whether the operator an the calcstatement
position i is a legitimate operator and converts it
to a formatted version. It handles single and double character
tokens which may appear at seperate lines…


int operatorList_find(string calcStatement, int i)
{
int operatorPos = -1;
string restCalcStatement = calcStatement.substr(i);
//cout << "i=" << i << " restCalcStatement=" << restCalcStatement << endl;
string operatorList[29] = {" * ", " / ", " + ", " - ", " %= ",
"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", " OR ", " AND "};
string operatorListBegChar[29] = {"*", "/", "+", "-", "%=",
"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", "OR", "AND"};
string operatorListBegDoubleChar[29] = {"* ", "/ ", "+ ", "- ", "%= ",
"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 ", "OR ", "AND "};
//pre-compiler conversions
for (int j =0; j < 29; j++)
{
if (i==0)
{
if (calcStatement.length() < 3)
operatorPos = restCalcStatement.find(operatorListBegChar[j], 0);
else
operatorPos = restCalcStatement.find(operatorListBegDoubleChar[j], 0);
}
else operatorPos = restCalcStatement.find(operatorList[j], 0);

if ( operatorPos == 0)
{
//cout << "J=" << j << endl;
CH = operatorList[j];
return(operatorList[j].length());
}
}
return(-1);
}

Wednesday, 27 June 2007

Statement continuation for a Parser/converter from Natural to JAVA

Statement continuation includes parsing and
conversion processes. This outline excludes
statements related to conversion and simplifies
the program generally.

// ADD A + 1 TO B GIVING C
// ADD A + 1 TO B END

void continueADDstatement(std::string tokenVal)
{
//if END
if (tokenVal == "END")
{
endADDstatementWithoutGiving();
return;
}
//if move
if (object.last(head)->meaning == "ADD")
{
if (tokenVal == "TO")
{
…
//push CONDITION from the calcSTACK to the tokenSTACK
… object.push(head,statement_text,"CALC");

head=object.push(head, tokenVal, "ADD-TO");
}
else
{
//call CONDITION processing with (tokenVal)Take in(A + 1)
calcPARSE(tokenVal);
}
}
else
//if parm2 (B)
if (object.last(head)->meaning == "ADD-TO")
{
head=object.push(head, tokenVal, "ADD-PARM2");

if (objTOKEN.is_characteristic(nextTokenVal) nextTokenVal == "END-IF") //if End of statement
{
endADDstatementWithoutGiving();
}
}
else
//if giving
if (object.last(head)->meaning == "ADD-PARM2")
{
head=object.push(head, tokenVal, "ADD-GIVING");
}
else
//if parm3
if (object.last(head)->meaning == "ADD-GIVING")
{
head=object.push(head, tokenVal, "ADD-PARM3");

// CONVERT
…

JAVA_statement_text = "" + PARM3_text + " = " + PARM2_text + " + " + PARM1_text + ";" + "\n";
…
fputs( JAVA_statement_text.c_str(), outFile);
}

if (instrObject.pop(instrHead) == NULL) instrHead = NULL;

if (instrHead == NULL) object.stack_delete();
}
}
void endADDstatementWithoutGiving()
{
…
// pop the TOKEN stack and create the output code line for MOVE
// CONVERTTTTTTTTTTTTTTTTTTTTttttttttttttttt
…
JAVA_statement_text = PARM2_text + ".add(" + PARM1_text + ");\n";

//if (head == NULL)
if (opened_output_file == true)
{
fputs( JAVA_statement_text.c_str(), outFile);
}

if (instrObject.pop(instrHead) == NULL) instrHead = NULL;

if (instrHead == NULL) object.stack_delete();
instrObject.stack_display(instrHead);
object.stack_display(head);
}

statement initiation for a parser/converter from Natural to JAVA

Statement initiation is basicly putting a leaf into the
instruction stack. The last leaf in the instruction stack
indicates the instruction that is related to the leafs in
the token stack. If reduction is used, instruction stack
becomes very useful.

void beginADDstatement()
{
string statement_text="";

head=object.push(head, "ADD", "ADD");
instrHead=instrObject.push(instrHead, "ADD", "ADD");
}

Tuesday, 26 June 2007

Implementation of a LOOK AHEAD function with C++ for a PARSER/CONVERTER

//20070318ARS Break this line into its tokens
tokenSeq = 0;

while (tokenVal != "")
{
tokenVal = objTOKEN.get_ith_token (code_line, tokenSeq);
nextTokenVal = objTOKEN.get_ith_token (code_line, tokenSeq + 1);

if (nextTokenVal == "" && tokenVal != "" && !feof( stream ))
{
filePos = ftell( stream );

if (fgets( line_lookFW, 199, stream) == NULL) cout << "could not read in LookFW" << endl;

nextTokenVal = objTOKEN.get_ith_token (line_lookFW, 0);
cout << "line_lookFW nextTokenVal=" << nextTokenVal << endl;

while (nextTokenVal == "" && !feof( stream ))
{
if (fgets( line_lookFW, 199, stream) == NULL) cout << "could not read in LookFW" << endl;
nextTokenVal = objTOKEN.get_ith_token (line_lookFW, 0);
cout << "1line_lookFW nextTokenVal=" << nextTokenVal << endl;
}
result = fseek( stream, filePos, SEEK_SET);
if (result) printf( "line_lookFW Fseek failedddddddd" );
if (nextTokenVal == "") cout << "EOFFFFFFFFFFffff" << endl;
}

if (tokenVal == "") //tokens on the line are finished
{
cout << "tokens on the line are finished" << endl;
}
else //tokens on the line are being processed.............




//20070318ARS Break this line into its tokens
tokenSeq = 0;

while (tokenVal != "")
{
tokenVal = objTOKEN.get_ith_token (code_line, tokenSeq);
nextTokenVal = objTOKEN.get_ith_token (code_line, tokenSeq + 1);

if (nextTokenVal == "" && tokenVal != "" && !feof( stream ))
{
filePos = ftell( stream );

if (fgets( line_lookFW, 199, stream) == NULL) cout << "could not read in LookFW" << endl;

nextTokenVal = objTOKEN.get_ith_token (line_lookFW, 0);
cout << "line_lookFW nextTokenVal=" << nextTokenVal << endl;

while (nextTokenVal == "" && !feof( stream ))
{
if (fgets( line_lookFW, 199, stream) == NULL) cout << "could not read in LookFW" << endl;
nextTokenVal = objTOKEN.get_ith_token (line_lookFW, 0);
cout << "1line_lookFW nextTokenVal=" << nextTokenVal << endl;
}
result = fseek( stream, filePos, SEEK_SET);
if (result) printf( "line_lookFW Fseek failedddddddd" );
if (nextTokenVal == "") cout << "EOFFFFFFFFFFffff" << endl;
}

if (tokenVal == "") //tokens on the line are finished
{
cout << "tokens on the line are finished" << endl;
}
else //tokens on the line are being processed.............