1public
2class BinaryPlus extends BinaryExpr {
3
4 public
5 BinaryPlus(Expr left, Expr right) {
6 super(left, right);
7 }
8
9
10
11 protected
12 Object op2(Object v1, Object v2) {
13
14
15 if ( v1 instanceof Integer
16 &&
17 v2 instanceof Integer ) {
18
19 return
20 new Integer( ((Integer)v1).intValue()
21 +
22 ((Integer)v2).intValue() );
23 }
24
25
26 if ( v1 instanceof Double
27 &&
28 v2 instanceof Double ) {
29
30 return
31 new Double( ((Double)v1).doubleValue()
32 +
33 ((Double)v2).doubleValue() );
34 }
35
36
37 throw
38 new IllegalArgumentException("binary + : illegal operand types");
39 }
40
41
42
43 protected
44 String op2ToString() {
45 return
46 "+";
47 }
48}
49