Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
 public string visitVariableExpr(Expr.Variable expr)
 {
     return(parenthesize("var", expr));
 }
Ejemplo n.º 4
0
 public Class(Token name, Expr.Variable superClass, List <Stmt.Function> methods)
 {
     Name       = name;
     SuperClass = superClass;
     Methods    = methods;
 }
Ejemplo n.º 5
0
 public object visitVariableExpr(Expr.Variable expr)
 {
     return(lookUpVariable(expr.Name, expr));
 }