NichtHaskell/Source/abstractSyntaxTree/Expression/BinaryExpression.java
2024-05-02 13:12:39 +02:00

40 lines
1.1 KiB
Java

package abstractSyntaxTree.Expression;
import TypeCheck.TypeCheckResult;
import TypeCheck.TypeCheckHelper;
import TypeCheck.AbstractType;
import java.util.Objects;
public class BinaryExpression extends AbstractType implements IExpression{
public String operator;
public IExpression left;
public IExpression right;
@Override
public TypeCheckResult typeCheck() throws Exception {
TypeCheckHelper helper = new TypeCheckHelper();
TypeCheckResult result = new TypeCheckResult();
TypeCheckResult leftType = left.typeCheck();
TypeCheckResult rightType = right.typeCheck();
switch (operator) {
case "and":
case "or" :{
if (Objects.equals(helper.upperBound(leftType.type, rightType.type), "bool")){
result.valid = true;
result.type = "bool";
}
break;
}
// ==, !=
}
setTypeCheckResult(result); // writes to attribute in abstract type class
return result;
}
}