Ejemplo n.º 1
0
        public object visitVariableExpr(Expr.Variable expr)
        {
            //jlox: (!scopes.isEmpty() && scopes.peek().get(expr.name.lexeme) == Boolean.FALSE)
            if (scopes.Count > 0 && scopes[scopes.Count - 1].ContainsKey(expr.name.lexeme))
            {
                if (scopes[scopes.Count - 1][expr.name.lexeme] == false) // declared but not yet defined
                {
                    Lox.error(expr.name, "Cannot read local variable in its own initializer.");
                }
            }

            resolveLocal(expr, expr.name);
            return(null);
        }
Ejemplo n.º 2
0
        private Stmt classDeclaration()
        {
            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.");

            List <Stmt.Function> 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("");
 }
Ejemplo n.º 4
0
 public object visitVariableExpr(Expr.Variable expr)
 {
     return(lookUpVariable(expr.name, expr));
 }
Ejemplo n.º 5
0
 public Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods)
 {
     this.name       = name;
     this.superclass = superclass;
     this.methods    = methods;
 }