package abstractSyntaxTree.Statement; import TypeCheck.TypeCheckResult; import TypeCheck.AbstractType; import abstractSyntaxTree.Expression.IExpression; public class IfStatement extends AbstractType implements IStatement{ IExpression condition; IStatement ifStatement; public IfStatement(IExpression condition, IStatement ifStatement) { this.condition = condition; this.ifStatement = ifStatement; } @Override public TypeCheckResult typeCheck() throws Exception { TypeCheckResult result = new TypeCheckResult(); TypeCheckResult conditionType = condition.typeCheck(); if (!conditionType.equals("boolean")) { throw new IllegalArgumentException("should be boolean"); } TypeCheckResult ifStatementType = ifStatement.typeCheck(); result.type = ifStatementType.type; return result; } }