Ejemplo n.º 1
0
        public object VisitVariableExpr(Expr.Variable expr)
        {
            _scopes.TryPeek(out IDictionary <string, bool> peekedDictionary);
            bool getValue = false;

            peekedDictionary?.TryGetValue(expr.Name.Lexeme, out getValue);
            if (_scopes.Count != 0 && getValue == false)
            {
                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(IDENTIFIER, "Expect class name.");

            Expr.Variable 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 Class(Token name, Expr.Variable superclass, IEnumerable <Stmt.Function> methods)
 {
     this.Name       = name;
     this.Superclass = superclass;
     this.Methods    = methods;
 }
Ejemplo n.º 5
0
 public string Visit(Expr.Variable expr)
 {
     throw new NotImplementedException();
 }