Skip to content

Commit cba44ae

Browse files
committed
Implemented ambiguous operation mechanism
1 parent bd31007 commit cba44ae

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/jmc/cas/BinaryOperation.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -454,19 +454,12 @@ private Operable simplify(Operable op, BinaryOperation binOp) {
454454
}
455455
break; // I always forget to put break!!!! So many bugs were born simply because I forgot to put this statement!!!!
456456
case "+":
457-
// return binOp.ambiguousIteration((o1, o2, operator) -> {
458-
// if (o1.equals(op) && operator.equals("*")) {
459-
// return Operation.mult(op, Operation.add(o2, 1));
460-
// }
461-
// return null;
462-
// });
463-
if (binOp.operation.equals("*")) {
464-
if (binOp.getLeftHand().equals(op)) {
465-
return Operation.mult(op, Operation.add(binOp.getRightHand(), 1)).simplify(); // again, should x+x*a be simplified to x*(a+1)?
466-
} else if (binOp.getRightHand().equals(op)) {
467-
return Operation.mult(op, Operation.add(binOp.getLeftHand(), 1)).simplify();
457+
return binOp.ambiguousIteration((o1, o2, operator) -> {
458+
if (o1.equals(op) && operator.equals("*")) {
459+
return Operation.mult(op, Operation.add(o2, 1)).simplify();
468460
}
469-
}
461+
return null;
462+
});
470463
}
471464
return null;
472465
}

0 commit comments

Comments
 (0)