if (curExpr instanceof E_LogicalOr)
{
if (!(leftExpr instanceof E_LogicalAnd) && !(rightExpr instanceof E_LogicalAnd))
{
// no distributive law - normal or
this.resultExpr = new E_LogicalOr(leftExpr, rightExpr);
}else
{
// criterion for distributive law - first OR, then AND
if (leftExpr instanceof E_LogicalAnd)
{
leftLeftExpr = ((E_LogicalAnd)leftExpr).getArg1();
rightLeftExpr = ((E_LogicalAnd)leftExpr).getArg2();
// OR AND will become to AND OR OR
newOrExpr1 = new E_LogicalOr(leftLeftExpr, rightExpr);
newOrExpr2 = new E_LogicalOr(rightLeftExpr, rightExpr);
newAndExpr = new E_LogicalAnd(newOrExpr1, newOrExpr2);
this.resultExpr = newAndExpr;
// apply for subexpression again
newAndExpr.visit(this);
}
if (rightExpr instanceof E_LogicalAnd)
{
leftRightExpr = ((E_LogicalAnd)rightExpr).getArg1();
rightRightExpr = ((E_LogicalAnd)rightExpr).getArg2();
// OR AND will become to AND OR OR
newOrExpr1 = new E_LogicalOr(leftExpr, leftRightExpr);
newOrExpr2 = new E_LogicalOr(leftExpr, rightRightExpr);
newAndExpr = new E_LogicalAnd(newOrExpr1, newOrExpr2);
this.resultExpr = newAndExpr;
// apply for subexpression again
newAndExpr.visit(this);