private string parseUserDefinedFunction(ASTNode rootNode, string functionId) { FunctionDefinition function = null; foreach (var funcDef in FunctionDefinitions.Where(funcDef => funcDef.getId() == functionId)) { function = funcDef; } if (function?.getNumArguments() != rootNode.getNumChildren()) { return(string.Empty); //error } var tmpDictionary = new Dictionary <string, string>(); for (long i = 0; i < function.getNumArguments(); i++) { var argument = function.getArgument(i).getName(); var replacement = Eval(rootNode.getChild(i)); tmpDictionary.Add(argument, replacement); _functionDefDictionary[argument] = replacement; } foreach (var entry in tmpDictionary) { _functionDefDictionary[entry.Key] = entry.Value; } var res = Eval(function.getBody()); return(res); }
/// <summary> /// Parses a user defined function by looking it up in the pre-imported user defined /// functions. /// </summary> private string parseFunction(ASTNode rootNode) { if (FunctionDefinitions == null) { return(String.Empty); } foreach (var func in FunctionDefinitions.Where(func => rootNode.getName() == func.getId())) { return(parseUserDefinedFunction(rootNode, func.getId())); } return(string.Empty); }