/// <summary>
        /// Execute the expression list.
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public object Evaluate(IScopeContext c)
        {
            var             newcontext = new ScopeContext(c);
            object          result     = null;
            Action <object> saver      = a => { result = a; };

            newcontext.AddExpressionStatementEvaluationCallback(saver);
            try
            {
                foreach (var s in Statements)
                {
                    s.Evaluate(newcontext);
                }

                return(result);
            }
            finally
            {
                c.RemoveExpressionStatementEvaluationCallback(saver);
            }
        }
Пример #2
0
        /// <summary>
        /// Parse and evaluate a single line of script. Done in place, and immediately, and in the
        /// global scope.
        /// </summary>
        /// <param name="scriptline">text to execute</param>
        /// <returns>Whatever the value of the script line is</returns>
        public static object eval(IScopeContext c, string scriptline)
        {
            var             statements = Grammar.ModuleParser.End().Parse(scriptline);
            object          result     = null;
            Action <object> saver      = o => result = o;

            c.AddExpressionStatementEvaluationCallback(saver);

            try
            {
                foreach (var s in statements)
                {
                    s.Evaluate(c);
                }
            }
            finally
            {
                c.RemoveExpressionStatementEvaluationCallback(saver);
            }
            return(result);
        }