/// /// <param name="fex"> /// is the For expression. </param> /// <returns> fex expression. </returns> public virtual object visit(ForExpr fex) { for (IEnumerator <VarExprPair> i = fex.iterator(); i.MoveNext();) { i.Current.expr().accept(this); } fex.expr().accept(this); return(null); }
/// <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); }
public override Expression Clone(Scope scope) { var forExpr = new ForExpr(scope); forExpr.Var = Var; forExpr.List = List.Clone(scope); forExpr.ForScope = ForScope.Clone(scope); return(forExpr); }
/// <summary> /// Visits the for statement tree. /// </summary> /// <param name="forExpr"></param> public void For(ForExpr forExpr) { _callBack(forExpr); Visit(forExpr.Start); Visit(forExpr.Condition); Visit(forExpr.Increment); foreach (var stmt in forExpr.Statements) { Visit(stmt); } }
/// <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); }
/// <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); }
/// /// <param name="fex"> /// is the For expression. </param> /// <returns> fex expression. </returns> public virtual object visit(ForExpr fex) { ForExpr last = fex; Expr ret = fex.expr(); int depth = 0; for (IEnumerator i = fex.iterator(); i.MoveNext();) { VarExprPair ve = (VarExprPair)i.Current; // ok we got nested fors... if (depth > 0) { var pairs = new List <VarExprPair>(); pairs.Add(ve); ForExpr fe = new ForExpr(pairs, ret); last.set_expr(fe); last = fe; } depth++; } // normalize return value, and set it to the last for expr ret.accept(this); // get rid of the pairs in the parent (original) for if (depth > 1) { fex.truncate_pairs(); } return(fex); }
private Expr ParseForLoop() { var stmt = new ForExpr(); var statements = new List<Expr>(); // While ( condition expression ) // Parse while condition var start = _parser.ParseStatement(); var condition = _parser.ParseExpression(Terminators.ExpSemicolonEnd); _tokenIt.Advance(); string name = _tokenIt.ExpectId(); var increment = _parser.ParseUnary(name, false); _tokenIt.Expect(Tokens.RightParenthesis); stmt.Init(start, condition, increment); ParseBlock(stmt); return stmt; }
/// <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; }
/// <summary> /// Validate a for expression. /// </summary> /// <param name="fex"> /// is the for expression. </param> /// <returns> null. </returns> public virtual object visit(ForExpr fex) { doForExpr(fex.iterator(), fex.expr()); return(null); }
/// <summary> /// Creates a unary expression with symbol scope, context, script refernce set. /// </summary> /// <param name="name"></param> /// <param name="token"></param> /// <returns></returns> public Expr ToForExpr(Expr start, Expr condition, Expr increment, TokenData token) { var exp = new ForExpr(start, condition, increment); this.SetupContext(exp, token); return exp; }