Skip to content

Commit

Permalink
Expression for ORG(untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
faizal3199 committed Apr 4, 2018
1 parent 5026ca2 commit 0f8c042
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions pass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void handle_LTORG(string& litPrefix, int& lineNumberDelta,int lineNumber,int& LO
}
}

void evaluateExpression(string expression, bool& relative,string& tempOperand,int lineNumber, ofstream& errorFile){
void evaluateExpression(string expression, bool& relative,string& tempOperand,int lineNumber, ofstream& errorFile,bool& error_flag){
string singleOperand="?",singleOperator="?",valueString="",valueTemp="",writeData="";
int lastOperand=0,lastOperator=0,pairCount=0;
char lastByte = ' ';
Expand Down Expand Up @@ -71,6 +71,7 @@ void evaluateExpression(string expression, bool& relative,string& tempOperand,in
if(lastOperand*lastOperator == 1){//Check expressions legallity
writeData = "Line: "+to_string(lineNumber)+" : Illegal expression";
writeToFile(errorFile,writeData);
error_flag = true;
Illegal = true;
break;
}
Expand All @@ -94,6 +95,7 @@ void evaluateExpression(string expression, bool& relative,string& tempOperand,in
if(singleOperator.length()>1){
writeData = "Line: "+to_string(lineNumber)+" : Illegal operator in expression. Found "+singleOperator;
writeToFile(errorFile,writeData);
error_flag = true;
Illegal = true;
break;
}
Expand Down Expand Up @@ -125,12 +127,14 @@ void evaluateExpression(string expression, bool& relative,string& tempOperand,in
else{
writeData = "Line: "+to_string(lineNumber)+" : Illegal expression";
writeToFile(errorFile,writeData);
error_flag = true;
tempOperand = "00000";
relative = 0;
}
}
else{
tempOperand = "00000";
error_flag = true;
relative = 0;
}
}
Expand Down Expand Up @@ -309,6 +313,14 @@ void pass1(){
}
else if(opcode=="ORG"){
readFirstNonWhiteSpace(fileLine,index,statusCode,operand);

char lastByte = operand[operand.length()-1];
while(lastByte=='+'||lastByte=='-'||lastByte=='/'||lastByte=='*'){
readFirstNonWhiteSpace(fileLine,index,statusCode,tempOperand);
operand += tempOperand;
lastByte = operand[operand.length()-1];
}

int tempVariable;
tempVariable = saveLOCCTR;
saveLOCCTR = LOCCTR;
Expand All @@ -317,6 +329,16 @@ void pass1(){
if(SYMTAB[operand].exists=='y'){
LOCCTR = stringHexToInt(SYMTAB[operand].address);
}
else{
bool relative;
//set error_flag to false
error_flag = false;
evaluateExpression(operand,relative,tempOperand,lineNumber,errorFile,error_flag);
if(!error_flag){
LOCCTR = stringHexToInt(tempOperand);
}
error_flag = false;//reset error_flag
}
}
else if(opcode=="USE"){
// cout<<"Changing block"<<endl;
Expand Down Expand Up @@ -353,11 +375,7 @@ void pass1(){
else if(opcode=="EQU"){
readFirstNonWhiteSpace(fileLine,index,statusCode,operand);
tempOperand = "";
string singleOperand="?",singleOperator="?",valueString="",valueTemp="";
int lastOperand=0,lastOperator=0,pairCount=0;
bool relative;
char lastByte = ' ';
bool Illegal = false;

if(operand=="*"){
tempOperand = intToStringHex(LOCCTR-lastDeltaLOCCTR,6);
Expand All @@ -368,14 +386,14 @@ void pass1(){
relative = 0;
}
else{
lastByte = operand[operand.length()-1];
char lastByte = operand[operand.length()-1];

while(lastByte=='+'||lastByte=='-'||lastByte=='/'||lastByte=='*'){
readFirstNonWhiteSpace(fileLine,index,statusCode,tempOperand);
operand += tempOperand;
lastByte = operand[operand.length()-1];
}//Code for reading whole operand
evaluateExpression(operand,relative,tempOperand,lineNumber,errorFile);
evaluateExpression(operand,relative,tempOperand,lineNumber,errorFile,error_flag);
}

SYMTAB[label].name = label;
Expand Down

0 comments on commit 0f8c042

Please sign in to comment.