Exemplo n.º 1
0
        static void LoadText(string input)
        {
            input = input.Substring(5, input.Length - 5);
            if (!input.Contains("."))
            {
                input += ".txt";
            }
            if (!File.Exists(input))
            {
                throw new Exception("File not found");
            }
            var line = 0;

            using (var fileStream = File.OpenText(input))
            {
                while (!fileStream.EndOfStream)
                {
                    line++;
                    var code = fileStream.ReadLine();
                    if (code.ToLower().StartsWith("int"))
                    {
                        code = code.Substring(3, code.Length - 3).Trim(' ');
                    }
                    FiniteStates.ProcessCode(code);
                }
                Console.WriteLine("File successfully validated");
            }
        }
Exemplo n.º 2
0
        static void OnCommand(string input)
        {
            try
            {
                if (input.StartsWith("load "))
                {
                    LoadText(input);
                    return;
                }

                if (input.StartsWith("import "))
                {
                    ImportAutomat(input);
                    Console.WriteLine("Finite state automate successfully loaded");
                    return;
                }

                if (input.ToLower() == "minimize")
                {
                    if (!FiniteStates.MinimizeAutomat())
                    {
                        return;
                    }
                    var xlsWorker = new XlsWorker();
                    xlsWorker.Write(new string(FiniteStates.CurrentFileName.TakeWhile(ch => ch != '.').ToArray()) + "_optimized.xls", FiniteStates.GetTable);
                    return;
                }
                FiniteStates.ProcessCode(input);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }