public object visitGetExpr(Expr.Get expr) { object instance = Evaluate(expr.instance); if (instance is LoxInstance loxInstance) { return(loxInstance.Get(expr.name)); } if (instance is LoxClass loxClass) { return(loxClass.FindStaticMethod(expr.name.lexeme)); } throw new RuntimeError(expr.name, "Only instances have properties."); }
Expr ParseCall() { Expr expr = ParsePrimary(); 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 object visitGetExpr(Expr.Get expr) { Resolve(expr.instance); return(null); }
public string visitGetExpr(Expr.Get expr) { return(parenthesize("GET")); }