public override Task <string> Visit(NodeExprBinary e, CancellationToken t)
        {
            return(Task.Run
                   (
                       () =>
            {
                var lt = Visit(e.Left, t);
                var rt = Visit(e.Right, t);

                Task.WaitAll(new[] { lt, rt }, t);

                t.ThrowIfCancellationRequested();

                var l = lt.Result;
                var r = rt.Result;
                var lp = e.Left.Priority > e.Priority;
                var rp = e.Priority < e.Right.Priority;

                if (e.IsNecesaryParenthesisLeft)
                {
                    l = $"({l})";
                }
                if (e.IsNecesaryParenthesisRight)
                {
                    r = $"({r})";
                }

                return (e.TypeBinary == ETypeBinary.Mult && !(e.Left.TypeExpr == ENodeTypeExpr.Constant && e.Right.TypeExpr == ENodeTypeExpr.Constant)) ? l + r : l + MathExpr.TypeBinariesStr[e.TypeBinary] + r;
            }
                   ));
        }
예제 #2
0
        public override Task <NodeExpr> Visit(NodeExprBinary e, CancellationToken t)
        {
            return(Task.Run
                   (
                       () =>
            {
                var lt = Visit(e.Left, t);
                var rt = Visit(e.Right, t);

                Task.WaitAll(new[] { lt, rt }, t);

                t.ThrowIfCancellationRequested();

                var l = lt.Result;
                var r = rt.Result;

                return
                ((l is NodeExprNumber <N> ln) && (r is NodeExprNumber <N> rn))
                    ? (NodeExpr)NodeExpr.Number(mAlg.EvalBinaryOperator(e.TypeBinary, ln.Value, rn.Value))
                    : NodeExpr.Binary(e.TypeBinary, l, r);
            }
                   ));
        }
예제 #3
0
 public override Task <NodeExpr> Visit(NodeExprBinary e, CancellationToken t) => Task.FromResult <NodeExpr>(e);
예제 #4
0
 public virtual Task <T> Visit(NodeExprBinary e, CancellationToken t) => Task.FromResult(default(T));
예제 #5
0
 public virtual T Visit(NodeExprBinary e) => default(T);
예제 #6
0
 public NodeExprBinary(NodeExprBinary e) : this(e.TypeBinary, e.Left, e.Right)
 {
 }