예제 #1
0
        internal override Literal Execute(IConstruct argument1, IConstruct argument2)
        {
            var argument2Transformed = base.GetTransformedConstruct <Literal>(argument2);

            var existingVariable = Program.Variables.SingleOrDefault(x => x.Name == argument1.ToString().Split(':')[0]);

            if (existingVariable == null)
            {
                Program.Variables.Add(new Variable(argument1.ToString().Split(':')[0], argument2Transformed));
            }
            else
            {
                existingVariable.Construct = argument2Transformed;
            }

            return(base.Empty());
        }
예제 #2
0
        internal override Literal Execute(IConstruct argument1, IConstruct argument2)
        {
            var argument2Value = base.GetTransformedConstruct<Number>(argument2);

            if (argument2Value == 0)
                throw new DivideByZeroException(argument2.ToString());

            return base.GetTransformedConstruct<Number>(argument1) / argument2Value;
        }
예제 #3
0
        internal override Literal Execute(IConstruct argument1, IConstruct argument2)
        {
            var argument2Value = base.GetTransformedConstruct <Number>(argument2);

            if (argument2Value == 0)
            {
                throw new DivideByZeroException(argument2.ToString());
            }

            return(base.GetTransformedConstruct <Number>(argument1) / argument2Value);
        }
예제 #4
0
        public static JTokenType ConvertInterpreterArrayTypeIntoJTokenType(IConstruct l)
        {
            string expectedValueType = l.GetType().Name;

            if (expectedValueType == "Variable")
            {
                Variable v = l as Variable;
                return(ConvertInterpreterArrayTypeIntoJTokenType(v.Value));
            }
            else if (expectedValueType == "Array")
            {
                var a = (l as HiSystems.Interpreter.Array).ToList();
                if (a.Count > 0)
                {
                    return(ConvertInterpreterTypeIntoJTokenType(a[0]));
                }
                else
                {
                    throw new System.ArgumentException($"ConvertInterpreterArrayTypeIntoJTokenType() cannot infer the type of the array because the array is empty, l:{l.ToString()} ");
                }
            }
            else
            {
                throw new System.ArgumentException($"ConvertInterpreterArrayTypeIntoJTokenType() requires an array as first parameter, received:${l.ToString()}");
            }
        }
예제 #5
0
        /// <summary>
        /// Throws an exception if the argument passed, via the argument index is not the expected type.
        /// ArgumentIndex is only used for the error message and should match the index of the argument that is passed.
        /// </summary>
        private T CastArgumentToType <T>(IConstruct argument, int argumentIndex)
        {
            if (!(argument is T))
            {
                throw new InvalidOperationException(String.Format("Argument {1}: {0} is not of type {2} and cannot be used with the {3} function", argument.ToString(), argumentIndex + 1, typeof(T).Name, this.Name));
            }

            return((T)argument);
        }
예제 #6
0
        /// <summary>
        /// Throws an exception if the argument passed is not the expected type.
        /// </summary>
        private T CastConstructToType <T>(IConstruct construct)
        {
            if (!(construct is T))
            {
                throw new InvalidOperationException(String.Format("{0} construct is not of type {1} and cannot be used with the {2} operator", construct.ToString(), typeof(T).Name, this.Token));
            }

            return((T)construct);
        }