diff --git a/src/main/java/de/maishai/ExpressionGenerator.java b/src/main/java/de/maishai/ExpressionGenerator.java index ff3a6e0..89421d8 100644 --- a/src/main/java/de/maishai/ExpressionGenerator.java +++ b/src/main/java/de/maishai/ExpressionGenerator.java @@ -69,9 +69,13 @@ public class ExpressionGenerator extends DecafBaseVisitor { public static Binary generateBinary(DecafParser.BinaryOperationContext ctx) { ExpressionGenerator eGen = new ExpressionGenerator(); - return new Binary(eGen.visit(ctx.expr().get(0)) // left side + Binary binary = new Binary(eGen.visit(ctx.expr().get(0)) // left side , generateOperator(ctx.binaryOp()) //operator , eGen.visit(ctx.expr().get(1))); //right side + binary = pointBeforeLineLogic(ctx, binary); + + + return binary; } public static Operator generateOperator(DecafParser.BinaryOpContext ctx) { @@ -143,4 +147,19 @@ public class ExpressionGenerator extends DecafBaseVisitor { } throw new RuntimeException(); } + + private static Binary pointBeforeLineLogic(DecafParser.BinaryOperationContext ctx, Binary binary) { + if (ctx.expr().get(0).getText().charAt(ctx.expr().get(0).getText().length()-1) == ')'){ + return binary; + } + if (!(binary.op() == Operator.MUL || binary.op() == Operator.DIV || binary.op() == Operator.MOD)){ + return binary; + } + if (binary.left() instanceof Binary left){ + if (left.op() == Operator.ADD || left.op() == Operator.SUB ){ + return new Binary(left.left(), left.op(), new Binary(binary.right(), binary.op(),left.right())); + } + } + return binary; + } }