package abstractSyntaxTree.Expression; import TypeCheck.AbstractType; import TypeCheck.TypeCheckHelper; import TypeCheck.TypeCheckResult; import abstractSyntaxTree.Datatype.IDatatype; import java.util.Objects; public class UnaryExpression extends AbstractType implements IExpression{ public String operator; public IDatatype operand; @Override public TypeCheckResult typeCheck() throws Exception { TypeCheckResult result = new TypeCheckResult(); TypeCheckResult operandTypeCheckResult = operand.typeCheck(); String operandType = operandTypeCheckResult.type; switch (operator) { case "!" :{ if (Objects.equals(operandType, "bool")){ result.type = "bool"; } break; } case "-": case "+": if (Objects.equals(operandType, "int")){ result.type = "int"; } break; } setTypeCheckResult(result); return result; } }