Пример #1
0
        private object _execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            if (ParentExpression == null)
            {
                if (Identifier != null)
                {
                    return(variableEnvironment.GetVariableValue(Identifier));
                }
                else if (Literal != null)
                {
                    return(Literal.Execute());
                }
                else if (FunctionCall != null)
                {
                    return(FunctionCall.Execute(functionEnvironment, variableEnvironment));
                }
                else
                {
                    throw new Exception("Unknown expression");
                }
            }
            else
            {
                object right;
                if (Identifier != null)
                {
                    right = variableEnvironment.GetVariableValue(Identifier);
                }
                else if (Literal != null)
                {
                    right = Literal.Execute();
                }
                else if (FunctionCall != null)
                {
                    right = FunctionCall.Execute(functionEnvironment, variableEnvironment);
                }
                else
                {
                    throw new Exception("Unknown expression");
                }

                object left = ParentExpression._execute(functionEnvironment, variableEnvironment);
                return(Operators.OperatorHelper.Execute(ParentExpression.Operator, left, right));
            }
        }
Пример #2
0
 public object GetVariableValue(string identifier)
 {
     if (IsVariableDeclared(identifier))
     {
         return(DeclaredVariables[identifier].Value);
     }
     else if (ParentEnvironment != null)
     {
         return(ParentEnvironment.GetVariableValue(identifier));
     }
     throw new Exception("Undeclared identifer: " + identifier);
 }