public override CalcValue GetValue(CLLocalStore vars = null, CLContextProvider context = null)
        {
            vars ??= new CLLocalStore();
            context ??= new CLContextProvider();

            CalcObject obj = GetObject(vars, context);

            vars = new CLLocalStore(Params);

            return(obj.GetValue(vars, context));
        }
        public override CalcValue GetValue(CLLocalStore vars = null, CLContextProvider context = null)
        {
            vars ??= new CLLocalStore();
            context ??= new CLContextProvider();

            CalcValue[] ret = new CalcValue[_list.Length];

            for (int i = 0; i < _list.Length; i++)
            {
                ret[i] = _list[i].GetValue(vars);
            }

            return(new CalcList(ret));
        }
        public override CalcValue GetValue(CLLocalStore vars = null, CLContextProvider context = null)
        {
            vars ??= new CLLocalStore();
            context ??= new CLContextProvider();

            if (Operator is CLBinaryOperator bin)
            {
                return(bin.Run(Left, Right, vars, context));
            }
            else if (Operator is CLPrefixOperator pre)
            {
                return(pre.Run(Right, vars, context));
            }
            else if (Operator is CLPostfixOperator post)
            {
                return(post.Run(Left, vars, context));
            }
            else
            {
                throw new InvalidCastException("Operators must be binary, prefix, or postfix.");
            }
        }
Beispiel #4
0
 /// <summary>
 /// Evaluates this <c>CalcObject</c> and returns its value.
 /// </summary>
 /// <param name="vars">A <c>CLLocalStore</c> that stores local
 ///   variables.</param>
 /// <param name="context">The object representing the context in which
 ///   the expression is being evaluated.</param>
 public abstract CalcValue GetValue(CLLocalStore store = null, CLContextProvider context = null);
 public override CalcValue GetValue(CLLocalStore vars = null, CLContextProvider context = null)
 {
     vars ??= new CLLocalStore();
     context ??= new CLContextProvider();
     return(Function.FunctionDef.Invoke(Params, vars, context));
 }
 /// <summary>
 /// Evaluates this <c>CalcExpression</c> and returns the result.
 /// </summary>
 /// <param name="vars">A <c>CLLocalStore</c> that stores local
 ///   variables.</param>
 /// <param name="context">The object representing the context in which
 ///   the expression is being evaluated.</param>
 public abstract override CalcValue GetValue(CLLocalStore vars = null, CLContextProvider context = null);
        /// <summary>
        /// Returns the object referenced by the name.
        /// </summary>
        /// <param name="vars">A <c>CLLocalStore</c> that stores local
        ///   variables.</param>
        /// <param name="context">The object representing the context in which
        ///   the expression is being evaluated.</param>
        public CalcObject GetObject(CLLocalStore vars = null, CLContextProvider context = null)
        {
            vars ??= new CLLocalStore();
            context ??= new CLContextProvider();

            if (Name.StartsWith("!"))
            {
                if (CLCodeFunction.Exists(Name.Substring(1)))
                {
                    return(new CalcCodeFunction(Name.Substring(1), Params));
                }
            }

            if (Name.StartsWith("_") || Name.StartsWith("^"))
            {
                if (!(vars.ContainsVar(Name)))
                {
                    throw new CLException("No variable named " + Name + " exists.");
                }
                else
                {
                    return(vars[Name]);
                }
            }

            int count = 0;

            if (Int32.TryParse(Name, out count))
            {
                if (count == 0)
                {
                    return(new CalcString(Name));
                }
                if (vars.ParamCount >= count)
                {
                    return(vars[count - 1]);
                }
                else if (Params.Length > 0)
                {
                    return(Params[0]);
                }
                else
                {
                    throw new CLException("No parameter #" + count + " exists.");
                }
            }

            if (Name == "...")
            {
                return(new CalcListExpression(vars.CopyParams()));
            }

            CalcObject ret = CLVariables.Load(Name, context);

            if (ret != null)
            {
                return(ret);
            }

            throw new CLException("No variable named " + Name + " exists.");
        }
 public sealed override CalcValue GetValue(CLLocalStore vars, CLContextProvider context = null) => this;