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