private static EnviromentNode EvalSentense(ParseNode node, Enviroment enviroment) { EnviromentNode envNode = new EnviromentNode(enviroment); if (node.Token.Type == TokenType.LET) { EvalVariableSentense(node, enviroment, envNode); if (!string.IsNullOrEmpty(envNode.Symbol)) enviroment.AddEnviromentNode(envNode); } else if (node.Token.Type == TokenType.SET) { EvalVariableSentense(node, enviroment, envNode); if (!string.IsNullOrEmpty(envNode.Symbol)) enviroment.UpdateEnviromentNode(envNode); } else if (node.Token.Type == TokenType.FUNCDEF) { EvalFunctionDefineSentense(node, enviroment, envNode); if (!string.IsNullOrEmpty(envNode.Symbol)) enviroment.AddEnviromentNode(envNode); } else if (node.Token.Type == TokenType.FUNCTION) { // if a direct call occures in eval sentense, it must be an IO, or return envNode = EvalDirectFunctionCall(node, enviroment, envNode.Enviroment); if (!string.IsNullOrEmpty(envNode.Symbol)) enviroment.AddEnviromentNode(envNode); } return envNode; }
private static void BindParameter(EnviromentNode[] parameters, Enviroment newEnviro, int index, string symbol) { EnviromentNode applyTo = parameters.Length < index ? null : parameters[index]; EnviromentNode newNode = null; if (applyTo == null) { newNode = new EnviromentNode(newEnviro); newNode.Symbol = symbol; } else { EnviromentNode applyEnvNode = applyTo; newNode = new EnviromentNode(newEnviro, applyEnvNode); newNode.Symbol = symbol; } newEnviro.AddEnviromentNode(newNode); }