public BinaryEvaluation(Evaluation left, Evaluation right, BinaryOperation operation)
 {
     this.left      = left;
     this.right     = right;
     this.operation = operation;
 }
Example #2
0
        private Evaluation PerformEvaluate(ParseTreeNode node)
        {
            switch (node.Term.Name)
            {
            case "BinExpr":
                var             leftNode      = node.ChildNodes[0];
                var             operationNode = node.ChildNodes[1];
                var             rightNode     = node.ChildNodes[2];
                Evaluation      left          = PerformEvaluate(leftNode);
                Evaluation      right         = PerformEvaluate(rightNode);
                BinaryOperation operation     = BinaryOperation.Add;
                switch (operationNode.Term.Name)
                {
                case "+":
                    operation = BinaryOperation.Add;
                    break;

                case "-":
                    operation = BinaryOperation.Sub;
                    break;

                case "*":
                    operation = BinaryOperation.Mul;
                    break;

                case "/":
                    operation = BinaryOperation.Div;
                    break;

                case "^":
                    operation = BinaryOperation.Exp;
                    break;
                }
                return(new BinaryEvaluation(left, right, operation));

            case "FunctionCall":
                var               functionNode = node.ChildNodes[0];
                var               argumentNode = node.ChildNodes[1];
                Evaluation        argument     = PerformEvaluate(argumentNode);
                FunctionOperation function     = FunctionOperation.sin;
                switch (functionNode.Token.Text)
                {
                case "sin":
                    function = FunctionOperation.sin;
                    break;

                case "cos":
                    function = FunctionOperation.cos;
                    break;

                case "tg":
                    function = FunctionOperation.tg;
                    break;

                case "ctg":
                    function = FunctionOperation.ctg;
                    break;
                }
                return(new FunctionEvaluation(function, argument));

            case "number":
                CultureInfo culture = new CultureInfo("en-US");
                var         value   = Convert.ToSingle(node.Token.Text, culture);
                return(new ConstantEvaluation(value));

            case "AssignmentStmt":
                var        expNode    = node.ChildNodes[0];
                var        expreNode  = node.ChildNodes[2];
                Evaluation expression = PerformEvaluate(expreNode);
                return(new NameEvaluation(expNode.ToString(), expression));

            case "Term":
                Console.WriteLine("не знаю что с этим делать");
                throw new NotSupportedException();

            case "UnExpr":
                var        unNode       = node.ChildNodes[0];
                var        unExprNode   = node.ChildNodes[1];
                Evaluation unExpression = PerformEvaluate(unExprNode);
                return(new UnaryEvaluation(unNode.ToString(), unExpression));
            }

            throw new InvalidOperationException($"Unrecognizable term {node.Term.Name}");
        }
Example #3
0
 public NameEvaluation(string name, Evaluation values)
 {
     variables.Add(name, values);
 }
 public UnaryEvaluation(string op, Evaluation evaluation)
 {
     this.op         = op;
     this.evaluation = evaluation;
 }
 public FunctionEvaluation(FunctionOperation function, Evaluation argument)
 {
     this.function = function;
     this.argument = argument;
 }