mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 17:08:03 +00:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
3b0649f5cd
@ -69,9 +69,13 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
|
|
||||||
public static Binary generateBinary(DecafParser.BinaryOperationContext ctx) {
|
public static Binary generateBinary(DecafParser.BinaryOperationContext ctx) {
|
||||||
ExpressionGenerator eGen = new ExpressionGenerator();
|
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
|
, generateOperator(ctx.binaryOp()) //operator
|
||||||
, eGen.visit(ctx.expr().get(1))); //right side
|
, eGen.visit(ctx.expr().get(1))); //right side
|
||||||
|
binary = pointBeforeLineLogic(ctx, binary);
|
||||||
|
|
||||||
|
|
||||||
|
return binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Operator generateOperator(DecafParser.BinaryOpContext ctx) {
|
public static Operator generateOperator(DecafParser.BinaryOpContext ctx) {
|
||||||
@ -143,4 +147,19 @@ public class ExpressionGenerator extends DecafBaseVisitor<Expression> {
|
|||||||
}
|
}
|
||||||
throw new RuntimeException();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user