initial
[prop.git] / demos / rewrite-trick4.pC
blobffa631f381e2dadb01b57c8a9c55d3330dec3a22
1 #include <iostream.h>
4 datatype Exp :: rewrite =
5    NUM   of int        => _  
6 |  ADD   of Exp, Exp   => "(" _ "+" _ ")"
9 instantiate datatype Exp;
11 rewrite class Silly (Exp) {
12 public:
13    Silly() {}
16 rewrite Silly {
17    NUM x: { x = x == 0 ? 1 : 2; }
20 int main() 
22    Exp e = ADD(NUM(0),NUM(3));
23    Silly S;
24    cout << "Before = " << e << '\n';
25    S(e);
26    cout << "After = " << e << '\n';
27    return 0;