public FunctionCall createClone(FunctionCall parent = null) { FunctionCall result = new FunctionCall(); result.Identifier = Identifier; result.Parent = parent; result.Arguments = new List<FunctionCall>(); foreach (FunctionCall fc in Arguments) { result.Arguments.Add(fc.createClone(result)); } return result; }
public void AddArgument(FunctionCall call) { Arguments.Add(call); call.Parent = this; }
/// <summary> /// input is something like this: f(g(h(a,b,c),d,g),n,o(x,y),p) /// and result will be: f-> g-> /// n h-> a /// o d b /// p g c /// </summary> /// <param name="txt"></param> /// <returns></returns> public static List<FunctionCall> ExtractNestedFunctionCalls(string txt) { List<FunctionCall> result = new List<FunctionCall>(); FunctionCall currentCall = new FunctionCall(); string currentIdentifier = ""; for (int i = 0; i < txt.Length; i++) { string chr = txt[i].ToString(); if (chr == "(") { currentCall.Identifier = currentIdentifier; string exp = extractBracketExpression(txt, ref i); foreach (FunctionCall fc in ExtractNestedFunctionCalls(exp)) { currentCall.AddArgument(fc); } result.Add(currentCall); currentIdentifier = ""; currentCall = new FunctionCall(); //bypass closing bracket i++; } else if (chr == ",") { if (currentIdentifier != "") { currentCall.Identifier = currentIdentifier; result.Add(currentCall); currentIdentifier = ""; currentCall = new FunctionCall(); } } else { currentIdentifier += chr; } } if (currentIdentifier != "") { currentCall.Identifier = currentIdentifier; result.Add(currentCall); } return result; }