示例#1
0
 public object VisitVariableExpr(Expr.Variable expr)
 {
     if (scopes.Count != 0 && scopes.Peek().ContainsKey(expr.name.lexeme) && scopes.Peek()[expr.name.lexeme] == false)
     {
         Basil.Error(expr.name, "Cannot read local variable in its own initializer.");
     }
     ResolveLocal(expr, expr.name);
     return(null);
 }
示例#2
0
        private Stmt ClassDeclaration()
        {
            Token name       = Consume(Token.TokenType.Identifier, "Expect class name.");
            Expr  superclass = null;

            if (Match(Token.TokenType.Less))
            {
                Consume(Token.TokenType.Identifier, "Expect superclass name.");
                superclass = new Expr.Variable(Previous());
            }
            Consume(Token.TokenType.LeftBrace, "Expect '{' before class body.");
            List <Stmt.Function> methods = new List <Stmt.Function>();

            while (!Check(Token.TokenType.RightBrace) && !IsAtEnd())
            {
                methods.Add(Function("method"));
            }
            Consume(Token.TokenType.RightBrace, "Expect '}' after class body.");
            return(new Stmt.Class(name, superclass, methods));
        }
示例#3
0
 public object VisitVariableExpr(Expr.Variable expr)
 {
     return(LookUpVariable(expr.name, expr));
 }
示例#4
0
 public string VisitVariableExpr(Expr.Variable expr)
 {
     return(expr.name.ToString());
 }