Ejemplo n.º 1
0
 /// <summary>
 /// Rename all the variables in this block
 /// </summary>
 /// <param name="origName"></param>
 /// <param name="newName"></param>
 public override void RenameVariable(string origName, string newName)
 {
     ArrayLength.RenameRawValue(origName, newName);
     InitialValue.RenameRawValue(origName, newName);
     _loopVariable.RenameParameter(origName, newName);
     RenameBlockVariables(origName, newName);
 }
Ejemplo n.º 2
0
 public override string Print(int depth)
 {
     return("loop " + LoopVariable + ":" + InitialValue.Print(depth) + " " + StepDirection + " " +
            EndingValue.Print(depth)
            + (Step == null ? string.Empty : " with " + Step.Print(depth)) + NewLine(depth)
            + "{" + Statements.Print(depth + 1) + "}");
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            Values.IValue retVal = null;

            Values.ListValue value = ListExpression.GetValue(context) as Values.ListValue;
            if (value != null)
            {
                int token = PrepareIteration(context);
                context.LocalScope.setVariable(AccumulatorVariable);
                AccumulatorVariable.Value = InitialValue.GetValue(context);

                foreach (Values.IValue v in value.Val)
                {
                    if (v != EFSSystem.EmptyValue)
                    {
                        IteratorVariable.Value = v;
                        if (conditionSatisfied(context))
                        {
                            AccumulatorVariable.Value = IteratorExpression.GetValue(context);
                        }
                    }
                    NextIteration();
                }
                EndIteration(context, token);
                retVal = AccumulatorVariable.Value;
            }
            else
            {
                AddError("Cannot evaluate list value " + ListExpression.ToString());
            }

            return(retVal);
        }
Ejemplo n.º 4
0
      public string ToDisplayString()
      {
         string nullable = Required ? string.Empty : "?";
         string initial = !string.IsNullOrEmpty(InitialValue) ? $" = {InitialValue.Trim('"')}" : string.Empty;

         return $"{Name}: {Type}{nullable}{LengthDisplay()}{initial}";
      }
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            LastIteration.Value = InitialValue.GetValue(context);

            bool stop = false;

            while (!stop)
            {
                int token = context.LocalScope.PushContext();
                context.LocalScope.setVariable(LastIteration);
                CurrentIteration.Value = Expression.GetValue(context);

                context.LocalScope.setVariable(CurrentIteration);
                Values.BoolValue stopCondition = Condition.GetValue(context) as Values.BoolValue;
                if (stopCondition != null)
                {
                    stop = stopCondition.Val;
                }
                else
                {
                    AddError("Cannot evaluate condition " + Condition.ToString());
                    stop = true;
                }
                context.LocalScope.PopContext(token);
                LastIteration.Value = CurrentIteration.Value;
            }

            return(CurrentIteration.Value);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Checks the expression and appends errors to the root tree node when inconsistencies are found
        /// </summary>
        public override void CheckExpression()
        {
            base.CheckExpression();

            Type initialValueType = InitialValue.GetExpressionType();

            if (initialValueType != null)
            {
                Collection listExpressionType = ListExpression.GetExpressionType() as Collection;
                if (listExpressionType != null)
                {
                    IteratorExpression.CheckExpression();
                }
            }
            else
            {
                AddError("Cannot determine initial value expression type for " + ToString(), RuleChecksEnum.SemanticAnalysisError);
            }


            bool refToResultFound = false;

            foreach (Usage usage in IteratorExpression.StaticUsage.AllUsages)
            {
                if (usage.Referenced == AccumulatorVariable && usage.Mode == Usage.ModeEnum.Read)
                {
                    refToResultFound = true;
                    break;
                }
            }
            if (!refToResultFound)
            {
                AddError("REDUCE expressions should reference RESULT variable", RuleChecksEnum.SyntaxError);
            }
        }
Ejemplo n.º 7
0
        public override void Draw(System.Drawing.Graphics g)
        {
            Pen p = new Pen(Selected ? System.Drawing.Color.Red : System.Drawing.Color.Black);

            g.DrawRectangle(p, DrawRect);
            g.DrawString(InitialValue.ToString(), DCSFont, p.Brush, X, Y);
        }
Ejemplo n.º 8
0
      /// <summary>Returns a string that represents the current object.</summary>
      /// <remarks>Output is, in order:
      /// <ul>
      /// <li>Visibility</li>
      /// <li>Type (with optional '?' if not a required field</li>
      /// <li>Max length in brackets, if a string field and length is specified</li>
      /// <li>Name (with optional '!' if an identity field</li>
      /// <li>an equal sign (=) followed by an initializer, if an initializer is specified</li>
      /// </ul>
      /// </remarks>
      /// <returns>A string that represents the current object.</returns>
      public override string ToString()
      {
         List<string> parts = new List<string>
                              {
                                 SetterVisibility.ToString().ToLower(),
                                 $"{Type}{(Required ? string.Empty : "?")}"
                              };

         if (Type?.ToLower() == "string")
         {
            // if a min length is present, output both the min and max
            // otherwise, just the max, if present
            if (MinLength > 0)
               parts.Add($"[{MinLength}-{MaxLength}]");
            else if (MaxLength > 0)
               parts.Add($"[{MaxLength}]");
         }

         parts.Add($"{Name}{(IsIdentity ? "!" : string.Empty)}");

         if (!string.IsNullOrEmpty(InitialValue))
         {
            string initialValue = InitialValue;

            // make sure string initial values are in quotes, but don't duplicate quotes if already present
            if (Type?.ToLower() == "string")
               initialValue = $"\"{InitialValue.Trim('"')}\"";

            parts.Add($"= {initialValue}");
         }

         // get rid of the space between type name and length, if any
         return string.Join(" ", parts).Replace(" [", "[");
      }
 private void AssociatedObject_Initialized(object sender, EventArgs e)
 {
     //LastKnowCaretPosition = 1;
     ((TextBox)sender).Text      = InitialValue.ToString();
     AssociatedObject.CaretIndex = InitialValue.ToString().Length;
     AssociatedObject.Focus();
 }
 public override void VisitChildren(IVisitor visitor)
 {
     if (InitialValue != null)
     {
         InitialValue.Visit(visitor);
     }
 }
Ejemplo n.º 11
0
        public static async Task <OutputPort> Create(int pin, InitialValue initial, IGpioDriver driver = null)
        {
            var port = await Create(pin, driver ?? new FileDriver());

            await port.SetDirection(initial == InitialValue.High?GpioDirection.High : GpioDirection.Low);

            return(port);
        }
Ejemplo n.º 12
0
 private void ScaleY_Point(Rectangle _point, InitialValue _initialeValue, double _minValue, double _yScale)
 {
     if (_initialeValue.Value < _minValue)
     {
         MessageBox.Show("Вот.");
     }
     Canvas.SetBottom(_point, Y_Set(_initialeValue, _minValue, _yScale));
 }
Ejemplo n.º 13
0
      /// <summary>Returns a string that represents the current object.</summary>
      /// <remarks>Output is, in order:
      /// <ul>
      /// <li>Visibility</li>
      /// <li>Type (with optional '?' if not a required field</li>
      /// <li>Min/Max length in brackets, if a string field and length(s) is/are specified</li>
      /// <li>Name (with optional '!' if an identity field</li>
      /// <li>an equal sign (=) followed by an initializer, if an initializer is specified</li>
      /// </ul>
      /// </remarks>
      /// <returns>A string that represents the current object. Note that this is a parsable string when turning back to a ModelAttribute.</returns>
      public override string ToString()
      {
         string visibility = SetterVisibility.ToString().ToLower();
         string identity = IsIdentity ? "!" : string.Empty;

         string nullable = Required ? string.Empty : "?";
         string initial = !string.IsNullOrEmpty(InitialValue) ? $" = {InitialValue.Trim('"')}" : string.Empty;

         return $"{visibility} {Type}{nullable}{LengthDisplay()} {Name}{identity}{initial}";
      }
Ejemplo n.º 14
0
        /// <summary>
        /// Rename the parameter name to the new name as long as it matches the old name.
        /// </summary>
        /// <param name="oldname"></param>
        /// <param name="newname"></param>
        public void RenameParameter(string oldname, string newname)
        {
            if (ParameterName == oldname)
            {
                ParameterName = newname;
            }

            if (InitialValue != null)
            {
                InitialValue.RenameRawValue(oldname, newname);
            }
        }
Ejemplo n.º 15
0
        private void ScaleY_Gistogramm(Rectangle _gistogramm, InitialValue _initialeValue, double _minValue, double _yScale)
        {
            // -! ЗДЕСЬ КОСЯК (_initialeValue < _minValue так быть не должно)-
            //костыль
            double h = Y_Set(_initialeValue, _minValue, _yScale);

            if (h < 0)
            {
                h = 0;
            }
            //--------------------
            _gistogramm.Height = h;
        }
Ejemplo n.º 16
0
    void Update()
    {
        initial = GameObject.FindObjectOfType <InitialValue>();

        if (comparedValueField.GetComponent <Text>().text != "")
        {
            comparedValue = comparedValueField.GetComponent <Text>().text;
        }
        if (comparingValueField.GetComponent <Text>().text != "")
        {
            comparingValue = comparingValueField.GetComponent <Text>().text;
        }
    }
Ejemplo n.º 17
0
        /// <summary>
        /// Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(Utils.INamable instance, Filter.AcceptableChoice expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                InitialValue.SemanticAnalysis(instance, Filter.AllMatches);

                AccumulatorVariable.Type = InitialValue.GetExpressionType();
            }

            return(retVal);
        }
Ejemplo n.º 18
0
    // Update is called once per frame
    void Update()
    {
        initial = GameObject.FindObjectOfType <InitialValue>();

        if (variableNameField.GetComponent <Text>().text != "")
        {
            variableName = variableNameField.GetComponent <Text>().text;
        }
        if (valueField.GetComponent <Text>().text != "")
        {
            value = valueField.GetComponent <Text>().text;
        }
    }
Ejemplo n.º 19
0
        private int CalculateProjectedCount(TimePeriod timePeriod, InitialValue initialValue)
        {
            TimeSpan span  = timePeriod.EndTime - timePeriod.StartTime;
            int      count = (int)(span.Ticks / TimeSpan.TicksPerSecond);

            if (timePeriod.StartTime.Ticks % TimeSpan.TicksPerSecond > 0 && initialValue != InitialValue.None)
            {
                // start is at fraction of a second, add one if initial value requested
                count++;
            }

            return(count);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Provides the surface of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the surface</param>
        /// <param name="xParam">The X axis of this surface</param>
        /// <param name="yParam">The Y axis of this surface</param>
        /// <param name="explain"></param>
        /// <returns>The surface which corresponds to this expression</returns>
        public override Surface CreateSurface(InterpretationContext context, Parameter xParam, Parameter yParam,
                                              ExplanationPart explain)
        {
            Surface retVal = base.CreateSurface(context, xParam, yParam, explain);

            Surface surface = InitialValue.CreateSurface(context, xParam, yParam, explain);

            if (surface != null)
            {
                ListValue value = ListExpression.GetValue(context, explain) as ListValue;
                if (value != null)
                {
                    int token = PrepareIteration(context);
                    AccumulatorVariable.Value = surface.Function;

                    foreach (IValue v in value.Val)
                    {
                        if (v != EfsSystem.Instance.EmptyValue)
                        {
                            // All elements should always be != from EmptyValue
                            ElementFound           = true;
                            IteratorVariable.Value = v;
                            if (ConditionSatisfied(context, explain))
                            {
                                MatchingElementFound      = true;
                                AccumulatorVariable.Value = IteratorExpression.GetValue(context, explain);
                            }
                        }
                        NextIteration();
                    }
                    Function function = AccumulatorVariable.Value as Function;
                    if (function != null)
                    {
                        retVal = function.Surface;
                    }
                    else
                    {
                        throw new Exception("Expression does not reduces to a function");
                    }
                    EndIteration(context, explain, token);
                }
            }
            else
            {
                throw new Exception("Cannot create surface for initial value " + InitialValue);
            }
            retVal.XParameter = xParam;
            retVal.YParameter = yParam;

            return(retVal);
        }
Ejemplo n.º 21
0
        public void OnCalculate()
        {
            try
            {
                dynamic initTemp = InitialValue;
                this.InitialValue = Convert.ToDecimal(Regex.Replace(InitialValue.ToString(), "-", ""));

                var     initialValue      = Convert.ToDouble(InitialValue.ToString().Contains("-") ? InitialValue : Convert.ToDecimal("-" + InitialValue));
                var     diff              = UpperBoundRate - LowerBoundRate;
                int     numberOfIncrement = Convert.ToInt32(diff / Increment);
                decimal lbr       = LowerBoundRate;
                decimal ValueRate = Increment;
                for (int i = 1; i <= numberOfIncrement; i++)
                {
                    //CashFlow 1
                    var discountFactor1 = 1 / Math.Pow(Convert.ToDouble(1 + lbr), 1);
                    var presentValue1   = discountFactor1 * Convert.ToDouble(CashFlow1);

                    //CashFlow 2
                    var discountFactor2 = 1 / Math.Pow(Convert.ToDouble(1 + lbr), 2);
                    var presentValue2   = discountFactor2 * Convert.ToDouble(CashFlow2);

                    //CashFlow 2
                    var discountFactor3 = 1 / Math.Pow(Convert.ToDouble(1 + lbr), 3);
                    var presentValue3   = discountFactor3 * Convert.ToDouble(CashFlow3);

                    var totalPresentValue = initialValue + presentValue1 + presentValue2 + presentValue3;

                    NetPresentationValueModel netPV = new NetPresentationValueModel();

                    lbr       += Increment;
                    ValueRate += Increment;

                    netPV.InitialValue   = initTemp;
                    netPV.DiscountRate   = lbr;
                    netPV.NPV            = Convert.ToDecimal(totalPresentValue);
                    netPV.CashFlowAmount = InitialValue + Convert.ToDecimal(totalPresentValue);
                    netPV.DateCreated    = DateTime.Now;

                    NPVModelList.Add(netPV);
                    this.SaveNPV(netPV.InitialValue, netPV.CashFlowAmount, netPV.DiscountRate, netPV.NPV);
                }
                InitialValue = initTemp;
            }

            catch (Exception ex)

            {
                MessageBox.Show(ex.Message + " Fill all filelds with correct values.", "Net Presentation Value");
            }
        }
Ejemplo n.º 22
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Size.GetHashCode();
         hashCode = (hashCode * 397) ^ Polynomial.GetHashCode();
         hashCode = (hashCode * 397) ^ InitialValue.GetHashCode();
         hashCode = (hashCode * 397) ^ FinalXorValue.GetHashCode();
         hashCode = (hashCode * 397) ^ ReflectInput.GetHashCode();
         hashCode = (hashCode * 397) ^ ReflectOutput.GetHashCode();
         hashCode = (hashCode * 397) ^ ExpectedCheck.GetHashCode();
         return(hashCode);
     }
 }
Ejemplo n.º 23
0
 public string Extract(IRow row)
 {
     try
     {
         var field = InitialValue.GetValue(row);
         foreach (var filter in Filters)
         {
             field = filter.Apply(field);
         }
         return(field);
     }
     catch (Exception ex)
     { throw new ExtractedValueException(this, row, InitialValue, ex); }
 }
Ejemplo n.º 24
0
      public string ToDisplayString()
      {
         string nullable = Required ? string.Empty : "?";
         string initial = !string.IsNullOrEmpty(InitialValue) ? $" = {InitialValue.Trim('"')}" : string.Empty;

         string lengthDisplay = "";

         if (MinLength > 0)
            lengthDisplay = $"[{MinLength}-{(MaxLength > 0 ? MaxLength.ToString() : "")}]";
         else if (MaxLength > 0)
            lengthDisplay = $"[{MaxLength}]";

         return $"{Name}: {Type}{nullable}{lengthDisplay}{initial}";
      }
Ejemplo n.º 25
0
        public override void AcceptVisitor(StatementVisitor visitor)
        {
            visitor.VisitVariableDeclaraitonStatement(this);

            if (Variable != null)
            {
                visitor.VisitReferenceToLocalVariable(Variable);
            }

            if (InitialValue != null)
            {
                InitialValue.AcceptVisitor(visitor);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Provides the callable that is called by this expression
        /// </summary>
        /// <param name="context"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override ICallable GetCalled(InterpretationContext context, ExplanationPart explain)
        {
            ICallable retVal = null;

            Function function = InitialValue.Ref as Function;

            if (function == null)
            {
                function = InitialValue.GetCalled(context, explain) as Function;
            }

            if (function != null)
            {
                if (function.FormalParameters.Count == 1)
                {
                    int token = context.LocalScope.PushContext();
                    context.LocalScope.SetGraphParameter((Parameter)function.FormalParameters[0]);
                    Graph graph = CreateGraph(context, (Parameter)function.FormalParameters[0], explain);
                    context.LocalScope.PopContext(token);
                    if (graph != null)
                    {
                        retVal = graph.Function;
                    }
                }
                else if (function.FormalParameters.Count == 2)
                {
                    int token = context.LocalScope.PushContext();
                    context.LocalScope.SetSurfaceParameters((Parameter)function.FormalParameters[0],
                                                            (Parameter)function.FormalParameters[1]);
                    Surface surface = CreateSurface(context, (Parameter)function.FormalParameters[0],
                                                    (Parameter)function.FormalParameters[1], explain);
                    context.LocalScope.PopContext(token);
                    if (surface != null)
                    {
                        retVal = surface.Function;
                    }
                }
                else
                {
                    AddError("Cannot evaluate REDUCE expression to a function", RuleChecksEnum.ExecutionFailed);
                }
            }
            else
            {
                AddError("Cannot evaluate REDUCE expression to a function", RuleChecksEnum.ExecutionFailed);
            }

            return(retVal);
        }
Ejemplo n.º 27
0
 public string GetStringValue()
 {
     if (SetToDefault || SetToNull || SetToUndefined)
     {
         return(null);
     }
     else if (SetToEmptyString)
     {
         return("");
     }
     else
     {
         return(InitialValue.ToString());
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        ///     Creates the graph associated to this expression, when the given parameter ranges over the X axis
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <param name="parameter">The parameters of *the enclosing function* for which the graph should be created</param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = base.CreateGraph(context, parameter, explain);

            Graph graph = InitialValue.CreateGraph(context, parameter, explain);

            if (graph != null)
            {
                ListValue value = ListExpression.GetValue(context, explain) as ListValue;
                if (value != null)
                {
                    int token = PrepareIteration(context);
                    AccumulatorVariable.Value = graph.Function;

                    foreach (IValue v in value.Val)
                    {
                        if (v != EfsSystem.Instance.EmptyValue)
                        {
                            // All elements should always be != from EmptyValue
                            ElementFound           = true;
                            IteratorVariable.Value = v;
                            if (ConditionSatisfied(context, explain))
                            {
                                MatchingElementFound      = true;
                                AccumulatorVariable.Value = IteratorExpression.GetValue(context, explain);
                            }
                        }
                        NextIteration();
                    }
                    Function function = AccumulatorVariable.Value as Function;
                    if (function != null)
                    {
                        retVal = function.Graph;
                    }
                    else
                    {
                        retVal = Function.CreateGraphForValue(AccumulatorVariable.Value);
                    }
                    EndIteration(context, explain, token);
                }
            }
            else
            {
                throw new Exception("Cannot create graph for initial value " + InitialValue);
            }

            return(retVal);
        }
        /// <summary>
        /// Performs the semantic analysis of the expression
        /// </summary>
        /// <param name="instance">the reference instance on which this element should analysed</param>
        /// <paraparam name="expectation">Indicates the kind of element we are looking for</paraparam>
        /// <returns>True if semantic analysis should be continued</returns>
        public override bool SemanticAnalysis(Utils.INamable instance, Filter.AcceptableChoice expectation)
        {
            bool retVal = base.SemanticAnalysis(instance, expectation);

            if (retVal)
            {
                InitialValue.SemanticAnalysis(instance, Filter.IsRightSide);
                Expression.SemanticAnalysis(instance, Filter.AllMatches);
                Condition.SemanticAnalysis(instance, Filter.AllMatches);

                LastIteration.Type    = InitialValue.GetExpressionType();
                CurrentIteration.Type = InitialValue.GetExpressionType();
            }

            return(retVal);
        }
Ejemplo n.º 30
0
      /// <summary>Returns a string that represents the current object.</summary>
      /// <remarks>Output is, in order:
      /// <ul>
      /// <li>Visibility</li>
      /// <li>Type (with optional '?' if not a required field</li>
      /// <li>Max length in brackets, if a string field and length is specified</li>
      /// <li>Name (with optional '!' if an identity field</li>
      /// <li>an equal sign (=) followed by an initializer, if an initializer is specified</li>
      /// </ul>
      /// </remarks>
      /// <returns>A string that represents the current object.</returns>
      public override string ToString()
      {
         string visibility = SetterVisibility.ToString().ToLower();
         string identity = IsIdentity ? "!" : string.Empty;

         string nullable = Required ? string.Empty : "?";
         string initial = !string.IsNullOrEmpty(InitialValue) ? $" = {InitialValue.Trim('"')}" : string.Empty;

         string lengthDisplay = "";

         if (MinLength > 0)
            lengthDisplay = $"[{MinLength}-{(MaxLength > 0 ? MaxLength.ToString() : "")}]";
         else if (MaxLength > 0)
            lengthDisplay = $"[{MaxLength}]";

         return $"{visibility} {Type}{nullable}{lengthDisplay} {Name}{identity}{initial}";
      }