Beispiel #1
0
        /// <summary>
        ///		Ejecuta una instrucción while
        /// </summary>
        private void Execute(InstructionWhile instruction)
        {
            bool end       = false;
            int  loopIndex = 0;

            // Ejecuta las instrucciones en un bucle
            do
            {
                ValueBase result = ExpressionComputer.Evaluate(instruction.ConditionRPN);

                if (result.HasError)
                {
                    Compiler.LocalErrors.Add(instruction.Token, result.Error);
                    end = true;
                }
                else if (!(result is ValueBool))
                {
                    Compiler.LocalErrors.Add(instruction.Token, "El resultado de calcular la expresión no es un valor lógico");
                    end = true;
                }
                else if (!(result as ValueBool).Value)
                {
                    end = true;
                }
                else
                {
                    Execute(instruction.Instructions);
                }
            }while (!end && ++loopIndex < Compiler.MaximumRepetitionsLoop);
        }
Beispiel #2
0
        /// <summary>
        ///		Lee una sentencia while
        /// </summary>
        private InstructionWhile ReadCommandWhile(Token token)
        {
            InstructionWhile instruction = new InstructionWhile(token);

            // Lee la expresión
            instruction.Condition    = ReadExpression(ExpressionReaderMode.Normal, out string error);
            instruction.ConditionRPN = _expressionEvaluator.ConvertToRPN(instruction.Condition);
            if (!string.IsNullOrWhiteSpace(error))
            {
                instruction.Error = error;
            }
            // Lee las instrucciones del bucle
            if (!instruction.IsError)
            {
                ReadInstructions(instruction.Instructions);
            }
            // Devuelve la instrucción
            return(instruction);
        }