/// <summary> /// Evaluates a function and returns its value. It is assumed the current /// position is at the opening parenthesis of the argument list. /// </summary> /// <param name="parser">TextParser object</param> /// <param name="name">Name of function</param> /// <param name="pos">Position at start of function</param> /// <returns></returns> protected double EvaluateFunction(TextParser parser, string name, int pos) { double result = default(double); // Parse function parameters List <double> parameters = ParseParameters(parser); // We found a function reference FunctionStatus status = FunctionStatus.UndefinedFunction; if (ProcessFunction != null) { FunctionEventArgs args = new FunctionEventArgs(); args.Name = name; args.Parameters = parameters; args.Result = result; args.Status = FunctionStatus.OK; ProcessFunction(this, args); result = args.Result; status = args.Status; } if (status == FunctionStatus.UndefinedFunction) { throw new EvalException(String.Format(ErrUndefinedFunction, name), pos); } if (status == FunctionStatus.WrongParameterCount) { throw new EvalException(ErrWrongParamCount, pos); } return(result); }
/// <summary> /// Evaluates a function and returns its value. It is assumed the current /// position is at the opening parenthesis of the argument list. /// </summary> /// <param name="parser">TextParser object</param> /// <param name="name">Name of function</param> /// <param name="pos">Position at start of function</param> /// <returns></returns> protected double EvaluateFunction(TextParser parser, string name, int pos) { double result = default(double); // Parse function parameters List<double> parameters = ParseParameters(parser); // We found a function reference FunctionStatus status = FunctionStatus.UndefinedFunction; if (ProcessFunction != null) { FunctionEventArgs args = new FunctionEventArgs(); args.Name = name; args.Parameters = parameters; args.Result = result; args.Status = FunctionStatus.OK; ProcessFunction(this, args); result = args.Result; status = args.Status; } if (status == FunctionStatus.UndefinedFunction) throw new EvalException(String.Format(ErrUndefinedFunction, name), pos); if (status == FunctionStatus.WrongParameterCount) throw new EvalException(ErrWrongParamCount, pos); return result; }