static void DumpIntermidiateFile(string filePath, List <ExpresionLine> expresionLines, Globals.DataStructures dataStructures) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath + ".tmp")) { Chronicler.HoldOutput(); int curLinNum = 0; foreach (ExpresionLine expLine in expresionLines) { if (expLine != null && expLine.OriginalLine != null && expLine.OriginalLine != "") { curLinNum = expLine.lineNumber; file.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { file.Write(expLine.locationCounter.ToString("X6") + "\t"); } file.Write(expLine.OriginalLine); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { Chronicler.Write(expLine.locationCounter.ToString("X6") + "\t"); } Chronicler.WriteLine(expLine.OriginalLine); } } foreach (LiteralTable.LiteralValue lv in dataStructures.literalTable.literalTable) { curLinNum++; file.Write(curLinNum.ToString() + "\t"); file.Write(lv.address.ToString("X6") + "\t"); file.Write("*" + "\t"); file.Write(lv.label); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); Chronicler.Write(lv.address.ToString("X6") + "\t"); Chronicler.Write("*" + "\t"); Chronicler.WriteLine(lv.label); } } Chronicler.HoldOutput(); dataStructures.symbolTable.Print(); Chronicler.HoldOutput(); dataStructures.literalTable.PrintTable(); }
public bool addSymbol(string label, bool rflag, int value, string currentLine) { label = label.Trim(); if (ValidateLabel(label, currentLine, "Pass One adding symbol")) { Globals.Symbol newSym = default; newSym.label = label; if (newSym.label.Length > 6) { newSym.label = newSym.label.Substring(0, 6); } newSym.RFlag = rflag; newSym.value = value; newSym.MFlag = false; if (SymbolTableBST.ContainsKey(newSym.label)) { Chronicler.LogError("Symbol with same Label('" + newSym.label + "') already exists! Setting MFlag and \n\tskipping: \"" + currentLine + "\"" + "\n", "Adding Symbol"); Globals.Symbol sym = SymbolTableBST.GetValueOrDefault(newSym.label); if (sym.MFlag == false) { sym.MFlag = true; SymbolTableBST.Remove(newSym.label); SymbolTableBST.Add(newSym.label, sym); } return(false); } else { Chronicler.Write("Adding symbol: ", Chronicler.OutputOptions.INFO); newSym.Print(Chronicler.OutputOptions.INFO); SymbolTableBST.Add(newSym.label, newSym); } } else { return(false); } return(true); }
//************************************************************************ //*** FUNCTION PrintTable //*** ******************************************************************** //*** DESCRIPTION : prints the current contents of the literal table //*** INPUT ARGS : N/A //*** OUTPUT ARGS : N/A //*** IN/OUT ARGS : N/A //*** RETURN : N/A //************************************************************************ public void PrintTable(Chronicler.OutputOptions outputOptions = Chronicler.OutputOptions.IGNORE) { Chronicler.WriteLine("NAME\t\tVALUE\t\tLENGTH\tADDRESS", outputOptions); Chronicler.WriteLine("===============================================", outputOptions); StringBuilder sb = new StringBuilder(""); foreach (LiteralValue lv in literalTable) { sb.Clear(); for (int x = 0; x < (16 - lv.label.Length); x++) { sb.Append(" "); } Chronicler.Write(lv.label + sb.ToString(), outputOptions); sb.Clear(); for (int x = 0; x < (16 - lv.hexValue.Length); x++) { sb.Append(" "); } Chronicler.Write(lv.hexValue + sb.ToString(), outputOptions); Chronicler.Write(lv.Length.ToString(), outputOptions); Chronicler.WriteLine("\t" + lv.address.ToString("X6"), outputOptions); } }
public static void Execute(Globals.DataStructures dataStructures, List <PassOne.ExpresionLine> expresionLines, string filePath) { Chronicler.Write("\nPassTwo\n"); foreach (PassOne.ExpresionLine expresionLine in expresionLines) { //evaluate expresion if (expresionLine.DeferExpresionResolutiontoPass2 && (expresionLine.instructionFormat == 3 || expresionLine.instructionFormat == 4)) { if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, expresionLine.operandFieldAndComment, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } } //convert expresion format if (expresionLine.Opcode == "" && expresionLine.IsEQU != true && (expresionLine.instructionFormat == 3 || expresionLine.instructionFormat == 4))//don't redo work { switch (expresionLine.expresionData.ExpresionType) { case Globals.ExpresionData.Contents.SYMBOL: int?value = null; if (expresionLine.expresionData.second.HasValue) { if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.SUBTRACT) { value = (expresionLine.expresionData.first.Value.value) - expresionLine.expresionData.second.Value.value; } if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.ADD) { value = (expresionLine.expresionData.first.Value.value) + expresionLine.expresionData.second.Value.value; } } if (value.HasValue && expresionLine.instructionFormat == 4) { expresionLine.Opcode = value.Value.ToString("X5"); } else if (value.HasValue && expresionLine.instructionFormat == 3) { expresionLine.Opcode = value.Value.ToString("X3"); } break; case Globals.ExpresionData.Contents.ERROR: Chronicler.WriteLine("This is wrong for some reason, you should look at it:\n" + expresionLine.OriginalLine, Chronicler.OutputOptions.ERR); break; case Globals.ExpresionData.Contents.LITERAL: if (expresionLine.expresionData.literal.isOldStyleLiteral != true) { expresionLine.Opcode = expresionLine.locationCounter.ToString("X6"); } break; case Globals.ExpresionData.Contents.EMPTY: //consider break break; } } if (expresionLine.operationData.HasValue && expresionLine.operationData.Value.format == 2) { string[] tmp = expresionLine.operandFieldAndComment.Split(";", StringSplitOptions.RemoveEmptyEntries); if (tmp.Length > 0) { expresionLine.operandFieldAndComment = tmp[0]; } string[] subStrs = expresionLine.operandFieldAndComment.Split(",", StringSplitOptions.RemoveEmptyEntries); if (subStrs.Length == 1) { int val; if (dataStructures.opcodeTable.RegisterTable.TryGetValue(subStrs[0].Trim(), out val)) { expresionLine.Opcode = val.ToString(); } else { Chronicler.LogError("failed parsing F2: " + expresionLine.OriginalLine); } } else if (subStrs.Length == 2) { int val; if (dataStructures.opcodeTable.RegisterTable.TryGetValue(subStrs[0].Trim(), out val)) { expresionLine.Opcode = val.ToString() + "0"; } else { Chronicler.LogError("failed parsing F2: " + expresionLine.OriginalLine); } if (dataStructures.opcodeTable.RegisterTable.TryGetValue(subStrs[1].Trim(), out val)) { expresionLine.Opcode += val.ToString(); } else { Chronicler.LogError("failed parsing F2: " + expresionLine.OriginalLine); } } else { Chronicler.LogError("failed parsing F2, incorect term count: " + expresionLine.OriginalLine); } } if (expresionLine.operationData.HasValue) { expresionLine.Opcode = expresionLine.operationData.Value.code.ToString("X") + expresionLine.Opcode; } } DumpObjFile(filePath, expresionLines, dataStructures); }
static void DumpObjFile(string filePath, List <PassOne.ExpresionLine> expresionLines, Globals.DataStructures dataStructures) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath + ".txt")) { Chronicler.HoldOutput(); int curLinNum = 0; foreach (PassOne.ExpresionLine expLine in expresionLines) { if (expLine != null && expLine.OriginalLine != null && expLine.OriginalLine != "") { curLinNum = expLine.lineNumber; file.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { file.Write(expLine.locationCounter.ToString("X6") + "\t"); } file.Write(expLine.OriginalLine + "\t"); file.Write(expLine.Opcode); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); if (expLine.CommentLine != true) { Chronicler.Write(expLine.locationCounter.ToString("X6") + "\t"); } Chronicler.Write(expLine.OriginalLine + "\t"); Chronicler.WriteLine(expLine.Opcode); } } foreach (LiteralTable.LiteralValue lv in dataStructures.literalTable.literalTable) { curLinNum++; file.Write(curLinNum.ToString() + "\t"); file.Write(lv.address.ToString("X6") + "\t"); file.Write("*" + "\t"); file.Write(lv.label); file.Write("\n"); Chronicler.Write(curLinNum.ToString() + "\t"); Chronicler.Write(lv.address.ToString("X6") + "\t"); Chronicler.Write("*" + "\t"); Chronicler.WriteLine(lv.label); } } Chronicler.HoldOutput(); dataStructures.symbolTable.Print(); Chronicler.HoldOutput(); dataStructures.literalTable.PrintTable(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath + ".obj")) { Chronicler.HoldOutput(); string buffer = ""; string prevOpCode = "start"; int sl = 0; if (expresionLines.Count > 0) { sl = expresionLines[0].locationCounter; } Chronicler.WriteLine("Object code:"); foreach (PassOne.ExpresionLine expLine in expresionLines) { if (expLine != null && expLine.OriginalLine != null && expLine.OriginalLine != "") { if ((buffer.Length + expLine.Opcode.Length) > 60 || (prevOpCode == "" && buffer != "")) { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); sl = expLine.locationCounter; //clear buffer buffer = ""; } prevOpCode = expLine.Opcode; //check continuity buffer += expLine.Opcode; //add curr line to buffer } } if (buffer != "") { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); //clear buffer buffer = ""; } foreach (LiteralTable.LiteralValue lv in dataStructures.literalTable.literalTable) { if (buffer != "" && (buffer.Length + lv.hexValue.Length) > 60) { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); //clear buffer buffer = ""; } buffer += lv.hexValue;//add curr line to buffer } if (buffer != "") { //dump buffer contents file.Write("T" + sl.ToString("X5") + buffer.Length.ToString("X2") + buffer); file.Write("\n"); Chronicler.WriteLine("T" + buffer); //clear buffer buffer = ""; } dataStructures.symbolTable.PrintFile(file); dataStructures.symbolTable.Print(); } }
//************************************************************************ //*** FUNCTION LoadSymbols //*** ******************************************************************** //*** DESCRIPTION : opens a file and populates SymbolTableBST //*** INPUT ARGS : string filePath //*** OUTPUT ARGS : N/A //*** IN/OUT ARGS : N/A //*** RETURN : N/A //************************************************************************ public void LoadSymbols(string filePath) { Globals.Symbol symbol = default; symbol.label = ""; symbol.IFlag = true; char[] tmpLabel = new char[7]; //discard line flag bool discardLine; //get the line and trim whitespace string currentLine; string[] rflagAndValueStrings; string rFlag; try { using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan)) { try { using (StreamReader streamReader = new StreamReader(fileStream)) { while (!streamReader.EndOfStream) { //discard line flag discardLine = false; //get the line and trim whitespace currentLine = streamReader.ReadLine().CompactAndTrimWhitespaces(); if (currentLine == "") { Chronicler.LogError("blank line, skipping: \"" + currentLine + "\"" + "\n", "Adding Symbol"); discardLine = true; } else if (currentLine.CountStringCharachters(':') != 1)//check incorrect colon seperator count { Chronicler.LogError("Extra colon seperators in current line, skipping: \"" + currentLine + "\"" + "\n", "Adding Symbol"); discardLine = true; } if (!discardLine) { string[] symbolSubstrings = currentLine.Split(':'); //validate Label string label = symbolSubstrings[0].Trim(); discardLine = !ValidateLabel(label, currentLine, "Adding Symbol"); if (!discardLine) { rflagAndValueStrings = symbolSubstrings[1].Trim().Split(' '); //validate RFlag rFlag = rflagAndValueStrings[0].Trim(); discardLine = TestAndSetRFlag(rFlag, out symbol.RFlag, currentLine, "Adding Symbol"); if (!discardLine) { string value = rflagAndValueStrings[1].Trim(); if (!int.TryParse(value, out symbol.value) || value[0] == '+') { discardLine = true; Chronicler.LogError("Invalid integer value(" + value + "), skipping: \"" + currentLine + "\"" + "\n", "Adding Symbol"); } if (!discardLine) { //parse data into Symbol struct int symbolLabelIndex = 0; for (symbolLabelIndex = 0; symbolLabelIndex < 6 && symbolLabelIndex < label.Length; symbolLabelIndex++) { tmpLabel[symbolLabelIndex] = label[symbolLabelIndex]; } tmpLabel[symbolLabelIndex] = '\0'; StringBuilder sb = new StringBuilder(""); foreach (char c in tmpLabel.TakeWhile(c => c != '\0')) { sb.Append(c); } symbol.label = sb.ToString().Trim(); symbol.MFlag = false; if (SymbolTableBST.ContainsKey(symbol.label)) { Chronicler.LogError("Symbol with same Label('" + symbol.label + "') already exists! Setting MFlag and \n\tskipping: \"" + currentLine + "\"" + "\n", "Adding Symbol"); Globals.Symbol sym = SymbolTableBST.GetValueOrDefault(symbol.label); if (sym.MFlag == false) { sym.MFlag = true; SymbolTableBST.Remove(symbol.label); SymbolTableBST.Add(symbol.label, sym); } } else { Chronicler.Write("Adding symbol: ", Chronicler.OutputOptions.INFO); symbol.Print(Chronicler.OutputOptions.INFO); SymbolTableBST.Add(symbol.label, symbol); } } } } } } } } catch (IOException e) { Chronicler.LogError("failed to open File: " + filePath); } } } catch (IOException e) { Chronicler.LogError("failed to open File: " + filePath); } }
public static void Execute(Globals.DataStructures dataStructures, out List <ExpresionLine> expresionLines, string filePath) { int locationCounter = 0; int lineNumber = 0; expresionLines = new List <ExpresionLine>(); Regex regex = new Regex(@"^([\t ]*(?<label>[^\s]+:)[\t ]*){0,1}[\t ]*(?<flag>\+{0,1}[\t ]*)(?<operation>[^\s]+)(?<operandFieldAndComment>[\t ].*){0,1}[\t ]*($|(\r?\n))"); int programLength = 0; bool skipOperandParsing = false; try { using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan)) { try { using (StreamReader streamReader = new StreamReader(fileStream)) { while (!streamReader.EndOfStream) { lineNumber++; string currentLine = streamReader.ReadLine().Trim(); Match match = regex.Match(currentLine); skipOperandParsing = false; if (match.Success) { ExpresionLine expresionLine = new ExpresionLine(); expresionLine.OriginalLine = currentLine; expresionLine.lineNumber = lineNumber; expresionLine.locationCounter = locationCounter; expresionLine.label = match.Groups["label"].Value.Trim(); expresionLine.operation = match.Groups["operation"].Value.Trim(); expresionLine.operandFieldAndComment = match.Groups["operandFieldAndComment"].Value.Trim(); expresionLine.lineNumber = lineNumber; expresionLine.format4indicator = match.Groups["flag"].Value.Trim(); expresionLine.DeferExpresionResolutiontoPass2 = false; if (expresionLine.label != "") { if (expresionLine.label[expresionLine.label.Length - 1] == ':') { expresionLine.label = expresionLine.label.Substring(0, expresionLine.label.Length - 1).Trim(); } else { expresionLine.validLine = false; Chronicler.LogError("Labels must end in a ':'"); } if (expresionLine.validLine) { SymbolTable.ValidateLabel(expresionLine.label, currentLine, "pass one"); } } Regex commentChecker = new Regex(@"[\t ]*(?<com>;.*)"); Match comment = commentChecker.Match(currentLine); if (comment.Success) { expresionLine.OriginalLine = currentLine; expresionLine.locationCounter = 0; expresionLine.label = ""; expresionLine.operation = ""; expresionLine.operandFieldAndComment = ""; expresionLine.lineNumber = lineNumber; expresionLine.format4indicator = ""; expresionLine.CommentLine = true; expresionLine.DeferExpresionResolutiontoPass2 = false; skipOperandParsing = true; expresionLines.Add(expresionLine); } else { if (dataStructures.opcodeTable.assemblerDirectives.Contains(expresionLine.operation)) { switch (expresionLine.operation) { case "EQU": skipOperandParsing = true; expresionLine.IsEQU = true; if (expresionLine.operandFieldAndComment[0] == '*' && expresionLine.validLine) { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } else if (expresionLine.validLine) { if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } else { if (expresionLine.expresionData.first.HasValue) { int value = expresionLine.expresionData.first.Value.value; if (expresionLine.expresionData.second.HasValue) { if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.SUBTRACT) { value = (expresionLine.expresionData.first.Value.value) - expresionLine.expresionData.second.Value.value; } if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.ADD) { value = (expresionLine.expresionData.first.Value.value) + expresionLine.expresionData.second.Value.value; } if (expresionLine.expresionData.rflag.HasValue != true) { expresionLine.validLine = false; } if (expresionLine.validLine) { expresionLine.locationCounter = value; dataStructures.symbolTable.addSymbol(expresionLine.label, expresionLine.expresionData.rflag.Value, value, currentLine); } else { Chronicler.LogError("Couldn't add \"" + currentLine + "\" to symbol table.", "pass one"); } } else { expresionLine.expresionData.rflag = expresionLine.expresionData.first.Value.RFlag; if (expresionLine.validLine) { expresionLine.locationCounter = value; dataStructures.symbolTable.addSymbol(expresionLine.label, expresionLine.expresionData.rflag.Value, value, currentLine); } else { Chronicler.LogError("Couldn't add \"" + currentLine + "\" to symbol table.", "pass one"); } } } else { Chronicler.LogError("EQU can not be a literal value", "pass one"); expresionLine.validLine = false; } } } break; case "BYTE": if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } else { skipOperandParsing = false; if (expresionLine.expresionData.first.HasValue) { Chronicler.LogError("BYTE doesn't accept integer values", "pass one"); expresionLine.validLine = false; } else if (expresionLine.expresionData.literal != null) { if (expresionLine.expresionData.literal.isOldStyleLiteral) { if (expresionLine.label != "") { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } locationCounter += expresionLine.expresionData.literal.Length; expresionLine.Opcode = expresionLine.expresionData.literal.hexValue; } else { expresionLine.validLine = false; Chronicler.LogError("New style literals are not allowed in assembler directives"); } } } break; case "WORD": expresionLine.DeferExpresionResolutiontoPass2 = true; if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } else { if (expresionLine.expresionData.first.HasValue) { int value = expresionLine.expresionData.first.Value.value; if (expresionLine.expresionData.second.HasValue) { if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.SUBTRACT) { value = (expresionLine.expresionData.first.Value.value) - expresionLine.expresionData.second.Value.value; } if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.ADD) { value = (expresionLine.expresionData.first.Value.value) + expresionLine.expresionData.second.Value.value; } } if (expresionLine.expresionData.rflag.HasValue != true) { expresionLine.validLine = false; } if (expresionLine.validLine && expresionLine.label != "") { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } if (expresionLine.validLine) { expresionLine.Opcode = value.ToString("X"); locationCounter += 3; } else { Chronicler.LogError("Couldn't parse \"" + currentLine + "\"", "pass one"); } } else if (expresionLine.expresionData.literal != null) { Chronicler.LogError("BYTE doesn't accept Charachter/Hex values", "pass one"); expresionLine.validLine = false; } } break; case "START": skipOperandParsing = true; Regex testBlankLine = new Regex(@"[\t ]*;.*"); if (expresionLine.operandFieldAndComment == "") { locationCounter = 0; } else if (testBlankLine.IsMatch(expresionLine.operandFieldAndComment)) { locationCounter = 0; } else { if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } else { Regex stripComment = new Regex(@"[\t ]*(?<min>-{0,1})[\t ]*(?<val>[0-9]+)[\t ]*(;.*){0,1}"); Match match1 = stripComment.Match(expresionLine.operandFieldAndComment); if (match1.Success) { Globals.Symbol?tmp; ExpresionHandler.ParseNum(match1.Groups["min"].Value + match1.Groups["val"].Value, out tmp, "(" + match1.Groups["min"].Value + match1.Groups["val"].Value + ")" + currentLine); expresionLine.expresionData.comment = match1.Groups["$3"].Value; if (tmp.HasValue && locationCounter == 0) { locationCounter = tmp.Value.value; ExpresionLine.startLoc = locationCounter; } else { Chronicler.LogError("couldn't parse starting adress number, or start was not at beggining of the program", "Pass One"); } } else { expresionLine.validLine = false; Chronicler.LogError("couldn't parse starting adress", "Pass One"); } } } if (expresionLine.label != "") { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } break; case "END": skipOperandParsing = true; testBlankLine = new Regex(@"[\t ]*;.*"); if (expresionLine.operandFieldAndComment == "") { locationCounter = 0; } else if (testBlankLine.IsMatch(expresionLine.operandFieldAndComment)) { locationCounter = 0; } else { ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData); if (expresionLine.expresionData.first.HasValue) { int value = expresionLine.expresionData.first.Value.value; if (expresionLine.expresionData.second.HasValue) { if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.SUBTRACT) { value = (expresionLine.expresionData.first.Value.value) - expresionLine.expresionData.second.Value.value; } if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.ADD) { value = (expresionLine.expresionData.first.Value.value) + expresionLine.expresionData.second.Value.value; } } if (expresionLine.expresionData.second.HasValue && expresionLine.expresionData.rflag.HasValue != true) { expresionLine.validLine = false; } if (expresionLine.validLine) { Globals.Symbol?symbol; if (dataStructures.symbolTable.SearchSymbol(expresionLine.expresionData.first.Value.label, currentLine, out symbol)) { programLength = locationCounter - symbol.Value.value; } } else { Chronicler.LogError("Couldn't add \"" + currentLine + "\" to symbol table.", "pass one"); } } else { Chronicler.LogError("END can not be a literal value", "pass one"); expresionLine.validLine = false; } } if (expresionLine.label != "") { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } break; case "RESB": skipOperandParsing = true; if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } else { if (expresionLine.expresionData.first.HasValue) { int value = expresionLine.expresionData.first.Value.value; if (expresionLine.expresionData.second.HasValue) { if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.SUBTRACT) { value = (expresionLine.expresionData.first.Value.value) - expresionLine.expresionData.second.Value.value; } if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.ADD) { value = (expresionLine.expresionData.first.Value.value) + expresionLine.expresionData.second.Value.value; } } if (expresionLine.validLine && expresionLine.label != "") { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } else { Chronicler.LogError("Couldn't add \"" + currentLine + "\" to symbol table.", "pass one"); } if (expresionLine.validLine) { locationCounter += value; } } else if (expresionLine.expresionData.literal != null) { Chronicler.LogError("BYTE doesn't accept Charachter/Hex values", "pass one"); expresionLine.validLine = false; } } break; case "RESW": skipOperandParsing = true; if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } else { if (expresionLine.expresionData.first.HasValue) { int value = expresionLine.expresionData.first.Value.value; if (expresionLine.expresionData.second.HasValue) { if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.SUBTRACT) { value = (expresionLine.expresionData.first.Value.value) - expresionLine.expresionData.second.Value.value; } if (expresionLine.expresionData.operatorValue != null && expresionLine.expresionData.operatorValue == Globals.ExpresionData.Arithmetic.ADD) { value = (expresionLine.expresionData.first.Value.value) + expresionLine.expresionData.second.Value.value; } } if (expresionLine.validLine && expresionLine.label != "") { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } else { Chronicler.LogError("Couldn't add \"" + currentLine + "\" to symbol table.", "pass one"); } if (expresionLine.validLine) { locationCounter += value * 3; } } else if (expresionLine.expresionData.literal != null) { Chronicler.LogError("BYTE doesn't accept Charachter/Hex values", "pass one"); expresionLine.validLine = false; } } break; case "EXTREF": string[] arr = expresionLine.operandFieldAndComment.Split(',', StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < arr.Length; i++) { arr[i] = arr[i].Trim(); dataStructures.symbolTable.addSymbol(arr[i], false, 0, currentLine); } break; default: Chronicler.LogDetailedInfo("Doing: " + expresionLine.operation); break; } } else { opcodeTable.operationData operDat; if (dataStructures.opcodeTable.operationTableDictionary.TryGetValue(expresionLine.operation, out operDat)) { if (expresionLine.label != "") { dataStructures.symbolTable.addSymbol(expresionLine.label, true, locationCounter, currentLine); } switch (operDat.format) { case 1: locationCounter += 1; break; case 2: locationCounter += 2; break; case 3: if (expresionLine.format4indicator == "") { locationCounter += 3; } else { locationCounter += 4; } break; case 4: locationCounter += 4; break; default: break; } if (Parser.guessOperandType(expresionLine.operandFieldAndComment) == Parser.OperandType.DISPLACEMENT_OR_ADDRESS) { expresionLine.DeferExpresionResolutiontoPass2 = true; } else { expresionLine.DeferExpresionResolutiontoPass2 = false; } expresionLine.operationData = operDat; } else { expresionLine.operationData = null; } Chronicler.Write("Parsing operation: " + expresionLine.operation + "\n", Chronicler.OutputOptions.INFO); } } if (expresionLine.validLine && skipOperandParsing != true && expresionLine.operandFieldAndComment != "" && !expresionLine.DeferExpresionResolutiontoPass2) { if (ExpresionHandler.ResolveF3F4Expresion(dataStructures, expresionLine.operandFieldAndComment, currentLine, out expresionLine.expresionData) != true) { expresionLine.validLine = false; } } expresionLines.Add(expresionLine); } else { Chronicler.LogError("Couldn't parse fields on line: " + lineNumber); } } } } catch (IOException e) { Chronicler.LogError("failed to open File: " + filePath); } } } catch (IOException e) { Chronicler.LogError("failed to open File: " + filePath); } dataStructures.literalTable.setStartAddress(locationCounter); DumpIntermidiateFile(filePath, expresionLines, dataStructures); }