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; return(new Expr.Assign(name, value)); } else if (expr is Expr.Get) { Expr.Get get = (Expr.Get)expr; return(new Expr.Set(get.object_, get.name, value)); } error(equals, "Invalid assignment target."); } return(expr); }
public object visitGetExpr(Expr.Get expr) { object object_ = evaluate(expr.object_); if (object_ is LoxInstance) { return(((LoxInstance)object_).get(expr.name)); } throw new RuntimeError(expr.name, "Only instances have properties."); }
private Expr call() { Expr expr = primary(); while (true) { if (match(TokenType.LEFT_PAREN)) { expr = finishCall(expr); } else if (match(TokenType.DOT)) { Token name = consume(TokenType.IDENTIFIER, "Expect property name after '.'."); expr = new Expr.Get(expr, name); } else { break; } } return(expr); }
public string visitGetExpr(Expr.Get expr) { return(""); }
public object visitGetExpr(Expr.Get expr) { resolve(expr.object_); return(null); }