コード例 #1
0
ファイル: Execution.cs プロジェクト: GHLabs/SambaPOS-3
        /// <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;
        }
コード例 #2
0
ファイル: Exprs.cs プロジェクト: GHLabs/SambaPOS-3
 /// <summary>
 /// Creates a unary expression with symbol scope, context, script refernce set.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Expr For(Expr start, Expr condition, Expr increment, TokenData token)
 {
     var exp = new ForExpr();
     exp.Start = start;
     exp.Condition = condition;
     exp.Increment = increment;
     SetupContext(exp, token);
     return exp;
 }
コード例 #3
0
ファイル: Visitor.cs プロジェクト: GHLabs/SambaPOS-3
 /// <summary>
 /// Visits the for statement tree.
 /// </summary>
 /// <param name="forExpr"></param>
 public object VisitFor(ForExpr expr)
 {
     _callBackOnNodeStart(expr);
     expr.Start.Visit(this);
     expr.Condition.Visit(this);
     expr.Increment.Visit(this);
     foreach (var stmt in expr.Statements)
     {
         stmt.Visit(this);
     }
     return null;
 }