예제 #1
0
        public object visitVariableExpr(Expr.Variable expr)
        {
            bool initialized;

            if (scopes.Count > 0 && scopes.Peek().TryGetValue(expr.Name.Lexeme, out initialized) && initialized == false)
            {
                Lox.error(expr.Name, "Cannot read local variable in it's own initializer");
            }
            resolveLocal(expr, expr.Name);
            return(null);
        }
예제 #2
0
        private Stmt classDelaration()
        {
            Token name = consume(TokenType.IDENTIFIER, "Expect class name");

            Expr.Variable superClass = null;
            if (match(TokenType.LESS))
            {
                consume(TokenType.IDENTIFIER, "Expect superclass name.");
                superClass = new Expr.Variable(previous());
            }

            consume(TokenType.LEFT_BRACE, "Expect '{' before class body");

            var methods = new List <Stmt.Function>();

            while (!check(TokenType.RIGHT_BRACE) && !isAtEnd())
            {
                methods.Add(function("method"));
            }
            consume(TokenType.RIGHT_BRACE, "Expect '}' after class body");

            return(new Stmt.Class(name, superClass, methods));
        }
예제 #3
0
 public string visitVariableExpr(Expr.Variable expr)
 {
     return(parenthesize("var", expr));
 }
예제 #4
0
 public Class(Token name, Expr.Variable superClass, List <Stmt.Function> methods)
 {
     Name       = name;
     SuperClass = superClass;
     Methods    = methods;
 }
예제 #5
0
 public object visitVariableExpr(Expr.Variable expr)
 {
     return(lookUpVariable(expr.Name, expr));
 }