// [Lhs / Rhs] / number public override ASTNode TryDivide(ASTNode number) { if (Lhs.IsNumeric) { // [Lhs / Rhs] / number --> [Lhs / number] / Rhs return(new ASTQuotient(new ASTQuotient(Lhs, number), Rhs)); } if (Rhs.IsNumeric) { // [Lhs / Rhs] / number --> Lhs / [Rhs * number] ASTNode product = new ASTParenthesized(new ASTProduct(Rhs, number)); ASTNode normalized = Lhs.TryDivide(product); return((normalized != null) ? normalized : new ASTQuotient(Lhs, product)); } return(null); }
// [Lhs / Rhs] * number public override ASTNode TryMultiply(ASTNode number) { if (Lhs.IsNumeric) { // [Lhs / Rhs] * number --> [Lhs * number] / Rhs return(new ASTQuotient(new ASTProduct(Lhs, number), Rhs)); } else if (Rhs.IsNumeric) { // [Lhs / Rhs] * number --> Lhs * [number / Rhs] ASTNode quotient = new ASTQuotient(number, Rhs); ASTNode normalized = Lhs.TryDivide(quotient); return((normalized != null) ? normalized : new ASTQuotient(Lhs, quotient)); } return(null); }
public override ASTNode TryNormalize() { return(Rhs.IsNumeric ? Lhs.TryDivide(Rhs) : null); }