Beispiel #1
0
        public static TrashObject RepeatStmt(this Interpreter interpreter, Stmt.Repeat stmt)
        {
            // we've got ourselves a low-high expression bois
            if (stmt.LowValue != null)
            {
                var low  = interpreter.Evaluate(stmt.LowValue).Access();
                var high = interpreter.Evaluate(stmt.HighValue).Access();
                if (low is int && high is int)
                {
                    for (int i = (int)low; i <= (int)high; ++i)
                    {
                        interpreter.Execute(stmt.Block);
                    }

                    return(null);
                }

                throw new Interpreter.RuntimeError("Invalid values for repeat loop");
            }

            // otherwise this guy's got a condition
            var cond = interpreter.Evaluate(stmt.Condition).Access();

            if (cond is bool)
            {
                while ((bool)interpreter.Evaluate(stmt.Condition).Access())
                {
                    interpreter.Execute(stmt.Block);
                }
            }

            return(null);
        }
Beispiel #2
0
    public string VisitRepeatStmt(Stmt.Repeat stmt)
    {
        // we've got ourselves a low-high expression bois
        if (stmt.LowValue != null)
        {
            var low  = evaluate(stmt.LowValue);
            var high = evaluate(stmt.HighValue);
            if (low is int && high is int)
            {
                for (int i = (int)low; i <= (int)high; ++i)
                {
                    execute(stmt.Block);
                }

                return("");
            }

            throw new RuntimeError("Invalid values for repeat loop");
        }
        else // this guy's got a condition
        {
            var cond = evaluate(stmt.Condition);
            if (cond is bool)
            {
                while ((bool)evaluate(stmt.Condition))
                {
                    execute(stmt.Block);
                }
            }
        }

        return("");
    }
Beispiel #3
0
 public TrashObject VisitRepeatStmt(Stmt.Repeat stmt)
 {
     return(this.RepeatStmt(stmt));
 }