Beispiel #1
0
        public InstructionString(Node _nodeIntStatement, Subprogram _parentSubprogram)
        {
            this.ParentSubprogram = _parentSubprogram;

            for (int i = 0; i < _nodeIntStatement.GetChildCount(); i++)
            {
                switch (_nodeIntStatement.GetChildAt(i).GetId())
                {
                case (int)KropConstants.WORD:
                    Token token = (Token)_nodeIntStatement.GetChildAt(i);
                    VarName = token.GetImage();
                    break;

                case (int)KropConstants.STRING_VAR_VALUE:

                    switch (_nodeIntStatement.GetChildAt(i).GetChildAt(0).GetId())
                    {
                    case (int)KropConstants.STRING_EXPRESSION:
                        VarValue = AlgorithmicExpression.CalculStringExpression(_nodeIntStatement.GetChildAt(i).GetChildAt(0), _parentSubprogram);
                        break;

                    case (int)KropConstants.INPUT:
                        inputValue = true;
                        break;
                    }
                    break;
                }
            }
        }
Beispiel #2
0
        public override bool Evaluate()
        {
            int?   valueOne = AlgorithmicExpression.CalculExpression(ExpressionOne, ParentSubprogram);
            int?   valueTwo = AlgorithmicExpression.CalculExpression(ExpressionTwo, ParentSubprogram);
            bool   result   = false;
            string errorMsg;

            if (CanEvaluate())
            {
                if (valueOne != null && valueTwo != null)
                {
                    if (IsEgal)
                    {
                        result = valueOne == valueTwo;
                    }
                    else if (IsBigger)
                    {
                        result = valueOne > valueTwo;
                    }
                    else if (IsSmaller)
                    {
                        result = valueOne < valueTwo;
                    }

                    if (IsNot)
                    {
                        return(!result);
                    }
                    else
                    {
                        return(result);
                    }
                }
                else
                {
                    if (IsEgal)
                    {
                        errorMsg = valueOne + " = " + valueTwo;
                    }
                    else if (IsBigger)
                    {
                        errorMsg = valueOne + " > " + valueTwo;
                    }
                    else
                    {
                        errorMsg = valueOne + " < " + valueTwo;
                    }

                    FormControlWindow.TerminalWriteLine("La condition ( " + errorMsg + " ) est impossible.");
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        public override bool Execute()
        {
            if (CanExecute())
            {
                if ((Var = ParentSubprogram.GetVar(varToken.GetImage(), ParentSubprogram)) == null)
                {
                    Error    = true;
                    ErrorMsg = "Variable " + varToken.GetImage() + " n'existe pas.";
                }

                if (!Error)
                {
                    if (Var is IntVar intVar)
                    {
                        if (inputValue)
                        {
                            intVar.SetValue(Subprogram.PromptInputValue <int>());
                        }
                        else
                        {
                            intVar.SetValue(AlgorithmicExpression.CalculExpression(SetVarValue.GetChildAt(0), ParentSubprogram));
                        }
                    }
                    else if (Var is StringVar stringVar)
                    {
                        if (inputValue)
                        {
                            stringVar.SetValue(Subprogram.PromptInputValue <string>());
                        }
                        else
                        {
                            stringVar.SetValue(AlgorithmicExpression.CalculStringExpression(SetVarValue.GetChildAt(0), ParentSubprogram));
                        }
                    }
                    return(true);
                }
                else
                {
                    FormControlWindow.TerminalWriteLine("VarError : " + ErrorMsg);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        public override bool Execute()
        {
            if (CanExecute())
            {
                if (inputValue)
                {
                    Value = Subprogram.PromptInputValue <string>();
                }
                else
                {
                    Value = AlgorithmicExpression.CalculStringExpression(stringExpression, ParentSubprogram);
                }

                if (Value != null && IsStringValue == true)
                {
                    FormControlWindow.TerminalWriteLine("Fourmi dit : " + Value);
                    return(true);
                }
                else
                {
                    if (VarName != null && IsStringValue == false)
                    {
                        if ((Value = Subprogram.VarToString(VarName, ParentSubprogram)) == null)
                        {
                            ErrorMsg = "Variable " + VarName + " n'existe pas.";
                        }
                        else
                        {
                            FormControlWindow.TerminalWriteLine("Fourmi dit : " + Value);
                            return(true);
                        }
                    }
                }
            }

            FormControlWindow.TerminalWriteLine("DireError : " + ErrorMsg);
            return(false);
        }