Tuesday 26 June 2007

Main loop and process line function

Main loop
While not EOF
Check end of member file
Readline
Processline
end




Process line loop
Extract statement
Parse statement
Convert statement




Extract statement
Read line
Read tokens of the line
if the new token is characteristic break
else continue to read tokens
if EOL continue to READ line


MAIN LOOP
//20070316ARS open inputFile
if( (stream = fopen(inputFile.c_str(), "r" )) != NULL )
{
//20070316ARS read inputFile
while( !feof( stream ))
{
if (fgets( line, 199, stream) == NULL) break;
//20070316ARS process input line
StringToUpper(line);
process_line(line);

if (EndOfInput == true) break;
}

//20070316ARS close files
fclose( stream );
fclose( outFile );
}

PROCESS LINE
void process_line (std::string code_line)
{
if program header process_header_line(code_line);
else
write the input line as it is to the output file
tokenSeq = 0;

while (tokenVal != "")
{
get_ith_token(code_line, tokenSeq);
get nextTokenVal

if (tokenVal == "")
tokens on the line are finished
else
{
if (tokenVal == "*E") Signal Natural program end;

if (is_characteristic(tokenVal))
call statement initialization routine
else
token is not characteristic
a regular statement is continued

end regular statement cont
end token is not characteristic
end tokens on the line are being processed
tokenSeq = tokenSeq + 1;
end of get next token
end of IF header ELSE program code line
end of process line function





void process_line (std::string code_line)
{


//20070316ARS check whether it is program header
if program header process_header_line(code_line);
//20070316ARS normal program line not header
else
{
//20070316ARS write the input line as it is to the output file
//20070318ARS Break this line into its tokens
tokenSeq = 0;

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

}

if (tokenVal == "")
tokens on the line are finished
else //tokens on the line are being processed........
{
if (tokenVal == "*E") EndOfInput=true;
//token is the first characteristic token
if (objTOKEN.is_characteristic(tokenVal))
{
if (tokenVal == "MOVE") beginMOVEstatement();

}
else //token is not characteristic
{
if instruction stack Head is NULL
not a regular statement
else
// a regular statement is continued
if MOVE
{
continueMOVEstatement(tokenVal);
tokenSeq = tokenSeq + 1;
continue;
}
… similar statements for other commands such as IF, SUBTRACT etc…
} //end regular statement cont
} // end token is not characteristic
} // end tokens on the line are being processed
tokenSeq = tokenSeq + 1;
} //end of get next token
} //end of IF header ELSE program code line
} //end of process line function