Пример #1
0
        static void EnterCommand()
        {
            Console.WriteLine("\nEnter Command...");
            expression = Console.ReadLine();
            List <char> items;
            string      formulaReversed;

            expression = Regex.Replace(expression, @"\s+", " ");

            if (expression.EndsWith(" "))
            {
                expression = expression.Remove(expression.Length - 1);
            }
            string[] words     = expression.Split(' ');
            string   firstWord = words[0].ToLower();

            Console.WriteLine();
            try
            {
                switch (firstWord)
                {
                case "enter":
                    formula    = "";
                    expression = expression.Remove(0, 6);
                    expression = expression.Replace(" ", "");

                    items = ConvertToPref(expression);
                    if (items.Count == 0)
                    {
                        Console.ReadLine();
                        return;
                    }
                    formulaReversed = "";
                    for (int i = 0; i < items.Count; i++)
                    {
                        formula += items[i];
                    }
                    tree = new CTree(formula[0], formula);
                    compCommand(1);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Formula accepted!");
                    Console.ResetColor();

                    EnterCommand();
                    break;

                case "comp":
                    compCommand();
                    break;

                case "vars":
                    tree.printVars();
                    EnterCommand();
                    break;

                case "join":
                    string tempFormula = formula;
                    formula    = "";
                    expression = expression.Remove(0, 4);
                    items      = ConvertToPref(expression);
                    if (items.Count == 0)
                    {
                        Console.ReadLine();
                        return;
                    }
                    formulaReversed = "";
                    for (int i = 0; i < items.Count; i++)
                    {
                        Console.Write("{0}", items[i]);
                        formula += items[i];
                    }
                    for (int i = items.Count - 1; i >= 0; i--)
                    {
                        formulaReversed += items[i];
                    }

                    treeJoin = new CTree(formula[0], formulaReversed);
                    tree.Join(treeJoin);
                    formula = tempFormula + formula;
                    EnterCommand();
                    break;

                case "print":
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(formula);
                    Console.ResetColor();

                    EnterCommand();
                    break;

                case "quit":
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("Good-bye!");
                    Console.ResetColor();
                    break;

                case "\\help":
                    commandList();
                    EnterCommand();
                    break;

                case "\\clear":
                    Console.Clear();
                    EnterCommand();
                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unknown command! Try again.");
                    Console.ResetColor();
                    EnterCommand();
                    break;
                }
            }
            catch (Exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"\nTry again!");
                Console.ResetColor();
                EnterCommand();
            }
        }
Пример #2
0
 public void Join(CTree temp)
 {
     rootNode.joine(temp.rootNode);
     this.formula += temp.formula;
 }