Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Console.WriteLine(breakLine);
            Console.WriteLine();
            //do
            while (true)
            {
                Console.Write("Input Calculation: ");
                Infix   infix   = new Infix(Console.ReadLine());
                Postfix postfix = infix.ToPostfix();

                if (infix.RawInfix == "")
                {
                    break;
                }

                bool debug = false;
                //debug = true;

                bool checkInfix = false;
                //checkInfix = true;
                //Console.WriteLine(infix.TokenizedInfix.ToArray());
                if (debug)
                {
                    if (checkInfix)
                    {
                        foreach (IToken token in infix.InfixTokens)
                        {
                            //if (token is Operand)
                            //{
                            //    Operand operand = (Operand)token;
                            //    if (operand.Negative)
                            //        Console.WriteLine("-" + token.Token);
                            //    else
                            //        Console.WriteLine(token.Token);
                            //}
                            //else
                            Console.WriteLine("Debug:               " + token.Token);
                            //if (token is Operator)
                            //{
                            //    Console.WriteLine("operator:                        " + token.Token);
                            //}
                        }
                    }
                    else
                    {
                        foreach (IToken token in postfix.PostfixExpression)
                        {
                            //Console.WriteLine("bazinga");
                            Console.WriteLine("Debug:                " + token.Token);
                        }

                        //Console.WriteLine();
                        //Console.WriteLine("Answer: " + postfix.SolvedExpression());
                    }
                }
                Console.WriteLine("Answer: " + postfix.SolvedExpression());

                //if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                //{
                //    break;
                //}
                //else
                //{
                //Console.WriteLine();
                Console.WriteLine(breakLine);
                //Console.WriteLine("--------------------------------------------------");
                Console.WriteLine();
                //}
            }// while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape));
        }
 public Calculator()
 {
     InitializeComponent();
     this.postfixStack = new Postfix();
     this.needsReset   = false;
 }