// assignment → identifier "=" assignment | logic_or ; private Expr Assignment() { Expr expr = Or(); if (CheckCurrentToken(TokenType.Equal)) { Token equalsToken = GetCurrentTokenAndAdvance(); Expr value = Assignment(); var nameToken = expr as VariableExpr; if (nameToken != null) { return(new AssignExpr(nameToken.name, value)); } else if (expr is GetExpr) { GetExpr get = (GetExpr)expr; return(new SetExpr(get.obj, get.name, value)); } CreateError(equalsToken, ErrorType.InvalidAssignmentTarget); } return(expr); }
public Object Visit_GetExpr(GetExpr expr) { Object obj = Evaluate(expr.obj); if (obj is LoxInstance) { return(((LoxInstance)obj).Get(expr.name)); } throw new RuntimeException(expr.name.line, expr.name.column, "Only instances have properties."); }
public object VisitGetExpr(GetExpr expr) { var obj = Evaluate(expr.Object) as LoxInstance; if (obj == null) { throw new LoxRuntimeException(expr.Name, "Only instances have properties."); } return(obj.Get(expr.Name)); }
// Call -> Primary ( "(" Arguments? ")" )* private AstNode Call() { AstNode expr = Primary(); while (true) { if (Match(TokenType.LEFT_PAREN)) { expr = FinishCall(expr); } else if (Match(TokenType.DOT)) { var name = Consume(TokenType.IDENTIFIER, "Expect property name after '.'."); expr = new GetExpr(expr, name); } else { break; } } return(expr); }
private Expr Call() { Expr expr = Primary(); while (true) { if (CheckCurrentTokenAndAdvance(TokenType.LeftParen)) { expr = FinishCall(expr); } else if (CheckCurrentTokenAndAdvance(TokenType.Dot)) { Token name = Expect(TokenType.Identifier, ErrorType.ExpectedIdentifier); expr = new GetExpr(expr, name); } else { break; } } return(expr); }
public object VisitGetExpr(GetExpr expr) { Resolve(expr.Object); return(null); }
public Void Visit_GetExpr(GetExpr expr) { Resolve(expr.obj); return(null); }
public string Visit_GetExpr(GetExpr expr) { var name = (string)expr.name.value; return(Parenthesize("Get " + name, expr.obj)); }