/// <summary> /// Execute each expression. /// </summary> /// <returns></returns> public object VisitFor(ForExpr expr) { expr.Start.Evaluate(this); expr.DoContinueRunning = true; expr.DoBreakLoop = false; expr.DoContinueLoop = false; var result = expr.Condition.Evaluate(this) as LObject; expr.DoContinueRunning = EvalHelper.IsTrue(result); while (expr.DoContinueRunning) { if (expr.Statements != null && expr.Statements.Count > 0) { foreach (var stmt in expr.Statements) { stmt.Evaluate(this); this.Ctx.Limits.CheckLoop(expr); // If Break statment executed. if (expr.DoBreakLoop) { expr.DoContinueRunning = false; break; } // Continue statement. else if (expr.DoContinueLoop) { break; } } } else { break; } // Break loop here. if (expr.DoContinueRunning == false) { break; } expr.Increment.Evaluate(this); result = expr.Condition.Evaluate(this) as LObject; expr.DoContinueRunning = EvalHelper.IsTrue(result); } return(LObjects.Null); }
/// <summary> /// Execute /// </summary> public object VisitIf(IfExpr expr) { // Case 1: If is true var result = expr.Condition.Evaluate(this) as LObject; bool execIf = EvalHelper.IsTrue(result); object returnVal = LObjects.Null; if (execIf) { if (expr.Statements != null && expr.Statements.Count > 0) { foreach (var stmt in expr.Statements) { returnVal = stmt.Evaluate(this); } } } // Case 2: Else available to execute else if (expr.Else != null) { returnVal = expr.Else.Evaluate(this); } return(returnVal); }