Example #1
0
        public object visitVariableExpr(Expr.Variable expr)
        {
            if (scopes.Count > 0 && scopes[scopes.Count - 1].ContainsKey(expr.name.lexeme))
            {
                if (scopes[scopes.Count - 1][expr.name.lexeme] == false)
                {
                    Jingle.Error(expr.name, "Cannot read local variable in its own initializer.");
                }
            }

            resolveLocal(expr, expr.name);
            return(null);
        }
Example #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.COLON, "Expect '{' before class body.");

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

            while (!check(TokenType.END) && !isAtEnd())
            {
                methods.Add(function("method"));
            }

            consume(TokenType.END, "Expect '}' after class body.");

            return(new Stmt.Class(name, superclass, methods));
        }
Example #3
0
 public string visitVariableExpr(Expr.Variable expr)
 {
     return("");
 }
Example #4
0
 public Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods)
 {
     this.name       = name;
     this.superclass = superclass;
     this.methods    = methods;
 }
Example #5
0
 public object visitVariableExpr(Expr.Variable expr)
 {
     return(lookUpVariable(expr.name, expr));
 }