Exemplo n.º 1
0
        public override object VisitExpressionReference(ShapPangParser.ExpressionReferenceContext context)
        {
            IValue val  = CurrentScenario.ResolveReference(context.ID().GetText(), ParsingContext.ElementScope.ElementName);
            string temp = val.GetType().ToString();

            switch (val.GetType().ToString())
            {
            case "ShapPang.Classes.Given":
                Given giv = (Given)val;
                if (giv.Description == null)
                {
                    CurrentScenario.CurrentlyBuildingExplanation += " the given " + giv.Key + " (" + giv.Value.ToString() + ")";
                }
                else
                {
                    CurrentScenario.CurrentlyBuildingExplanation += giv.Description;
                }
                break;

            case "ShapPang.Classes.Derivative":
                Derivative div = (Derivative)val;
                CurrentScenario.CurrentlyBuildingExplanation += " the derivation of " + div.Name + " (";
                if (div.Calculated == false)
                {
                    div.CalculateDerivative();
                }
                CurrentScenario.CurrentlyBuildingExplanation += " which equals " + div.Value.ToString() + ")";
                break;
            }
            return(val.Value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method takes a reference to a derivative and forces a calculation of it's value.
        /// </summary>
        /// <param name="derivativeReference">A reference in the form "X.Y"</param>
        /// <param name="description">A description string to be filled with the derivations method.</param>
        /// <returns>The decimal value of the calculation.</returns>
        public decimal CalculateDerivative(string derivativeReference, out string description)
        {
            CurrentlyBuildingExplanation = "";
            string[] references = derivativeReference.Split('.');
            Element  el         = this.Elements.Find(t => t.ElementName == references[0]);

            if (el == null)
            {
                throw new ArgumentException("Provided element reference does not exist in this scenario.");
            }
            Derivative der = el.Derivations.Find(t => t.Name == references[1]);

            if (der == null)
            {
                throw new ArgumentException("Provided derivative reference does not exist in the discovered element");
            }
            CurrentlyBuildingExplanation += el.ElementName + " contains a " + der.Name + ", " + der.Description;
            der.CalculateDerivative();
            description = CurrentlyBuildingExplanation += " yielding a value of " + der.Value.ToString() + ".";
            return(der.Value);
        }
Exemplo n.º 3
0
 internal void AddDerivation(Derivative der)
 {
     parseContext.ElementScope.Derivations.Add(der);
 }
Exemplo n.º 4
0
 public ShapExecutionVisitor(Derivative derivative, ParsingContext Context)
 {
     this.CurrentDerivation = derivative;
     this.ParsingContext    = Context;
     CurrentScenario        = derivative.Scenario;
 }