Beispiel #1
0
        private GStmt.Stmt classDeclaration()
        {
            Token name = consume(tt.IDENTIFIER, "Expect class name");

            GExpr.Variable superclass = null;
            if (Match(tt.LESS))
            {
                consume(tt.IDENTIFIER, "Expect superclass name");
                superclass = new GExpr.Variable(previous());
            }

            consume(tt.LEFT_BRACE, "Expect '{' before class body");

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

            while (!check(tt.RIGHT_BRACE) && !isAtEnd())
            {
                methods.Add(function("method") as GStmt.Function);
            }

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

            return(new GStmt.Class(name, superclass, methods));
        }
Beispiel #2
0
 public Object visit_Variable_Expr(GExpr.Variable expr)
 {
     return(lookUpVariable(expr.name, expr));
 }