public object visitAssignExpr(Expr.Assign expr) { object value = Evaluate(expr.value); int distance = -1; if (locals.ContainsKey(expr)) { distance = locals[expr]; } if (distance != -1) { environment.AssignAt(distance, expr.name, value); } else { environment.Assign(expr.name, value); } environment.Assign(expr.name, value); return(value); }
public void Assign(Token name, object value) { if (values.ContainsKey(name.lexeme)) { values[name.lexeme] = value; return; } if (enclosing != null) { enclosing.Assign(name, value); return; } throw new RuntimeError(name, "Undefined variable '" + name.lexeme + "',"); }