Пример #1
0
        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.");
        }
Пример #2
0
        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);
        }
Пример #3
0
 public object visitGetExpr(Expr.Get expr)
 {
     Resolve(expr.instance);
     return(null);
 }
Пример #4
0
 public string visitGetExpr(Expr.Get expr)
 {
     return(parenthesize("GET"));
 }