NichtHaskell/Source/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java
2024-05-02 15:31:31 +02:00

32 lines
1006 B
Java

package abstractSyntaxTree.StatementExpression;
import TypeCheck.AbstractType;
import TypeCheck.TypeCheckHelper;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Statement.IStatement;
import java.util.Objects;
public class AssignStatementExpression extends AbstractType implements IExpression, IStatement {
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();
String upperbound = helper.upperBound(leftType.type, rightType.type);
if (Objects.equals(upperbound, leftType.type)) {
result.type = leftType.type;
}
setTypeCheckResult(result);
return result;
}
}