示例#1
0
        public object VisitGetExpr(Expr.Get expr)
        {
            var @object = Evaluate(expr.Object);

            if (@object is LoxInstance loxInstance)
            {
                return(loxInstance.Get(expr.Name));
            }

            throw new RuntimeError(expr.Name, "Only instances have properties.");
        }
示例#2
0
        private Expr Call()
        {
            var expr = Primary();

            while (true)
            {
                if (Match(LEFT_PAREN))
                {
                    expr = FinishCall(expr);
                }
                else if (Match(DOT))
                {
                    var name = Consume(IDENTIFIER, "Expected property name after '.'.");
                    expr = new Expr.Get(expr, name);
                }
                else
                {
                    break;
                }
            }

            return(expr);
        }
示例#3
0
 public string VisitGetExpr(Expr.Get expr)
 {
     return(Parenthesize2(".", expr.Object, expr.Name.Lexeme));
 }
示例#4
0
 public object VisitGetExpr(Expr.Get expr)
 {
     Resolve(expr.Object);
     return(null);
 }