private Expr Assignment() { Expr expr = Or(); if (Match(TokenType.Equal)) { Token equals = Previous(); Expr value = Assignment(); if (expr is Expr.Variable) { Token name = ((Expr.Variable)expr).name; expr = new Expr.Assign(name, value); } else if (expr is Expr.Get) { Expr.Get get = (Expr.Get)expr; expr = new Expr.Set(get.obj, get.name, value); } else { Error(equals, "Invalid assignment target."); } } return(expr); }
public object Visit(Expr.Assign expr) { Resolve(expr.value); ResolveLocal(expr, expr.name); return(null); }
// Expr Visitors public object Visit(Expr.Assign expr) { object value = Evaluate(expr.value); if (locals.ContainsKey(expr)) { int distance = locals[expr]; environment.AssignAt(distance, expr.name, value); } else { globals.Assign(expr.name, value); } return(value); }
// Expr Visitors public string Visit(Expr.Assign assign) { //return Parentherize2("=", assign.name.lexeme, assign.value); return(""); }