Пример #1
0
        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.");
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 public string VisitGetExpr(Expr.Get expr)
 {
     throw new System.NotImplementedException();
 }
Пример #5
0
 public Nothing VisitGetExpr(Expr.Get expr)
 {
     Resolve(expr.ExprObject);
     return(Nothing.AtAll);
 }