/// <summary>
 /// Print the message
 /// </summary>
 public override void Execute()
 {
     Value v = new Evaluator(Expressions).Evaluate();
     if (v == null)
         Logger.Error("Cant print a null message.");
     WriteLine(v.ValueToString());
 }
 /// <summary>
 /// Assign the value to the variable
 /// </summary>
 public override void Execute()
 {
     if (!SuperBlock.VariableExists(Name))
         Logger.Error($"No variable exists with this name : {Name}");
     Variable v = SuperBlock.GetVariable(Name);
     Evaluator eval = new Evaluator(Expressions);
     Value value = eval.Evaluate();
     v.SetValue(value, Type);
 }
        /// <summary>
        /// Execute the statement
        /// </summary>
        public override void Execute()
        {
            Value leftValue = new Evaluator(Left).Evaluate();
            Value rightValue = new Evaluator(Right).Evaluate();

            bool success = false;

            switch (OperatorType)
            {
                #region EQUAL

                case TokenType.EQUAL:

                    switch (leftValue.VariableType)
                    {
                        case VariableType.BOOL:
                            if (CanBe.Converted(typeof(bool), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToBool() == rightValue.ValueToBool());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to bool.");
                            break;

                        case VariableType.STRING:
                            if (CanBe.Converted(typeof(string), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToString() == rightValue.ValueToString());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to string.");
                            break;

                        case VariableType.INT:
                            if (CanBe.Converted(typeof(int), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToInt() == rightValue.ValueToInt());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to int.");
                            break;

                        case VariableType.FLOAT:
                            if (CanBe.Converted(typeof(float), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToFloat() == rightValue.ValueToFloat());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to float.");
                            break;

                        case VariableType.CUSTOM:
                            Logger.Info("Condition not available for custom object for now.", true, true, 1);
                            break;

                        default:
                            Logger.Error("Unmanaged error IfBlock #1");
                            break;
                    }
                    break;

                #endregion

                #region GREATER

                case TokenType.GREATER:
                    switch (leftValue.VariableType)
                    {
                        case VariableType.INT:
                            if (CanBe.Converted(typeof(int), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToInt() > rightValue.ValueToInt());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to int.");
                            break;
                        case VariableType.FLOAT:
                            if (CanBe.Converted(typeof(float), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToFloat() > rightValue.ValueToFloat());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to float.");
                            break;
                        case VariableType.CUSTOM:
                            Logger.Info("Condition not available for custom object for now.", true, true, 1);
                            break;
                        default:
                            Logger.Error("Unmanaged error IfBlock #2");
                            break;
                    }

                    break;

                #endregion

                #region GREATER OR EQUAL

                case TokenType.GREATEREQUAL:
                    switch (leftValue.VariableType)
                    {
                        case VariableType.INT:
                            if (CanBe.Converted(typeof(int), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToInt() >= rightValue.ValueToInt());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to int.");
                            break;
                        case VariableType.FLOAT:
                            if (CanBe.Converted(typeof(float), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToFloat() >= rightValue.ValueToFloat());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to float.");
                            break;
                        case VariableType.CUSTOM:
                            Logger.Info("Condition not available for custom object for now.", true, true, 1);
                            break;
                        default:
                            Logger.Error("Unmanaged error IfBlock #3");
                            break;
                    }

                    break;

                #endregion

                #region LESS

                case TokenType.LESS:
                    switch (leftValue.VariableType)
                    {
                        case VariableType.INT:
                            if (CanBe.Converted(typeof(int), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToInt() < rightValue.ValueToInt());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to int.");
                            break;
                        case VariableType.FLOAT:
                            if (CanBe.Converted(typeof(float), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToFloat() < rightValue.ValueToFloat());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to float.");
                            break;
                        case VariableType.CUSTOM:
                            Logger.Info("Condition not available for custom object for now.", true, true, 1);
                            break;
                        default:
                            Logger.Error("Unmanaged error IfBlock #4");
                            break;
                    }

                    break;

                #endregion

                #region LESS OR EQUAL

                case TokenType.LESSEQUAL:
                    switch (leftValue.VariableType)
                    {
                        case VariableType.INT:
                            if (CanBe.Converted(typeof(int), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToInt() <= rightValue.ValueToInt());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to int.");
                            break;
                        case VariableType.FLOAT:
                            if (CanBe.Converted(typeof(float), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToFloat() <= rightValue.ValueToFloat());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to float.");
                            break;
                        case VariableType.CUSTOM:
                            Logger.Info("Condition not available for custom object for now.", true, true, 1);
                            break;
                        default:
                            Logger.Error("Unmanaged error IfBlock #5");
                            break;
                    }

                    break;

                #endregion

                #region DIFFERENT

                case TokenType.DIFFERENT:
                    switch (leftValue.VariableType)
                    {
                        case VariableType.BOOL:
                            if (CanBe.Converted(typeof(bool), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToBool() != rightValue.ValueToBool());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to bool.");
                            break;

                        case VariableType.STRING:
                            if (CanBe.Converted(typeof(string), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToString() != rightValue.ValueToString());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to string.");
                            break;

                        case VariableType.INT:
                            if (CanBe.Converted(typeof(int), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToInt() != rightValue.ValueToInt());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to int.");
                            break;

                        case VariableType.FLOAT:
                            if (CanBe.Converted(typeof(float), rightValue.ObjectValue))
                            {
                                success = (leftValue.ValueToFloat() != rightValue.ValueToFloat());
                                break;
                            }
                            else
                                Logger.Error("Right value cannot be converted to float.");
                            break;
                        case VariableType.CUSTOM:
                            Logger.Info("Condition not available for custom object for now.", true, true, 1);
                            break;
                        default:
                            Logger.Error("Unmanaged error IfBlock #6");
                            break;
                    }
                    break;

                #endregion

                default:
                    Logger.Error("Unmanaged error IfBlock #7");
                    break;
            }

            bool returnMethod = false;
            Method method = null;
            if (GetSuperBlockTypeOf<Method>() != null)
                method = GetSuperBlockTypeOf<Method>() as Method;
            if (method != null && method.ReturnType != VariableType.VOID)
                returnMethod = true;

            if (success)
            {
                foreach (Block b in SubBlocks)
                {
                    if (b is Statement && !(b is ElseIfStatement) && !(b is ElseStatement))
                        b.Execute();
                    if (method != null && returnMethod && method.ReturnValue != null)
                        break;
                }
            }
            else
            {
                bool elseIfSuccess = false;
                if (ElseIfStatements.Count > 0)
                {
                    foreach (var e in ElseIfStatements)
                    {
                        if (elseIfSuccess = e.Execute())
                            break;
                    }
                }
                if (ElseStatementBlock != null && !elseIfSuccess)
                    ElseStatementBlock.Execute();
            }
        }