public Expr VisitExprMinus(ExprMinus expr) { //x-(y+z) = x-y-z if (expr.Right is ExprSubExpr subExprPlus && subExprPlus.SubExpression is ExprPlus plus) { return(new ExprMinus(new ExprMinus(expr.Left, plus.Left.ToSubExprIfComplex()), plus.Right.ToSubExprIfComplex())); } //(x+y)-z = x+y-z if (expr.Left is ExprSubExpr subExprPlusL && subExprPlusL.SubExpression is ExprPlus plusL) { return(new ExprMinus(plusL, expr.Right)); } //x-(y-z) = x-y+z if (expr.Right is ExprSubExpr subExprMinus && subExprMinus.SubExpression is ExprMinus minus) { return(new ExprPlus(new ExprMinus(expr.Left, minus.Left.ToSubExprIfComplex()), minus.Right.ToSubExprIfComplex())); } //(x-y)-z = x-y-z if (expr.Left is ExprSubExpr subExprMinusL && subExprMinusL.SubExpression is ExprMinus minusL) { return(new ExprMinus(minusL, expr.Right)); } //x-(y*z) = x-y*z if (expr.Right is ExprSubExpr subExprMul && subExprMul.SubExpression is ExprMul mul) { return(new ExprMinus(expr.Left, mul)); } //(x*y)-z = x*y-z if (expr.Left is ExprSubExpr subExprMulL && subExprMulL.SubExpression is ExprMul mulL) { return(new ExprMinus(mulL, expr.Right)); } return(expr); }
public Expr VisitExprMinus(ExprMinus expr) { var newLeft = expr.Left.Accept(this).Accept(this._modifier); var newRight = expr.Right.Accept(this).Accept(this._modifier); if (!ReferenceEquals(newLeft, expr.Left) || !ReferenceEquals(newRight, expr.Right)) { return(new ExprMinus(newLeft, newRight)); } return(expr); }
public string VisitExprMinus(ExprMinus expr) => $"{expr.Left.Accept(this)}-{this.CheckPlusMinusParenthesizes(expr.Right)}";
public int VisitExprMinus(ExprMinus expr) => expr.Left.Accept(this) - expr.Right.Accept(this);