예제 #1
0
파일: Evaluator.cs 프로젝트: njmube/public
        public int Eval(string s)
        {
            if (string.IsNullOrEmpty(s))
            throw new Exception();
              var elements = new ElementList(parser.Parse(s));
              var operation = elements.FindOperation();
              while (operation != null)
              {
            var newElement = operation.Compute();
            elements.ReplaceOperation(operation, newElement);
            operation = elements.FindOperation();
              }

              return elements.First.Value;
        }
예제 #2
0
        public int Eval(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                throw new Exception();
            }
            var elements  = new ElementList(parser.Parse(s));
            var operation = elements.FindOperation();

            while (operation != null)
            {
                var newElement = operation.Compute();
                elements.ReplaceOperation(operation, newElement);
                operation = elements.FindOperation();
            }

            return(elements.First.Value);
        }