// выполнить команды, вписанные вручную public void PerformCalculate() { Dictionary <string, double> varibleList = new Dictionary <string, double>(); // словарь с переменными while (true) { Console.WriteLine("\nВведите команду:"); string inputCommand = Console.ReadLine(); // ввод команды с консоли if (inputCommand == "") { break; } var parsedCommand = ParsCommand(inputCommand); // разделить команду на части bool checkLenghtCommand = CheckLenghtCommand(parsedCommand); // проверка длины команды CommandParts readyCommand = CreateCommandParts(checkLenghtCommand, parsedCommand); // создание класса c частями команды PerformCommand(readyCommand, varibleList); // выполнить команду } Console.WriteLine("------------------------"); Console.WriteLine("Список всех переменных:"); foreach (var item in varibleList) { Console.WriteLine(item); } }
// Выполнение команды public void PerformCommand(CommandParts command, Dictionary <string, double> dict) { switch (command.Command) { case "var": Var(dict, command.First); break; case "mov": Mov(dict, command.First, command.Second); break; case "add": Add(dict, command.First, command.Second); break; case "sub": Sub(dict, command.First, command.Second); break; case "div": Div(dict, command.First, command.Second); break; case "mul": Mul(dict, command.First, command.Second); break; } }
// выполнять команды, записанные в файле public void PerformCalculate(string path) { Dictionary <string, double> varibleList = new Dictionary <string, double>(); // словарь с переменными string[] commands = ReadFile(path); foreach (var item in commands) { Console.WriteLine(item); string inputCommand = item; var parsedCommand = ParsCommand(inputCommand); // разделить команду на части bool checkLenghtCommand = CheckLenghtCommand(parsedCommand); // проверка длины команды CommandParts readyCommand = CreateCommandParts(checkLenghtCommand, parsedCommand); // создание класса c частями команды PerformCommand(readyCommand, varibleList); // выполнить команду } Console.WriteLine("------------------------"); Console.WriteLine("Список всех переменных:"); foreach (var item in varibleList) { Console.WriteLine(item); } }