예제 #1
0
파일: Program.cs 프로젝트: crazyender/plang
        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;
        }
예제 #2
0
파일: Program.cs 프로젝트: crazyender/plang
 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);
 }