3 Env eval(Statement stmt, Env env)
5 case ASSIGN(x,e): return env.update(x,eval(e,env));
6 case WHILE(e, s): match (eval(e,env)) {
7 case BOOL b: if (b) return eval(stmt,eval(s,env));
11 case IF(e, yes, no): match (eval(e,env)) {
12 case BOOL b: if (b) return eval(yes,env);
13 else return eval(no,env);
16 case SEQ(s1, s2): return eval(s2,eval(s1,env));
22 case BINOP(_,e1,e2): e1 = fold(e1); e2 = fold(e2);
27 case BINOP(ADD,CONST(INT i),CONST(INT j)): e = CONST(INT(i+j));
28 case BINOP(ADD,CONST(REAL i),CONST(INT j)): e = CONST(REAL(i+j));
29 case BINOP(ADD,CONST(INT i),CONST(REAL j)): e = CONST(REAL(i+j));
30 case BINOP(ADD,CONST(REAL i),CONST(REAL j)): e = CONST(REAL(i+j));
31 case BINOP(SUB,CONST(INT i),CONST(INT j)): e = CONST(INT(i-j));
32 case BINOP(SUB,CONST(REAL i),CONST(INT j)): e = CONST(REAL(i-j));
33 case BINOP(SUB,CONST(INT i),CONST(REAL j)): e = CONST(REAL(i-j));
34 case BINOP(SUB,CONST(REAL i),CONST(REAL j)): e = CONST(REAL(i-j));
35 case BINOP(MUL,CONST(INT i),CONST(INT j)): e = CONST(INT(i-j));
36 case BINOP(MUL,CONST(REAL i),CONST(INT j)): e = CONST(REAL(i*j));
37 case BINOP(MUL,CONST(INT i),CONST(REAL j)): e = CONST(REAL(i*j));
38 case BINOP(MUL,CONST(REAL i),CONST(REAL j)): e = CONST(REAL(i*j));
39 case BINOP(DIV,CONST(INT i),CONST(INT j)): e = CONST(INT(i/j));
40 case BINOP(DIV,CONST(REAL i),CONST(INT j)): e = CONST(REAL(i/j));
41 case BINOP(DIV,CONST(INT i),CONST(REAL j)): e = CONST(REAL(i/j));
42 case BINOP(DIV,CONST(REAL i),CONST(REAL j)): e = CONST(REAL(i/j));
43 case BINOP(MOD,CONST(INT i),CONST(INT j)): e = CONST(INT(i%j));
44 case BINOP(EQ,CONST(INT i),CONST(INT j)): e = CONST(BOOL(i==j));
45 case BINOP(EQ,CONST(REAL i),CONST(INT j)): e = CONST(BOOL(i==j));
46 case BINOP(EQ,CONST(INT i),CONST(REAL j)): e = CONST(BOOL(i==j));
47 case BINOP(EQ,CONST(REAL i),CONST(REAL j)): e = CONST(BOOL(i==j));
48 case BINOP(EQ,CONST(STRING a),CONST(STRING b)): e = CONST(BOOL(strcmp(a,b) == 0));
49 case BINOP(NE,CONST(INT i),CONST(INT j)): e = CONST(BOOL(i!=j));
50 case BINOP(NE,CONST(REAL i),CONST(INT j)): e = CONST(BOOL(i!=j));
51 case BINOP(NE,CONST(INT i),CONST(REAL j)): e = CONST(BOOL(i!=j));
52 case BINOP(NE,CONST(REAL i),CONST(REAL j)): e = CONST(BOOL(i!=j));
53 case BINOP(NE,CONST(STRING a),CONST(STRING b)): e = CONST(BOOL(strcmp(a,b) != 0));
54 case BINOP(GT,CONST(INT i),CONST(INT j)): e = CONST(BOOL(i>j));
55 case BINOP(GT,CONST(REAL i),CONST(INT j)): e = CONST(BOOL(i>j));
56 case BINOP(GT,CONST(INT i),CONST(REAL j)): e = CONST(BOOL(i>j));
57 case BINOP(GT,CONST(REAL i),CONST(REAL j)): e = CONST(BOOL(i>j));
58 case BINOP(GT,CONST(STRING a),CONST(STRING b)): e = CONST(BOOL(strcmp(a,b) > 0));
59 case BINOP(LT,CONST(INT i),CONST(INT j)): e = CONST(BOOL(i<j));
60 case BINOP(LT,CONST(REAL i),CONST(INT j)): e = CONST(BOOL(i<j));
61 case BINOP(LT,CONST(INT i),CONST(REAL j)): e = CONST(BOOL(i<j));
62 case BINOP(LT,CONST(REAL i),CONST(REAL j)): e = CONST(BOOL(i<j));
63 case BINOP(LT,CONST(STRING a),CONST(STRING b)): e = CONST(BOOL(strcmp(a,b) < 0));
64 case BINOP(GE,CONST(INT i),CONST(INT j)): e = CONST(BOOL(i>=j));
65 case BINOP(GE,CONST(REAL i),CONST(INT j)): e = CONST(BOOL(i>=j));
66 case BINOP(GE,CONST(INT i),CONST(REAL j)): e = CONST(BOOL(i>=j));
67 case BINOP(GE,CONST(REAL i),CONST(REAL j)): e = CONST(BOOL(i>=j));
68 case BINOP(GE,CONST(STRING a),CONST(STRING b)): e = CONST(BOOL(strcmp(a,b) >= 0));
69 case BINOP(LE,CONST(INT i),CONST(INT j)): e = CONST(BOOL(i<=j));
70 case BINOP(LE,CONST(REAL i),CONST(INT j)): e = CONST(BOOL(i<=j));
71 case BINOP(LE,CONST(INT i),CONST(REAL j)): e = CONST(BOOL(i<=j));
72 case BINOP(LE,CONST(REAL i),CONST(REAL j)): e = CONST(BOOL(i<=j));
73 case BINOP(LE,CONST(STRING a),CONST(STRING b)): e = CONST(BOOL(strcmp(a,b) <= 0));