diff --git a/pass1.cpp b/pass1.cpp index 633eb91..0df7211 100644 --- a/pass1.cpp +++ b/pass1.cpp @@ -8,7 +8,7 @@ using namespace std; bool error_flag=false; int program_length; -void handle_LTORG(string& litPrefix, int& lineNumberDelta,int lineNumber,int& LOCCTR, int& lastDeltaLOCCTR){ +void handle_LTORG(string& litPrefix, int& lineNumberDelta,int lineNumber,int& LOCCTR, int& lastDeltaLOCCTR, int currentBlockNumber){ string litAddress,litValue; litPrefix = ""; for(auto const& it: LITTAB){ @@ -21,7 +21,7 @@ void handle_LTORG(string& litPrefix, int& lineNumberDelta,int lineNumber,int& LO lineNumber += 5; lineNumberDelta += 5; LITTAB[it.first].address = intToStringHex(LOCCTR); - litPrefix += "\n" + to_string(lineNumber) + "\t" + intToStringHex(LOCCTR) + "\t" + "*" + "\t" + "="+litValue + "\t" + " " + "\t" + " "; + litPrefix += "\n" + to_string(lineNumber) + "\t" + intToStringHex(LOCCTR) + "\t" + to_string(currentBlockNumber) + "\t" + "*" + "\t" + "="+litValue + "\t" + " " + "\t" + " "; if(litValue[0]=='X'){ LOCCTR += (litValue.length() -3)/2; @@ -48,6 +48,10 @@ void pass1(){ string writeData,writeDataSuffix="",writeDataPrefix=""; int index=0; + string currentBlockName = "DEFAULT"; + int currentBlockNumber = 0; + int totalBlocks = 1; + bool statusCode; string label,opcode,operand,comment; string tempOperand; @@ -76,7 +80,7 @@ void pass1(){ // cout< SYMBOL_TABLE_TYPE; typedef map OPCODE_TABLE_TYPE; typedef map REG_TABLE_TYPE; typedef map LIT_TABLE_TYPE; +typedef map BLOCK_TABLE_TYPE; SYMBOL_TABLE_TYPE SYMTAB; OPCODE_TABLE_TYPE OPTAB; REG_TABLE_TYPE REGTAB; LIT_TABLE_TYPE LITTAB; +BLOCK_TABLE_TYPE BLOCKS; void load_REGTAB(){ REGTAB["A"].num='0'; @@ -322,7 +338,15 @@ void load_OPTAB(){ OPTAB["WD"].exists='y'; } +void load_BLOCKS(){ + BLOCKS["DEFAULT"].exists = 'y'; + BLOCKS["DEFAULT"].name = "DEFAULT"; + BLOCKS["DEFAULT"].startAddress = "?"; + BLOCKS["DEFAULT"].number=0; + BLOCKS["DEFAULT"].LOCCTR = "0"; +} void load_tables(){ + load_BLOCKS(); load_OPTAB(); load_REGTAB(); } diff --git a/utility.cpp b/utility.cpp index 7c27c81..4cff373 100644 --- a/utility.cpp +++ b/utility.cpp @@ -160,3 +160,80 @@ char getFlagFormat(string data){ } return ' '; } + +class EvaluateString{ +public: + int getResult(); + EvaluateString(string data); +private: + string storedData; + int index; + char peek(); + char get(); + int term(); + int factor(); + int number(); +}; + +EvaluateString::EvaluateString(string data){ + storedData = data; + index=0; +} + +int EvaluateString::getResult(){ + int result = term(); + while(peek()=='+' || peek() == '-'){ + if(get() == '+'){ + result += term(); + }else{ + result -= term(); + } + } + return result; +} + +int EvaluateString::term(){ + int result = factor(); + while(peek() == '*' || peek() == '/'){ + if(get()=='*'){ + result *= factor(); + } + else{ + result /= factor(); + } + } + return result; +} + +int EvaluateString::factor(){ + if(peek() >= '0' && peek() <= '9'){ + return number(); + } + else if(peek() == '('){ + get(); + int result = getResult(); + get(); + return result; + } + else if(peek()=='-'){ + get(); + return -factor(); + } + return 0; +} + +int EvaluateString::number(){ + int result = get() - '0'; + while(peek() >= '0' && peek() <= '9'){ + result = 10*result + get()-'0'; + } + return result; +} + +char EvaluateString::get(){ + return storedData[index++]; +} + +char EvaluateString::peek(){ + return storedData[index]; +}