/// <summary>
        ///		Ejecuta un bucle while
        /// </summary>
        private async Task ExecuteWhileAsync(SentenceWhile sentence, CancellationToken cancellationToken)
        {
            if (sentence.Condition.Empty)
            {
                AddError("Cant find condition for while loop");
            }
            else
            {
                bool end = false;

                // Ejecuta el bucle
                while (!end && !Stopped)
                {
                    VariableModel result = await ExecuteExpressionAsync(sentence.Condition, cancellationToken);

                    if (result != null)
                    {
                        if (result.Type != VariableModel.VariableType.Boolean || !(result.Value is bool resultLogical))
                        {
                            AddError("While condition result is not a logical value");
                        }
                        else if (resultLogical)
                        {
                            await ExecuteWithContextAsync(sentence.Sentences, cancellationToken);
                        }
                        else
                        {
                            end = true;
                        }
                    }
                }
            }
        }
 /// <summary>
 ///		Transforma una sentencia while
 /// </summary>
 private void TransformWhile(SentenceWhile sentence)
 {
     // Añade el while
     AddSentence(string.Empty);
     AddSentence("while " + TransformExpressions(sentence.Condition) + ":");
     // Añade las sentencias hija
     AddIndent();
     Transform(sentence.Sentences);
     RemoveIndent();
 }
        /// <summary>
        ///		Carga una sentencia While
        /// </summary>
        private SentenceBase LoadSentenceWhile(MLNode rootML, string pathBase)
        {
            SentenceWhile sentence = new SentenceWhile();

            // Carga la condición y las sentencias
            sentence.Condition = rootML.Attributes[TagCondition].Value;
            sentence.Sentences.AddRange(LoadSentences(rootML.Nodes, pathBase));
            // Devuelve la sentencia
            return(sentence);
        }
Example #4
0
        /// <summary>
        ///		Ejecuta un bucle while
        /// </summary>
        private void ExecuteWhile(SentenceWhile sentence)
        {
            if (string.IsNullOrWhiteSpace(sentence.Condition))
            {
                AddError("Cant find condition for while loop");
            }
            else
            {
                bool result = new Compiler.Interpreter().EvaluateCondition(Context, sentence.Condition, out string error);

                if (!string.IsNullOrEmpty(error))
                {
                    AddError(error);
                }
                else if (result)
                {
                    ExecuteWithContext(sentence.Sentences);
                }
            }
        }