Ejemplo n.º 1
0
        /// <summary>
        /// Updates the provided scope with the new variable value.
        /// </summary>
        /// <param name="scope">The scope object containing variable values and function parameters.</param>
        /// <returns>
        ///   <c>null</c> if successful, or a <see cref="ParseErrorExpression" /> if not.
        /// </returns>
        public ParseErrorExpression Evaluate(InterpreterScope scope)
        {
            var assignmentScope = new InterpreterScope(scope)
            {
                Context = this
            };
            ExpressionBase result;

            var functionDefinition = Value as FunctionDefinitionExpression;

            if (functionDefinition != null)
            {
                scope.AddFunction(functionDefinition);
                result = new FunctionReferenceExpression(functionDefinition.Name.Name);
            }
            else
            {
                if (!Value.ReplaceVariables(assignmentScope, out result))
                {
                    return((ParseErrorExpression)result);
                }
            }

            return(scope.AssignVariable(Variable, result));
        }