package abstractSyntaxTree.Statement; import TypeCheck.TypeCheckResult; import TypeCheck.AbstractType; import abstractSyntaxTree.Expression.IExpression; import java.util.List; public class BlockStatement extends AbstractType implements IStatement{ List statements; public BlockStatement(List statements){ this.statements = statements; } @Override public TypeCheckResult typeCheck() throws Exception { TypeCheckResult result = new TypeCheckResult(); if(statements.size() == 0){ result.type = "void"; } TypeCheckResult blockType = null; for (IStatement statement : statements) { TypeCheckResult typeOfCurrentStatement = statement.typeCheck(); if (blockType == null) { blockType = typeOfCurrentStatement; } else if (!typeOfCurrentStatement.equals(blockType) && !blockType.equals("void")) { throw new IllegalArgumentException("different statement types"); } } return result; } }