public object VisitGetExpr(Expr.Get expr) { object objekt = Evaluate(expr.ExprObject); if (objekt is LoxInstance) { return(((LoxInstance)objekt).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)) { Token name = Consume(IDENTIFIER, "Expect property name after '.'."); expr = new Expr.Get(expr, name); } else { break; } } return(expr); }
private Expr Assignment() { Expr expr = Or(); if (Match(EQUAL)) { Token equals = Previous(); Expr value = Assignment(); if (expr is Expr.Variable v) { Token name = v.Name; return(new Expr.Assign(name, value)); } else if (expr is Expr.Get) { Expr.Get get = (Expr.Get)expr; return(new Expr.Set(get.ExprObject, get.Name, value)); } Error(equals, "Invalid assignment target."); } return(expr); }
public string VisitGetExpr(Expr.Get expr) { throw new System.NotImplementedException(); }
public Nothing VisitGetExpr(Expr.Get expr) { Resolve(expr.ExprObject); return(Nothing.AtAll); }