2 #include <AD/generic/generic.h>
7 Rewritable() : enabled(true) {}
8 void enable() { enabled = true; }
9 void disable() { enabled = false; }
10 Bool is_enabled() { return enabled; }
13 datatype Exp : public Rewritable :: rewrite =
15 | ADD of Exp, Exp => "(" _ "+" _ ")"
17 { friend Exp FINAL(Exp e) { e->disable(); return e; }
21 instantiate datatype Exp;
23 rewrite class Silly (Exp) {
29 NUM 0 | redex->is_enabled(): FINAL(NUM(1))
30 | NUM x | redex->is_enabled(): FINAL(NUM(2))
35 Exp e = ADD(NUM(0),NUM(3));
37 cout << "Before = " << e << '\n';
39 rewrite (e) type (Exp) { (e : Exp): { e->enable(); } }
40 cout << "After = " << e << '\n';