示例#1
0
        /// <summary>
        /// Controls proper perfoming of operation button according to whether some operation were perfomed ealier.
        /// </summary>
        private void Basic_Calculation_Single(IOperand symbol)
        {
            // To rebuild after rebuilding exceptions thrown by Parser.

            string new_ResultSpace_Text;

            if (no_operand_Sign_Single == true)
            {
                if (no_First_Number_In_Equation_Single == true)
                {
                    First_Number_In_Equation_Single = Parse_WorkSpace();

                    new_ResultSpace_Text =
                        Back_Parser.Parse_Back(first_Number_In_Equation_Single) + symbol.ToString();
                }
                else
                {
                    new_ResultSpace_Text =
                        Back_Parser.Parse_Back(first_Number_In_Equation_Single) + symbol.ToString();
                }
            }
            else if ((String.IsNullOrEmpty(WorkSpace.Text) ||
                      String.IsNullOrWhiteSpace(WorkSpace.Text)) == true)
            {
                try
                {
                    first_Number_In_Equation_Single =
                        _Calculator.Operand_Selector(Operand_Sign_Single, first_Number_In_Equation_Single, Parse_WorkSpace());

                    new_ResultSpace_Text =
                        Back_Parser.Parse_Back(first_Number_In_Equation_Single);
                }
                catch (DivideByZeroException)
                {
                    new_ResultSpace_Text = "Dividing by zero is not allowed";

                    no_operand_Sign_Single = true;

                    no_First_Number_In_Equation_Single = true;
                }
                catch
                {
                    new_ResultSpace_Text = ResultSpace.Text;

                    symbol = Operand_Sign_Single;
                }
            }
            else
            {
                new_ResultSpace_Text = ResultSpace.Text;
            }

            Reset_ResultSpace_Text(new_ResultSpace_Text);

            Operand_Sign_Single = symbol;

            Clear_WorkSpace();
        }
示例#2
0
        protected string WrapParenthesis(IOperand operand)
        {
            INativeOperation oper = operand as INativeOperation;

            if (oper != null && oper.Operands.Count > 1 && oper.AssociationType == AssociationType.Addition)
            {
                return("(" + operand.ToString() + ")");
            }
            else
            {
                return(operand.ToString());
            }
        }
示例#3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region Overrides of Object

        public override string ToString()
        {
            return(string.Format(
                       "Delegate[{0}{1}]",
                       m_Method.IsStatic ? m_Method.DeclaringType.Name + "::" : m_Target.ToString() + ".",
                       m_Method.Name));
        }
示例#4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region Overrides of Object

        public override string ToString()
        {
            var isStatic = object.ReferenceEquals(m_Target, null);

            return(string.Format(
                       "{0}Field[{1}]",
                       isStatic ? m_Property.DeclaringType.Name + "::" : m_Target.ToString() + ".",
                       m_Property.Name));
        }
示例#5
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public override string ToString()
            {
                return(string.Format(
                           "Expr<{0}>{{({1}) {2} ({3})}}",
                           typeof(TExpr).Name,
                           m_Left != null ? m_Left.ToString() : "null",
                           m_Operation,
                           m_Right != null ? m_Right.ToString() : "null"));
            }
示例#6
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region Overrides of Object

        public override string ToString()
        {
            return(string.Format(
                       "FOR ({0} ; {1} ; {2}) {3}",
                       m_PreconditionBlock.ToString(),
                       m_Condition.ToString(),
                       m_NextBlock.ToString(),
                       m_BodyBlock.ToString()));
        }
示例#7
0
 /// <summary>
 /// Controls perfomance of action buttons according to calculation options setup.
 /// </summary>
 /// <param name="_Operand"></param>
 private void Operation_Button(IOperand _Operand)
 {
     if (Convert.ToBoolean(Options.Calculation_Method == Calculation_Method.Single))
     {
         Basic_Calculation_Single(_Operand);
     }
     else if (Convert.ToBoolean(Options.Calculation_Method == Calculation_Method.Complex))
     {
         Insert_To_WorkSpace(_Operand.ToString());
     }
 }
示例#8
0
        private string ImproveOperand(IOperand op)
        {
            IPortHandler handler = Parent.FindHandler(op);

            if (handler != null)
            {
                return(handler.Identify(op.AbsoluteAddress.Value));
            }

            return(op.ToString());
        }
示例#9
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region Overrides of Object

        public override string ToString()
        {
            if (m_ConditionIsAlwaysTrue)
            {
                return(m_ThenBlock.ToString());
            }
            else
            {
                return(
                    "IF (" + m_Condition.ToString() + ") " +
                    "THEN " + m_ThenBlock.ToString() +
                    (m_ElseBlock.Count > 0 ? " ELSE " + m_ElseBlock.ToString() : ""));
            }
        }
示例#10
0
        public static AsmExpr ToAsmExpr([NotNull] this IOperand operand)
        {
            switch (operand)
            {
            case NumericOperand num:
                return(new NumericLiteral(num.Value));

            case IndirectOperand indirect:
                return(new QuoteExpr(indirect.Variable.ToAsmExpr()));

            case SumOperand sum:
                return(new AdditionExpr(sum.Left.ToAsmExpr(), sum.Right.ToAsmExpr()));

            default:
                return(new SymbolExpr(operand.ToString()));
            }
        }
示例#11
0
        /// <summary>
        /// ToString语句语法 ToString(Expression|Operand,FormatString)
        /// </summary>
        /// <param name="startLink">语句开始标记</param>
        /// <param name="endLink">语句结束标记</param>
        /// <returns></returns>
        public IOperand Key_ToString_Analyze(TOKENLink startLink, out TOKENLink endLink)
        {
            IOperand         result;
            List <TOKENLink> commaList;

            Key_analyze(startLink, out endLink, out commaList);

            if (commaList.Count == 0)
            {
                _analyze.Analyze(startLink.Next.Next, endLink.Prev);
            }
            else if (commaList.Count == 1)
            {
                result = _analyze.Analyze(startLink.Next.Next, commaList[0].Prev);

                if (result.Type != EDataType.Ddatetime)
                {
                    throw new Exception(string.Format("Error! 关键字“{0}”(索引:{1}) 第一表达式无法转换为“datatime”",
                                                      ((TOKEN <KeyWord>)startLink.Token).Tag.Value, startLink.Token.Index.ToString()));
                }

                IOperand format = _analyze.Analyze(commaList[0].Next, endLink.Prev);

                try
                {
                    DateTime.Now.ToString(format.ToString());
                }
                catch
                {
                    throw new Exception(string.Format("Error! 关键字“{0}”(索引:{1}) 日期转换格式有误“{2}”",
                                                      ((TOKEN <KeyWord>)startLink.Token).Tag.Value, startLink.Token.Index.ToString(), format.ToString()));
                }

                return(new Operand <string>(EDataType.Dstring, ((Operand <DateTime>)result).TValue.ToString(((TOKEN <IOperand>)commaList[0].Next.Token).Tag.ToString())));
            }
            else
            {
                throw new Exception(string.Format("Error! 关键字“{0}”(索引:{1})表达式过多",
                                                  ((TOKEN <KeyWord>)startLink.Token).Tag.Value, startLink.Token.Index.ToString()));
            }

            return(new Operand <string>(EDataType.Dstring, ""));
        }
示例#12
0
        public static void Crop(int x1, int y1, int x2, int y2, IOperand x = null, bool spawn = true)
        {
            if (x == null)
            {
                x = ExecutionStack.X;
            }
            if (x == null)
            {
                return;
            }
            Rectangle crect = new Rectangle(x1, y1, x2 - x1, y2 - y1);

            using (Bitmap cbmp = new Bitmap(crect.Width, crect.Height))
            {
                float[][][] old = Normalize.ToFloat(x.GetBitmap());
                float[][][] img = Normalize.ToFloat(cbmp);
                for (int c = 0; c < Normalize.RGBPLANE_LENGTH; c++)
                {
                    for (int w = 0; w < crect.Width; w++)
                    {
                        for (int h = 0; h < crect.Height; h++)
                        {
                            img[c][h][w] = old[c][h + y1][w + x1];
                        }
                    }
                }
                if (spawn)
                {
                    x.CreateSibling(img, "Crop of " + x.ToString());
                }
                else
                {
                    ((FormStandard)x).Image = Normalize.FromFloat(img);
                }
            }
        }
示例#13
0
 protected string WrapParenthesis(IOperand operand)
 {
     INativeOperation oper = operand as INativeOperation;
     if (oper != null && oper.Operands.Count > 1 && oper.AssociationType == AssociationType.Addition)
     {
         return "(" + operand.ToString() + ")";
     }
     else
     {
         return operand.ToString();
     }
 }
示例#14
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public override string ToString()
        {
            return(string.Format(
                       "{0}Field[{1}]",
                       m_FieldInfo.IsStatic ? m_FieldInfo.DeclaringType.Name + "::" : m_Target.ToString() + ".",
                       m_Name));
        }
示例#15
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region Overrides of Object

        public override string ToString()
        {
            return(
                "WHILE (" + m_Condition.ToString() + ") " +
                m_BodyBlock.ToString());
        }
示例#16
0
        /// <summary>
        /// ToString语句语法 ToString(Expression|Operand,FormatString)
        /// </summary>
        /// <param name="startLink">语句开始标记</param>
        /// <param name="endLink">语句结束标记</param>
        /// <returns></returns>
        public IOperand Key_ToString(TOKENLink startLink, out TOKENLink endLink)
        {
            IOperand         result;
            List <TOKENLink> commaList;

            Key_Analyze(startLink.Next, out endLink, out commaList);

            if (commaList.Count == 0)
            {
                result = _eval.ExpressionEvaluate(startLink.Next.Next, endLink.Prev);
                return(new Operand <string>(EDataType.Dstring, result.ToString()));
            }
            else
            {
                result = _eval.ExpressionEvaluate(startLink.Next.Next, commaList[0].Prev);
                IOperand format = _eval.ExpressionEvaluate(commaList[0].Next, endLink.Prev);
                return(new Operand <string>(EDataType.Dstring, ((Operand <DateTime>)result).TValue.ToString(format.ToString())));
            }
        }