예제 #1
0
        public static TypeDescriptor OperateDataTypes(IOperator op, TypeDescriptor a, TypeDescriptor b)
        {
            if (a == b)
            {
                var dataType = a.DataType;
                if (dataType.IsDelegate() || dataType.IsObject() || dataType.IsArray())
                {
                    throw new InvalidOperatorForTypeCompilerException(op.GetType(), a, b, op.Info);
                }

                return(a);
            }

            if (a.IsInteger())
            {
                if (b.IsInteger())
                {
                    return(TypeDescriptor.Integer);
                }

                if (b.IsNumericOrFloat())
                {
                    return(TypeDescriptor.Numeric);
                }
            }

            if (a.IsNumber())
            {
                if (b.IsNumber())
                {
                    return(TypeDescriptor.Numeric);
                }

                if (b.IsString() && op is AdditionOperator)
                {
                    return(TypeDescriptor.String);
                }

                throw new InvalidOperatorForTypeCompilerException(op.GetType(), a, b, op.Info);
            }

            if (a.IsString())
            {
                if (b.IsNumber() && op is MultiplicationOperator)
                {
                    return(TypeDescriptor.String);
                }

                throw new InvalidOperatorForTypeCompilerException(op.GetType(), a, b, op.Info);
            }

            throw new InvalidOperatorForTypeCompilerException(op.GetType(), a, b, op.Info);
        }
예제 #2
0
 private void graphContextMenuStrip_Opening(object sender, CancelEventArgs e)
 {
     viewToolStripMenuItem.Enabled       = false;
     breakpointToolStripMenuItem.Enabled = false;
     breakpointToolStripMenuItem.Checked = false;
     if (graphTreeView.SelectedNode != null)
     {
         IOperator op = GetOperatorTag(graphTreeView.SelectedNode);
         if (op != null)
         {
             Type viewType = MainFormManager.GetDefaultViewType(op.GetType());
             if (viewType != null)
             {
                 viewToolStripMenuItem.Enabled = true;
                 viewToolStripMenuItem.Tag     = op;
             }
             breakpointToolStripMenuItem.Enabled = !Locked;
             breakpointToolStripMenuItem.Tag     = op;
             if (op.Breakpoint)
             {
                 breakpointToolStripMenuItem.Checked = true;
             }
         }
     }
 }
예제 #3
0
        private void setOperatorComboValue(IOperator op)
        {
            string sOp = op.GetType().Name;

            if (sOp.Equals(typeof(EqualOperator).Name))
            {
                Operator.SelectedIndex = 0;
            }
            if (sOp.Equals(typeof(NotEqualOperator).Name))
            {
                Operator.SelectedIndex = 1;
            }
            if (sOp.Equals(typeof(GreaterOperator).Name))
            {
                Operator.SelectedIndex = 2;
            }
            if (sOp.Equals(typeof(GreaterOrEqualOperator).Name))
            {
                Operator.SelectedIndex = 3;
            }
            if (sOp.Equals(typeof(LowerOperator).Name))
            {
                Operator.SelectedIndex = 4;
            }
            if (sOp.Equals(typeof(LowerOrEqualOperator).Name))
            {
                Operator.SelectedIndex = 5;
            }
        }
예제 #4
0
        public static IMemberPredicate Define(IOperator Operator, MemberInfo Member)
        {
            var OP        = Operator.GetType();
            var typedef   = typeof(MemberPredicate <>).GetGenericTypeDefinition();
            var type      = typedef.MakeGenericType(OP);
            var predicate = Activator.CreateInstance(type, Operator, Member) as IMemberPredicate;

            return(predicate);
        }
예제 #5
0
 /// <summary>
 /// Devuelve el nombre interno del operador pasado como parámetro
 /// </summary>
 /// <param name="conditionalOperator">operador condicional</param>
 /// <returns>el nombre interno del operador pasado como parámetro</returns>
 public static string GetOperatorInternalName(IOperator conditionalOperator)
 {
     return(Assembly.GetExecutingAssembly().GetTypes()
            .Where(type =>
                   type == conditionalOperator.GetType() &&
                   type.GetCustomAttribute(typeof(Operator)) != null)
            .Select(type => ((Operator)type.GetCustomAttribute(typeof(Operator))).InternalName)
            .FirstOrDefault());
 }
예제 #6
0
 public string Get()
 {
     return(JsonSerializer.Serialize(new
     {
         allPlugins = _plugins.Select(p => p.ToString()),
         operators = _operators.Select(o => o.GetType().Name),
         defaultOperator = _defaultOperator.GetType().Name
     }, new JsonSerializerOptions {
         WriteIndented = true
     }));
 }
예제 #7
0
        public void Execute(int op1, IOperator opr, int op2)
        {
            //STEP 1: calculate
            //int result = Calculate(op1, opr, op2);
            int result = opr.Calculate(op1, op2);
            //Step 2: format
            string output = Formatter.FormatResult(op1, opr.GetType().Name, op2, result);

            //Step 3: calculate
            Presenter.Present(output);
        }
    public static IOperatorShapeInfo CreateOperatorShapeInfo(IOperator op) {
      IEnumerable<string> operatorParameterNames = op.Parameters.Where(p => p is IValueParameter && typeof(IOperator).IsAssignableFrom(p.DataType)).Select(p => p.Name);
      IEnumerable<string> paramaterNameValues = op.Parameters.Where(p => !(p is IValueParameter && typeof(IOperator).IsAssignableFrom(p.DataType))).Select(p => p.ToString());

      OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(operatorParameterNames, paramaterNameValues);
      operatorShapeInfo.AddConnector(PredecessorConnector);
      operatorShapeInfo.Collapsed = true;
      operatorShapeInfo.Title = op.Name;
      operatorShapeInfo.TypeName = op.GetType().GetPrettyName();
      operatorShapeInfo.Color = Color.LightBlue;
      operatorShapeInfo.LineWidth = 1;
      operatorShapeInfo.LineColor = Color.Black;
      operatorShapeInfo.Icon = new Bitmap(op.ItemImage);

      return operatorShapeInfo;
    }
        public static IOperatorShapeInfo CreateOperatorShapeInfo(IOperator op)
        {
            IEnumerable <string> operatorParameterNames = op.Parameters.Where(p => p is IValueParameter && typeof(IOperator).IsAssignableFrom(p.DataType)).Select(p => p.Name);
            IEnumerable <string> paramaterNameValues    = op.Parameters.Where(p => !(p is IValueParameter && typeof(IOperator).IsAssignableFrom(p.DataType))).Select(p => p.ToString());

            OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(operatorParameterNames, paramaterNameValues);

            operatorShapeInfo.AddConnector(PredecessorConnector);
            operatorShapeInfo.Collapsed = true;
            operatorShapeInfo.Title     = op.Name;
            operatorShapeInfo.TypeName  = op.GetType().GetPrettyName();
            operatorShapeInfo.Color     = Color.LightBlue;
            operatorShapeInfo.LineWidth = 1;
            operatorShapeInfo.LineColor = Color.Black;
            operatorShapeInfo.Icon      = new Bitmap(op.ItemImage);

            return(operatorShapeInfo);
        }
예제 #10
0
        /// <summary>
        /// Builds the expression tree from the token queue
        /// </summary>
        /// <returns></returns>
        public Expression BuildTree()
        {
            // make a copy of the queue, so that we don't empty the original queue
            Queue <Token>      tempQueue = new Queue <Token>(tokenQueue);
            Stack <Expression> exprStack = new Stack <Expression>();
            List <Expression>  args      = new List <Expression>();

            //Stack<String> literalStack = new Stack<String>();

            //var q = tempQueue.Select(x => x.value.ToString() + (x.GetType() == typeof(MemberToken) ? ":" + ((MemberToken)x).name : ""));
            //System.Diagnostics.Debug.WriteLine(string.Join("][", q.ToArray()));

            while (tempQueue.Count > 0)
            {
                Token t = tempQueue.Dequeue();

                if (t.isIdent)
                {
                    // handle numeric literals
                    exprStack.Push(Expression.Constant(t.value, t.type));
                }
                else if (t.isType)
                {
                    exprStack.Push(Expression.Constant(t.value));
                }
                //else if (t.isVariable)
                //{
                //    // handle variables
                //    string token = (string)t.value;
                //    exprStack.Push(Expression.Property(Expression.Constant(StateBag), (string)token));
                //}
                //else if (t.isParameterizer)
                //{
                //    //exprStack.Push(Expression.Property(Expression.Constant(StateBag), (string)token));
                //}
                else if (t.isOperator)
                {
                    // handle operators

                    Expression topExpression = null;
                    bool       nullOnTop     = false;
                    if (exprStack.Count > 0)
                    {
                        topExpression = exprStack.Peek();
                        if (topExpression is ConstantExpression)
                        {
                            nullOnTop = (((ConstantExpression)topExpression).Value == null);
                        }
                    }


                    Expression result = null;
                    IOperator  op     = operators[(string)t.value];
                    if (nullOnTop && op is MethodOperator)
                    {
                        continue;
                    }
                    else
                    {
                        OpFuncDelegate opfunc = OpFuncServiceLocator.Resolve(op.GetType());
                        for (int i = 0; i < t.argCount; i++)
                        {
                            args.Add(exprStack.Pop());
                        }
                        // Arguments are in reverse order
                        args.Reverse();
                        try
                        {
                            result = opfunc(new OpFuncArgs()
                            {
                                tempQueue = tempQueue, exprStack = exprStack, t = t, op = op, args = args, stack = valueStack
                            });
                            args.Clear();
                            exprStack.Push(result);
                        }
                        catch (NotInDictionaryExeception e)
                        {
                            //exprStack.Clear();
                            exprStack.Push(e.Expression);
                            //break;
                        }
                    }
                }
                //else
                //{
                //    //tempQueue.Enqueue(t);
                //    literalStack.Push((string)t.value);
                //}
            }

            // we should only have one complete expression on the stack, otherwise, something went wrong
            if (exprStack.Count == 1)
            {
                Expression pop = exprStack.Pop();
                //System.Diagnostics.Debug.WriteLine(pop.ToString());
                return(pop);
            }
            else
            {
                throw new Exception("Invalid expression");
            }

            //return null;
        }
        private void VisitOr(IOperator node)
        {
            var conditionEndpoint = node as Or;

            if (conditionEndpoint == null)
            {
                throw new InvalidOperationException(string.Format(Strings.ExTypeXIsNotSupportedYNode, node.GetType(), node.NodeType));
            }

            if (node.Source != null)
            {
                node.Source.AcceptVisitor(this);
            }
            builder.Append(" OR ");
        }
        private void VisitRoot(IOperator node)
        {
            var conditionEndpoint = node as ConditionEndpoint;

            if (conditionEndpoint == null)
            {
                throw new InvalidOperationException(string.Format(Strings.ExTypeXIsNotSupportedYNode, node.GetType(), node.NodeType));
            }
        }
예제 #13
0
        /// <summary>
        /// Converts specified expression into a Token representation and then into a Postfix Token Stack.
        /// </summary>
        /// <param name="expression">A logical infix expression.</param>
        /// <returns>Postfix Token Stack.</returns>
        public Stack <IToken> ConvertToStack(string expression)
        {
            List <IToken>  tokens = _tokenParser.ParseInfixExpression(expression);
            Stack <IToken> temp   = new Stack <IToken>();

            // Temporary container for Operators
            Stack <IOperator> operatorStack = new Stack <IOperator>();

            foreach (var token in tokens)
            {
                if (!token.IsOperatorToken())
                {
                    // Identifiers are immediately added to the output stack
                    temp.Push(token);
                }
                else
                {
                    IOperator currentOperator = (IOperator)token;

                    if (currentOperator.GetType() == typeof(CloseParanthesisGroupingOperator))
                    {
                        // Encountered closing paranthesis
                        // Iterate through Operators in the OperatorToken stack until an opening paranthesis is encountered
                        // Add each OperatorToken to the output stack

                        // Begin with the first entry in the OperatorToken stack
                        currentOperator = operatorStack.Pop();

                        // Continue until open paranthesis is encountered
                        while (currentOperator.GetType() != typeof(OpenParanthesisGroupingOperator))
                        {
                            temp.Push(currentOperator);
                            currentOperator = operatorStack.Pop();
                        }
                    }
                    else if (operatorStack.Any() &&
                             currentOperator.Precedence.HasValue &&
                             operatorStack.Peek().Precedence.HasValue&&
                             currentOperator.Precedence < operatorStack.Peek().Precedence)
                    {
                        // Current OperatorToken has a lower precedence than the top OperatorToken in the OperatorToken stack
                        // Add OperatorToken from stack to output immediately
                        temp.Push(operatorStack.Pop());
                        operatorStack.Push(currentOperator);
                    }
                    else
                    {
                        // Current OperatorToken is either:
                        // - higher precedence than top OperatorToken in the OperatorToken stack
                        // - There is no OperatorToken in the OperatorToken stack
                        // - Current OperatorToken is an opening paranthesis
                        operatorStack.Push(currentOperator);
                    }
                }
            }

            // Out of Tokens
            // Add anything in the OperatorToken stack to the output stack
            foreach (IOperator op in operatorStack)
            {
                temp.Push(op);
            }

            // Return the reverse of the output stack
            return(new Stack <IToken>(temp));
        }
예제 #14
0
        /// <summary>
        /// Builds the expression tree from the token queue
        /// </summary>
        /// <returns></returns>
        public Expression BuildTree()
        {
            if (_tokenQueue.Count == 0)
            {
                Parse();
            }

            // make a copy of the queue, so that we don't empty the original queue
            Queue <Token>      tempQueue    = new Queue <Token>(_tokenQueue);
            Stack <Expression> exprStack    = new Stack <Expression>();
            List <Expression>  args         = new List <Expression>();
            Stack <String>     literalStack = new Stack <String>();

#if DEBUG
            var q = tempQueue.Select(x => x.Value.ToString() + (x.GetType() == typeof(MemberToken) ? ":" + ((MemberToken)x).Name : ""));
            System.Diagnostics.Debug.WriteLine(string.Join("][", q.ToArray()));
#endif
            int  isCastPending = -1;
            Type typeCast      = null;

            while (tempQueue.Count > 0)
            {
                Token t = tempQueue.Dequeue();

                if (isCastPending > -1)
                {
                    isCastPending--;
                }
                if (isCastPending == 0)
                {
                    exprStack.Push(Expression.Convert(exprStack.Pop(), typeCast));
                    isCastPending = -1;
                }

                if (t.IsIdent)
                {
                    // handle numeric literals
                    exprStack.Push(Expression.Constant(t.Value, t.Type));
                }
                else if (t.IsType)
                {
                    exprStack.Push(Expression.Constant(t.Value));
                }
                else if (t.IsOperator)
                {
                    // handle operators
                    Expression result = null;
                    IOperator  op     = _operators[(string)t.Value];
                    Func <OpFuncArgs, Expression> opfunc = OpFuncServiceLocator.Resolve(op.GetType());
                    for (int i = 0; i < t.ArgCount; i++)
                    {
                        args.Add(exprStack.Pop());
                    }
                    // Arguments are in reverse order
                    args.Reverse();
                    result = opfunc(new OpFuncArgs()
                    {
                        TempQueue = tempQueue, ExprStack = exprStack, T = t, Op = op, Args = args
                    });
                    args.Clear();
                    exprStack.Push(result);
                }
                else if (t.IsCast)
                {
                    isCastPending = 2;
                    typeCast      = t.Type;
                }
            }

            // we should only have one complete expression on the stack, otherwise, something went wrong
            if (exprStack.Count == 1)
            {
                Expression pop = exprStack.Pop();
#if DEBUG
                System.Diagnostics.Debug.WriteLine(pop.ToString());
#endif
                return(pop);
            }
            else
            {
                throw new Exception("Invalid expression");
            }

            return(null);
        }