protected override Variable Evaluate(ParsingScript script) { bool isList; List <Variable> functionArgs = Utils.GetArgs(script, Constants.START_ARG, Constants.END_ARG, out isList); //script.MoveForwardIf(Constants.END_ARG); script.MoveBackIf(Constants.START_GROUP); if (functionArgs.Count != m_args.Length) { throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " + m_args.Length + " declared, " + functionArgs.Count + " supplied"); } // 1. Add passed arguments as local variables to the Parser. StackLevel stackLevel = new StackLevel(m_name); for (int i = 0; i < m_args.Length; i++) { stackLevel.Variables[m_args[i]] = new GetVarFunction(functionArgs[i]); } ParserFunction.AddLocalVariables(stackLevel); // 2. Execute the body of the function. Variable result = null; ParsingScript tempScript = new ParsingScript(m_body); tempScript.ScriptOffset = m_parentOffset; if (m_parentScript != null) { tempScript.Char2Line = m_parentScript.Char2Line; tempScript.Filename = m_parentScript.Filename; tempScript.OriginalScript = m_parentScript.OriginalScript; } while (tempScript.Pointer < m_body.Length - 1 && (result == null || !result.IsReturn)) { result = tempScript.ExecuteTo(); tempScript.GoToNextStatement(); } ParserFunction.PopLocalVariables(); //script.MoveForwardIf(Constants.END_ARG); //script.MoveForwardIf(Constants.END_STATEMENT); if (result == null) { result = Variable.EmptyInstance; } else { result.IsReturn = false; } return(result); }
public void RegisterArguments(List <Variable> args) { StackLevel stackLevel = new StackLevel(m_name); for (int i = 0; i < m_args.Length; i++) { stackLevel.Variables[m_args [i]] = new GetVarFunction(args [i]); } ParserFunction.AddLocalVariables(stackLevel); }
protected override Variable Evaluate(string data, ref int from) { bool isList; List <Variable> functionArgs = Utils.GetArgs(data, ref from, Constants.START_ARG, Constants.END_ARG, out isList); Utils.MoveBackIf(data, ref from, Constants.START_GROUP); if (functionArgs.Count != _args.Length) { throw new ArgumentException("Функция [" + _name + "] аргументи несъответствие: " + _args.Length + " обявен, " + functionArgs.Count + " доставен"); } // 1. Добавете предаваните аргументи като локални променливи към анализатора. StackLevel stackLevel = new StackLevel(_name); for (int i = 0; i < _args.Length; i++) { stackLevel.Variables[_args[i]] = new GetVarFunction(functionArgs[i]); } ParserFunction.AddLocalVariables(stackLevel); // 2. Изпълнете тялото на функцията. int temp = 0; Variable result = null; while (temp < _body.Length - 1) { result = Parser.LoadAndCalculate(_body, ref temp, Constants.END_PARSE_ARRAY); Utils.GoToNextStatement(_body, ref temp); } ParserFunction.PopLocalVariables(); return(result); }