public UserFunctionNode Copy() { var copy = new UserFunctionNode(Value); copy.SymbolTable = new SymbolTable(SymbolTable); //copy.FormalArguments = FormalArguments.ToList(); copy.FirstStatement = FirstStatement; copy.LastStatement = LastStatement; return(copy); }
public override void AddNode(string value, ParserParts parserPart) { switch (parserPart) { case ParserParts.DefOp: if (GlobalFunctionId == value) { astBuilder.globalFunctionNode = new FunctionNode(value); astBuilder.currentFunctionNode = astBuilder.globalFunctionNode; } else { var userFuncNode = new UserFunctionNode(value); astBuilder.globalFunctionNode.UserFunctions.Add(userFuncNode); astBuilder.currentFunctionNode = userFuncNode; } break; case ParserParts.DefAlias: if (!value.StartsWith(":")) { throw new ArgumentException("Alias does not start with :"); } ((UserFunctionNode)astBuilder.currentFunctionNode).Alias = value.Substring(1, value.Length - 1); break; case ParserParts.SetRelFormalArg: //((UserFunctionNode)astBuilder.currentFunctionNode).AddArguement(); = value; break; case ParserParts.SetRelArg: primeVariable = value; break; case ParserParts.RelAttStr: var strInt = new StrInt(value, null); secondaryVariable.Add(strInt); break; case ParserParts.RelAttIndex: var strInt2 = new StrInt(null, int.Parse(value) - 1); secondaryVariable.Add(strInt2); break; case ParserParts.SetRelFormalArgEnd: if (secondaryVariable.Count == 0) { ((UserFunctionNode)astBuilder.currentFunctionNode).AddArguement(new SetNode(primeVariable)); } else { var relation = new RelationNode(primeVariable); //todo numeric index bzw empty args relation.Attributes = secondaryVariable.Select(t => t.Item1).ToList(); ((UserFunctionNode)astBuilder.currentFunctionNode).AddArguement(relation); } primeVariable = null; secondaryVariable.Clear(); break; default: throw new InvalidOperationException(); } }