1abstract
2class UnaryExpr extends Expr {
3
4
5
6 protected
7 Expr operand;
8
9
10
11 protected
12 UnaryExpr(Expr operand) {
13 this.operand = operand;
14 }
15
16 public Object eval() {
17 Object v1 = operand.eval();
18 return
19 op1(v1);
20 }
21
22 public
23 String toString() {
24 return
25 "(" +
26 op1ToString() +
27 operand.toString() +
28 ")";
29 }
30
31
32
33 protected abstract Object op1(Object v1);
34 protected abstract String op1ToString();
35}