示例#1
0
        private Stmt ClassDeclaration()
        {
            Token name = Consume(TokenType.IDENTIFIER, "Expect class name.");

            Expr.Variable baseclass = null;

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

            Consume(TokenType.LEFT_BRACE, "Expect '{' before class body.");

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

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

            Consume(TokenType.RIGHT_BRACE, "Expect '}' after class body.");

            return(new Stmt.Class(name, baseclass, methods));
        }
示例#2
0
        public Void VisitVariableExpr(Expr.Variable expr)
        {
            try
            {
                if (scopes.Count > 0 && scopes.Last()[expr.name.Lexeme] == false)
                {
                    ElizScriptCompiler.Error(expr.name,
                                             "Cannot read local variable in its own initializer.");
                }
            }
            catch { }

            ResolveLocal(expr, expr.name);

            return(null);
        }
示例#3
0
 public object VisitVariableExpr(Expr.Variable expr)
 {
     return(LookUpVariable(expr.name, expr));
     //return environment.Get(expr.name);
 }
示例#4
0
 public Class(Token name, Expr.Variable baseclass, List <Function> methods)
 {
     this.name      = name;
     this.methods   = methods;
     this.baseclass = baseclass;
 }