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