예제 #1
0
        public object Evaluate(Environment env, object target)
        {
            UserFunction user = target as UserFunction;

            if (user != null)
            {
                return(EvaluateFunction(env, user));
            }

            NativeFunction native = target as NativeFunction;

            if (native != null)
            {
                return(EvaluateNativeFunction(env, native));
            }

            throw new LepException("bad function", this);
        }
예제 #2
0
파일: ArgumentNode.cs 프로젝트: ljcleo/LEP
        protected object EvaluateFunction(Environment env, UserFunction function)
        {
            if (function == null) throw new ArgumentNullException(nameof(function), "null function");

            ParameterNode parameters = function.Parameters;
            if (Count != parameters.Count) throw new LepException("bad number of arguments", this);

            Environment inner = function.CreateEnvironment();

            int count = 0;
            foreach (IAstNode node in this) parameters.Evaluate(inner, count++, node.Evaluate(env));

            try { return function.Body.Evaluate(inner); }
            catch (JumpSignal signal)
            {
                if (signal.SignalType == JumpSignal.ReturnSignal) return signal.ReturnValue;
                else throw;
            }
        }
예제 #3
0
        protected object EvaluateFunction(Environment env, UserFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException(nameof(function), "null function");
            }

            ParameterNode parameters = function.Parameters;

            Tuple arguments = Evaluate(env) as Tuple;

            if (arguments == null)
            {
                throw new LepException("bad expression argument", this);
            }

            if (arguments.Count != parameters.Count)
            {
                throw new LepException("bad number of argument", this);
            }

            Environment inner = function.CreateEnvironment();

            for (int i = 0; i < arguments.Count; i++)
            {
                parameters.Evaluate(inner, i, arguments[i]);
            }

            try { return(function.Body.Evaluate(inner)); }
            catch (JumpSignal signal)
            {
                if (signal.SignalType == JumpSignal.ReturnSignal)
                {
                    return(signal.ReturnValue);
                }
                else
                {
                    throw;
                }
            }
        }
예제 #4
0
        protected object EvaluateFunction(Environment env, UserFunction function)
        {
            if (function == null) throw new ArgumentNullException(nameof(function), "null function");

            ParameterNode parameters = function.Parameters;

            Tuple arguments = Evaluate(env) as Tuple;
            if (arguments == null) throw new LepException("bad expression argument", this);

            if (arguments.Count != parameters.Count) throw new LepException("bad number of argument", this);

            Environment inner = function.CreateEnvironment();
            for (int i = 0; i < arguments.Count; i++) parameters.Evaluate(inner, i, arguments[i]);

            try { return function.Body.Evaluate(inner); }
            catch (JumpSignal signal)
            {
                if (signal.SignalType == JumpSignal.ReturnSignal) return signal.ReturnValue;
                else throw;
            }
        }
예제 #5
0
        protected object EvaluateFunction(Environment env, UserFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException(nameof(function), "null function");
            }

            ParameterNode parameters = function.Parameters;

            if (Count != parameters.Count)
            {
                throw new LepException("bad number of arguments", this);
            }

            Environment inner = function.CreateEnvironment();

            int count = 0;

            foreach (IAstNode node in this)
            {
                parameters.Evaluate(inner, count++, node.Evaluate(env));
            }

            try { return(function.Body.Evaluate(inner)); }
            catch (JumpSignal signal)
            {
                if (signal.SignalType == JumpSignal.ReturnSignal)
                {
                    return(signal.ReturnValue);
                }
                else
                {
                    throw;
                }
            }
        }