예제 #1
0
        public void Parse(string equation)
        {
            var operatorLocation = additionSubtraction.Match(equation);

            if (!operatorLocation.Success)
            {
                operatorLocation = multiplicationDivision.Match(equation);
            }

            if (operatorLocation.Success)
            {
                Operator = operatorLocation.Value;

                LeftNumber = new Operation();
                LeftNumber.Parse(equation.Substring(0, operatorLocation.Index));

                RightNumber = new Operation();
                RightNumber.Parse(equation.Substring(operatorLocation.Index + 1));
            }
            else
            {
                Operator = "v";
                result   = double.Parse(equation);
            }
        }
        public double Solve(string equation)
        {
            //Remove any spaces
            equation = Regex.Replace(equation, @"\s+", "");

            var operation = new Operation();

            operation.Parse(equation);

            return(operation.Solve());
        }