public object VisitGetExpr(Expr.Get expr) { var obj = Evaluate(expr.Obj); if (obj is LoxInstance li) { return(li.Get(expr.Name)); } throw new RuntimeError(expr.Name, "Only instances have properties"); }
object Expr.IVisitor <object> .Visit(Expr.Get _get) { object target = Evaluate(_get.target); if (target is LoxInstance) { return(((LoxInstance)target).Get(_get.name)); } throw new RuntimeError(_get.name, "Only instances have properties."); }
public object VisitGetExpr(Expr.Get expr) { if (Evaluate(expr.obj) is LoxInstance instance) { var value = instance[expr.name]; if (value is LoxFunction function && function.IsGetter) { value = function.Call(this, null); } return(value); } throw new RuntimeError(expr.name, "Only instances have properties"); }
public object visitGetExpr(Expr.Get get) { Object _object = evaluate(get._object); if (_object is LoxInstance && !(_object is LoxClass)) { object result = ((LoxInstance)_object).get(get.name); if (result is LoxFunction) { if (((LoxFunction)result).isGetter()) { result = ((LoxFunction)result).call(this, null); } } return(result); } throw new Exceptions.RuntimeError(get.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); }
private Expr assignment() { Expr expr = ternaryExpression(); if (match(TokenType.EQUALS)) { Token equals = previous(); Expr value = assignment(); if (expr is Expr.Variable) { Token name = ((Expr.Variable)expr).name; return(new Expr.AssignExpr(name, value)); } else if (expr is Expr.Get) { Expr.Get get = (Expr.Get)expr; return(new Expr.Set(get._object, get.name, value, get.isCascading)); } throw error(equals, "Invalid assignment target: " + expr.GetType()); } return(expr); }
private Expr Call() { Expr expr = Primary(); while (true) { if (Match(LEFT_PAREN)) { // Trying to call previous expr as a function. 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 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, false); } else if (match(TokenType.QUESTION_DOT)) { Token nil = new Token(TokenType.NIL, "nil", null, -1, -1); Expr callIfNotNull = new Expr.Get(expr, consume(TokenType.IDENTIFIER, "Expect property after '?."), false); if (match(TokenType.LEFT_PAREN)) { callIfNotNull = finishCall(callIfNotNull); } expr = new Expr.TernaryExpr( new Expr.BinaryExpr(expr, new Token(TokenType.EQUALS_EQUALS, "==", null, -1, -1), new Expr.Literal(null, nil)), // ? new Expr.Literal(null, nil), // : callIfNotNull); // new Expr.Get(expr, consume(TokenType.IDENTIFIER, "Expect property after '?."), false)); ((Expr.TernaryExpr)expr).isNullAccessor = true; } else { break; } } return(expr); }
string Expr.IVisitor <string> .Visit(Expr.Get _get) { throw new NotImplementedException(); }
public object visitGetExpr(Expr.Get get) { resolve(get._object); return(null); }
public object VisitGetExpr(Expr.Get expr) { Resolve(expr.obj); return(null); }
public string visitGetExpr(Expr.Get get) { return("(" + get._object.accept(this) + "." + get.name.lexeme + ")"); }
public Void VisitGetExpr(Expr.Get expr) { Resolve(expr.Obj); return(null); }
public string VisitGetExpr(Expr.Get expr) { return($"(value of {expr.Accept(this)})"); }
public object Visit(Expr.Get _get) { Resolve(_get.target); return(null); }