From 5026ca21d1e98cd36757523fa4c4acfeb284a2ef Mon Sep 17 00:00:00 2001 From: Faizal Hasanwala Date: Wed, 4 Apr 2018 17:48:29 +0530 Subject: [PATCH] Made seprate function for expression evaluation --- pass1.cpp | 188 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 98 insertions(+), 90 deletions(-) diff --git a/pass1.cpp b/pass1.cpp index fa18b5d..0a3567c 100644 --- a/pass1.cpp +++ b/pass1.cpp @@ -37,6 +37,103 @@ void handle_LTORG(string& litPrefix, int& lineNumberDelta,int lineNumber,int& LO } } } + +void evaluateExpression(string expression, bool& relative,string& tempOperand,int lineNumber, ofstream& errorFile){ + string singleOperand="?",singleOperator="?",valueString="",valueTemp="",writeData=""; + int lastOperand=0,lastOperator=0,pairCount=0; + char lastByte = ' '; + bool Illegal = false; + + for(int i=0;i1){ + writeData = "Line: "+to_string(lineNumber)+" : Illegal operator in expression. Found "+singleOperator; + writeToFile(errorFile,writeData); + Illegal = true; + break; + } + + if(singleOperator=="*" || singleOperator == "/"){ + lastOperator = 1; + } + else{ + lastOperator = 0; + } + + valueString += singleOperator; + } + + if(!Illegal){ + if(pairCount==1){ + /*relative*/ + relative = 1; + EvaluateString tempOBJ(valueString); + tempOperand = intToStringHex(tempOBJ.getResult()); + } + else if(pairCount==0){ + /*absolute*/ + relative = 0; + cout<1){ - writeData = "Line: "+to_string(lineNumber)+" : Illegal operator in expression. Found "+singleOperator; - writeToFile(errorFile,writeData); - Illegal = true; - break; - } - - if(singleOperator=="*" || singleOperator == "/"){ - lastOperator = 1; - } - else{ - lastOperator = 0; - } - - valueString += singleOperator; - } - - if(!Illegal){ - if(pairCount==1){ - /*relative*/ - relative = 1; - EvaluateString tempOBJ(valueString); - tempOperand = intToStringHex(tempOBJ.getResult()); - } - else if(pairCount==0){ - /*absolute*/ - relative = 0; - cout<