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.obj, get.name, value)); } Error(equals, "Invalid assignment target."); } return(expr); }
public object VisitGetExpr(Expr.Get expr) { var obj = Evaluate(expr.obj); if (obj is LoxInstance) { return(((LoxInstance)obj).Get(expr.name)); } throw new RuntimeError(expr.name, "Only instances have properties."); }
private Expr Call() { Expr expr = Primary(); while (true) { if (Match(LEFT_PAREN)) { expr = FinishCall(expr); } else if (Match(DOT)) { var name = Consume(IDENTIFIER, "Expect property name after '.'."); expr = new Expr.Get(expr, name); } else { break; } } return(expr); }
public object VisitGetExpr(Expr.Get expr) { Resolve(expr.obj); return(null); }
public string VisitGetExpr(Expr.Get expr) { throw new NotImplementedException(); }
public Void Visit(Expr.Get expr) { Resolve(expr.Obj); return(Void.Instance); }
object Expr.IVisitor <object> .VisitGetExpr(Expr.Get expr) { Resolve(expr.obj); return(null); }