コード例 #1
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
        public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            foreach (Tuple <BogieLangType, string> param in Parameters)
            {
                if (!variableEnvironment.IsVariableDeclared(param.Item2))
                {
                    throw new Exception("Missing parameter: " + param.Item2);
                }
            }

            foreach (Body body in Body)
            {
                object obj = body.Execute(functionEnvironment, variableEnvironment);
                if (obj != null)
                {
                    BogieLangType returningType = BogieLangTypeHelpr.ObjectToType(obj);
                    if (returningType == ReturnBogieLangType)
                    {
                        return(obj);
                    }
                    else
                    {
                        throw new Exception("Function " + Identifier + " returned a " + returningType + ", but should return a " + ReturnBogieLangType);
                    }
                }
            }
            return(null);
        }
コード例 #2
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
        public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            Expression rightExpression = _getRightmostExpression();

            return(rightExpression._execute(functionEnvironment, variableEnvironment));

            /*if (SubExpression == 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 left;
             *  if (Identifier != null) { left = variableEnvironment.GetVariableValue(Identifier); }
             *  else if (Literal != null) { left = Literal.Execute(); }
             *  else if (FunctionCall != null) { left = FunctionCall.Execute(functionEnvironment, variableEnvironment); }
             *  else { throw new Exception("Unknown expression"); }
             *
             *  object right = SubExpression.Execute(functionEnvironment, variableEnvironment);
             *  return Operators.OperatorHelper.Execute(Operator, left, right);
             * }*/
        }
コード例 #3
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
 public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
 {
     if (VarDeclaration != null)
     {
         VarDeclaration.Execute(functionEnvironment, variableEnvironment); return(null);
     }
     else if (VarDefinition != null)
     {
         VarDefinition.Execute(functionEnvironment, variableEnvironment); return(null);
     }
     else if (FunctionCall != null)
     {
         return(FunctionCall.Execute(functionEnvironment, variableEnvironment));
     }
     else if (FunctionReturn != null)
     {
         return(FunctionReturn.Execute(functionEnvironment, variableEnvironment));
     }
     else if (IfControl != null)
     {
         return(IfControl.Execute(functionEnvironment, variableEnvironment));
     }
     else if (WhileControl != null)
     {
         return(WhileControl.Execute(functionEnvironment, variableEnvironment));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #4
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
        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));
        }
コード例 #5
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
        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);
            }
        }
コード例 #6
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
        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));
            }
        }
コード例 #7
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
        public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            object obj = Expression.Execute(functionEnvironment, variableEnvironment);
            VariableEnvironment localVariables = new VariableEnvironment();

            localVariables.ParentEnvironment = variableEnvironment;

            if (obj is bool && (bool)obj == true)
            {
                foreach (Body body in Body)
                {
                    object val = body.Execute(functionEnvironment, localVariables);
                    if (val != null)
                    {
                        return(val);
                    }
                    ;
                }
            }
            return(null);
        }
コード例 #8
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
 public object Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
 {
     return(Expression.Execute(functionEnvironment, variableEnvironment));
 }
コード例 #9
0
ファイル: Nodes.cs プロジェクト: johnboggess/BogieLang
        public void Execute(FunctionEnvironment functionEnvironment, VariableEnvironment variableEnvironment)
        {
            object value = Expression.Execute(functionEnvironment, variableEnvironment);

            variableEnvironment.DefineVariable(Identifier, value);
        }