Example #1
0
        private static void EvalVarSentense(ParseNode node, Enviroment enviroment,
            EnviromentNode envNode)
        {
            envNode.Symbol = node.Nodes[1].Token.Text;
            if (node.Nodes[2].Token.Type == TokenType.FUNCTION)
            {
                EnviromentNode resultNode = EvalDirectFunctionCall(node.Nodes[2], enviroment, envNode.Enviroment);

                // before bind function result to a smbol, eval result node first
                EvalDelayEvalBlock(resultNode);
                if (resultNode.GrammerNode != null)
                {
                    ParseNode result = resultNode.GrammerNode;
                    if (resultNode.ValueType != "lambda")
                    {
                        envNode.Type = GetTypeString(result.Nodes[2], null);
                        envNode.Value = GetValueOfLambda(result.Nodes[2]);
                    }
                    envNode.GrammerNode = result;
                }
                envNode.Enviroment = resultNode.Enviroment;
                envNode.CopyValueFromNode(resultNode);
                return;
            }
            else if (node.Nodes[2].Token.Type == TokenType.IFTHENELSE)
            {
                DelayEvalBlock block = new DelayEvalBlock(node.Nodes[2], enviroment);
                envNode.AddDelayEvalBlock(block);
                EvalDelayEvalBlock(envNode);
            }
            else if (node.Nodes[2].Token.Type == TokenType.LAMBDA)
            {
                envNode.GrammerNode = node;
                envNode.Type = GetTypeString(node.Nodes[2], null);
                envNode.Value = GetValueOfLambda(node.Nodes[2]);
                envNode.ValueType = "lambda";
            }
            else if (node.Nodes[2].Token.Type == TokenType.DIGIT)
            {
                envNode.GrammerNode = null;
                envNode.ValueType = "int";
                envNode.IValue = Int32.Parse(node.Nodes[2].Token.Text);
            }
            else if (node.Nodes[2].Token.Type == TokenType.STRINGVAL)
            {
                envNode.GrammerNode = null;
                envNode.ValueType = "string";
                string tmp = node.Nodes[2].Token.Text;
                envNode.SValue = tmp.Substring(1, tmp.Length - 2);
            }
        }