コード例 #1
0
ファイル: Program.cs プロジェクト: tombler/SimpleCalculator
        static void Main(string[] args)
        {
            int count = 0;
            string prompt = "[" + count.ToString() + "]>";
            string instructions = "Type in a binary equation, then press enter." + System.Environment.NewLine + "Type 'quit' or 'exit' to exit the program." + System.Environment.NewLine + prompt;
            Console.Write(instructions);
            string userInput = Console.ReadLine();
            Parse firstInput = new Parse(userInput);
            Evaluate eval = new Evaluate(firstInput);
            Stack stack = new Stack(eval);
            count += 1;
            prompt = "[" + count.ToString() + "]>";
            Console.Write(" = " + stack.currentAnswer.ToString() + System.Environment.NewLine + prompt);
            userInput = Console.ReadLine();

            //ProgramInitializer PI = new ProgramInitializer();
            //string userInput = Console.ReadLine();
            //PI.EvaluateFirstExpression(userInput);
            //Evaluate eval = PI.FirstEval;
            //Stack stack = PI.ProgramStack;

            //Console.Write(" = " + stack.currentAnswer.ToString() + System.Environment.NewLine);
            //userInput = Console.ReadLine();

            while (userInput != "quit" || userInput != "exit")
            {
                try
                {
                    Parse input = new Parse(userInput);
                    eval.EvaluateExpression(input);
                    stack.stackEvaluate(eval);
                    count += 1;
                    prompt = "[" + count.ToString() + "]>";
                    Console.Write(" = " + stack.currentAnswer.ToString() + System.Environment.NewLine + prompt);
                    userInput = Console.ReadLine();
                }
                catch (Exception ex)
                {
                    if (userInput == "quit" || userInput == "exit")
                    {
                        break;
                    }
                    else
                    {
                        prompt = "[" + count.ToString() + "]>";
                        Console.Write("There was an error. Please try again." + System.Environment.NewLine + prompt);
                        userInput = Console.ReadLine();
                    }

                }
            }
        }