Esempio n. 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;
                }
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
        }