public object visitGetExpr(Expr.Get expr)
        {
            object obj = Evaluate(expr.obj);

            if (obj is Instance)
            {
                return(((Instance)obj).Get(expr.name));
            }

            throw new RuntimeError(expr.name, "Only instances have properties.");
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public Void visitGetExpr(Expr.Get expr)
        {
            Resolve(expr.obj);

            return(null);
        }