static void Main(string[] args) { string fileName; if (args.Length == 0) { Console.Write("Please enter the name for the SIC file: "); fileName = Console.ReadLine(); } else fileName = args[0]; while (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), ($@"{Environment.CurrentDirectory}\\..\\..\\" + fileName)))) { Console.Write("||Error|| SICXE file path does not exist. Please enter a valid file name: \n"); fileName = Console.ReadLine(); } Console.Clear(); OpcodeTable opcodes = new OpcodeTable(File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), ("..\\..\\" + "OPCODES.DAT")))); PassOne readFile = new PassOne(); //string searchPath = ReadInput(args); readFile.ProcessFile(fileName, opcodes); Console.WriteLine("Press any key to exit."); Console.ReadKey(); /*SymbolTable readText = new SymbolTable(); //declare readText for the search in search table readText.ReadAndSeparateFile(); //read in the file and separate the file Console.WriteLine("Press any key to enter search file."); Console.ReadLine(); //any key string searchPath = ReadInput(args); //declare searchPath for the directory path readText.SearchFile(searchPath); //compares the searchPath with readText Console.WriteLine(""); //new line ExpressionProcessing readText1 = new ExpressionProcessing(readText); //declare readText1 for expression processing Console.WriteLine("Press any key to enter expression file."); Console.ReadLine(); //any key string expressionPath = ReadInput(args); //declare expressionPath for the directory path readText1.Processing(expressionPath); //processes the expressionPath*/ }
/******************************************************************** *** FUNCTION : ProcessFile *** ********************************************************************* *** DESCRIPTION : run pass one *** *** INPUT ARGS : string inFile, OpcodeTable opcodeTable *** *** OUTPUT ARGS : No Output Args *** *** RETURN : Void *** *********************************************************************/ public void ProcessFile(string inFile, OpcodeTable oTable) { BinSearchTree sTable = new BinSearchTree(); LinkedList lTable = new LinkedList(); //read file string[] program = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), ($@"{Environment.CurrentDirectory}\\..\\..\\" + inFile))); var file = inFile.Remove(inFile.IndexOf('.')) + ".tmp"; int num = 0; string sAdd; string LC; string pLength; string[] line = ProcessLine(program[num], out bool check); File.Create(file).Close(); while (check) //while there is lines { num++; line = ProcessLine(program[num], out check); } if (line[1] == "START") //for start { sAdd = line[2]; LC = sAdd; sTable.Insert(new Symbol() { Element = line[0], //insert new symbol Value = int.Parse(LC, System.Globalization.NumberStyles.HexNumber), RFlag = true }); ToFile(ref num, LC, line, file); //put in file the symbol line = ProcessLine(program[num], out check); } else { sAdd = "00000"; //starting address 00000 LC = sAdd; } while (line[1] != "END") //for end { int count = 0; if (line[1] != null && line[2] != null) { if (line[0].Contains(";")) { check = true; } if (!check) { if (line[0].Contains(";")) //check for comment { Console.WriteLine("Comment: " + line[0]); } if (line[0] != string.Empty && line[1] != "EQU") { try { sTable.Search(line[2]); } catch (KeyNotFoundException) { string symbol = line[0]; if (char.IsLetter(symbol[0])) { sTable.Insert(new Symbol() { Element = line[0] + ':', Value = int.Parse(LC, System.Globalization.NumberStyles.HexNumber), RFlag = true }); } else { if (line[0].Contains(";")) //check for comment { Console.WriteLine("Comment: " + line[0]); } else { Console.WriteLine(string.Format("||ERROR|| Symbol {0} has an invalid character(s).", symbol)); } } } } if (oTable.Search(line[1], out Opcode opcode)) { count = opcode.form; } else if (line[1] == "WORD") //for word { count = 3; } else if (line[1] == "BYTE") //for byte { count = InsertL("=" + line[2]).length; } else if (line[1] == "RESW") //for resw { count = int.Parse(line[2]) * 3; } else if (line[1] == "RESB") //for resb { count = int.Parse(line[2]); } else if (line[2] == "FLOAT" || line[2] == "NORM" || line[2] == "FIX" || line[2] == "HIO" || line[2] == "TIO" || line[2] == "SIO") { count = 1; string[] temp = line; line[0] = temp[1]; line[1] = temp[2]; line[2] = " "; } else if (line[1] == "EQU") //for equ { sTable.Insert(CheckSymbol(ref num, LC, line, sTable, file)); line = ProcessLine(program[num], out check); continue; } else //if not any of those { Console.WriteLine(string.Format("||ERROR|| Opcode {0} not found.", line[2])); num++; line = ProcessLine(program[num], out check); continue; } if (line[2][0] == '=') { lTable.Add(InsertL(line[2])); } } ToFile(ref num, LC, line, file); LC = LCCount(LC, count); line = ProcessLine(program[num], out check); } else { num++; line = ProcessLine(program[num], out check); } } ToFile(ref num, LC, line, file); ToScreen(file); //display sic pLength = ((int.Parse(LC, System.Globalization.NumberStyles.HexNumber) - int.Parse(sAdd, System.Globalization.NumberStyles.HexNumber)) + CutLiteral(ref lTable, ref num, ref LC, file)).ToString("X"); Console.WriteLine("_______________________________________________________"); Console.WriteLine("\nProgram Length = " + pLength); Console.WriteLine("_______________________________________________________"); Console.WriteLine(""); lTable.Display(); Console.WriteLine("_______________________________________________________"); Console.WriteLine("\n SYMBOL TABLE"); Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-10} {4,-10}", "LABEL", "VALUE", "RFLAG", "IFLAG", "MFLAG"); Console.WriteLine("-------------------------------------------------------"); sTable.Display(); }