コード例 #1
0
        private Stmt ClassDeclaration()
        {
            var 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.");

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

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

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

            return(new Stmt.Class(name, superclass, methods));
        }
コード例 #2
0
 internal Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods)
 {
     this.name       = name;
     this.superclass = superclass;
     this.methods    = methods;
 }