Ejemplo n.º 1
0
 public Nothing VisitVariableExpr(Expr.Variable expr)
 {
     if (scopes.Count != 0 && scopes.Peek().ContainsKey(expr.Name.Lexeme) && scopes.Peek()[expr.Name.Lexeme] == false)
     {
         Lox.Error(expr.Name, "Cannot read local variable in its own initializer.");
     }
     ResolveLocal(expr, expr.Name);
     return(Nothing.AtAll);
 }
Ejemplo n.º 2
0
        private Stmt ClassDeclaration()
        {
            Token name       = Consume(IDENTIFIER, "Expect class name.");
            Expr  superclass = null;

            if (Match(LESS))
            {
                Consume(IDENTIFIER, "Expect superclass name.");
                superclass = new Expr.Variable(Previous());
            }

            Consume(LEFT_BRACE, "Expect '{' before class body.");
            List <Stmt.Function> methods = new List <Stmt.Function>();

            while (!Check(RIGHT_BRACE) && !IsAtEnd())
            {
                methods.Add(Function("method"));
            }

            Consume(RIGHT_BRACE, "Expect '}' after class body.");
            return(new Stmt.Class(name, superclass, methods));
        }
Ejemplo n.º 3
0
 public object VisitVariableExpr(Expr.Variable expr)
 {
     return(LookUpVariable(expr.Name, expr));
 }
Ejemplo n.º 4
0
 public string VisitVariableExpr(Expr.Variable expr)
 {
     throw new System.NotImplementedException();
 }