예제 #1
0
        public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            if (!functionEnvironment.IsFunctionDefined(Identifier))
            {
                throw new Exception("Calling undefined function: " + Identifier);
            }
            VariableEnvironment localVariables = new VariableEnvironment();

            localVariables.ParentEnvironment = variableEnvironment;//todo: switch

            FunctionDefinition functionDefinition = functionEnvironment.GetDefinedFunction(Identifier);

            for (int i = 0; i < Arguments.Count; i++)
            {
                object        obj           = Arguments[i].Execute(functionEnvironment, variableEnvironment);
                BogieLangType bogieLangType = BogieLangTypeHelpr.ObjectToType(obj);
                if (functionDefinition.Parameters[i].Item1 == bogieLangType)
                {
                    localVariables.DeclareVariable(functionDefinition.Parameters[i].Item2, functionDefinition.Parameters[i].Item1);
                    localVariables.DefineVariable(functionDefinition.Parameters[i].Item2, obj);
                }
            }

            return(functionDefinition.Execute(functionEnvironment, localVariables));
        }
예제 #2
0
        public void Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            object value = null;

            if (Expression != null)
            {
                value = Expression.Execute(functionEnvironment, variableEnvironment);
            }
            variableEnvironment.DeclareVariable(Identifier, (BogieLangType)BogieLangType);
            if (value != null)
            {
                variableEnvironment.DefineVariable(Identifier, value);
            }
        }
예제 #3
0
 public void DefineVariable(string identifier, object obj)
 {
     if (IsVariableDeclared(identifier))
     {
         if (DeclaredVariables[identifier].BogieLangType == BogieLangTypeHelpr.ObjectToType(obj))
         {
             DeclaredVariables[identifier].Value = obj;
         }
         else
         {
             throw new Exception(identifier + " is of type " + DeclaredVariables[identifier].BogieLangType + ", got a " + BogieLangTypeHelpr.ObjectToType(obj));
         }
     }
     else if (ParentEnvironment != null)
     {
         ParentEnvironment.DefineVariable(identifier, obj);
     }
     else
     {
         throw new Exception("Undeclaration variable: " + identifier);
     }
 }
예제 #4
0
        public void Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            object value = Expression.Execute(functionEnvironment, variableEnvironment);

            variableEnvironment.DefineVariable(Identifier, value);
        }