public ForStmt(DefStmt counter_definition, Expression condition, Expression counter_action, Statement body) { this.counter_definition = counter_definition; this.condition = condition; this.counter_action = counter_action; this.body = body; }
private Statement forloop() { consume(Token.Type.For); consume(Token.Type.LeftParenthesis, "Expected '(' for opening for loop specification"); bool iterator = false; DefStmt counter_definition = define(); Expression iterator_object = null, condition = null, counter_action = null; // Check if we have an iterator if (consume(Token.Type.In) != null) { iterator = true; iterator_object = expression(); } else { iterator = false; consume(Token.Type.IdentifierSeperator, "Expected ',' at expression end"); condition = expression(); consume(Token.Type.IdentifierSeperator, "Expected ',' at expression end"); counter_action = expression(); } consume(Token.Type.RightParenthesis, "Expected ')' for closing for loop specification"); // Create the body, along with the counter action Statement body = statement(); if (iterator) { return(new ForIterStmt(counter_definition, iterator_object, body)); } return(new ForStmt(counter_definition, condition, counter_action, body)); }
private ForStmt forloop() { consume(Token.Type.For); consume(Token.Type.LeftParenthesis, "Expected '(' for opening for loop specification"); DefStmt counter_definition = define(); consume(Token.Type.IdentifierSeperator, "Expected ',' at expression end"); Expression condition = expression(); consume(Token.Type.IdentifierSeperator, "Expected ',' at expression end"); Expression counter_action = expression(); consume(Token.Type.RightParenthesis, "Expected ')' for closing for loop specification"); // Create the body, along with the counter action Statement body = new BlockStmt( new List <Statement>() { statement(), new ExprStmt(counter_action) }); // Create a while statement WhileStmt while_stmt = new WhileStmt(condition, body); return(new ForStmt(counter_definition, while_stmt)); }
public void visit_define(DefStmt define_stmt) { declare(define_stmt.name); if (define_stmt.value != null) { resolve(define_stmt.value); } define(define_stmt.name); }
public void visit_define(DefStmt define_stmt) { object value = null; if (define_stmt.value != null) { value = evaluate(define_stmt.value); } local_scope.define((string)define_stmt.name.value, value); }
public ForIterStmt(DefStmt counter_definition, Expression iterator_object, Statement body) { this.counter_definition = counter_definition; this.iterator_object = iterator_object; this.body = body; }
public void Visit(DefStmt t, IEnvironment env) { env.PutNew(t.Name, new Function(t.Parameters, t.Body, env)); result = t.Name; return; }
private void Resolve(DefStmt definition) { Define(definition.Name); Resolve(definition.Value); }
public ForStmt(DefStmt counter_definition, WhileStmt body) { this.counter_definition = counter_definition; this.body = body; }
private void Execute(DefStmt definition) { _environment.Define(definition.Name, Evaluate(definition.Value)); }