2024-04-25 13:27:38 +02:00
|
|
|
package abstractSyntaxTree.Statement;
|
|
|
|
|
2024-05-02 13:12:39 +02:00
|
|
|
import TypeCheck.TypeCheckResult;
|
|
|
|
import TypeCheck.AbstractType;
|
2024-05-02 14:31:37 +02:00
|
|
|
import abstractSyntaxTree.Expression.IExpression;
|
2024-05-02 13:12:39 +02:00
|
|
|
|
|
|
|
public class WhileStatement extends AbstractType implements IStatement{
|
2024-05-02 14:31:37 +02:00
|
|
|
IExpression condition;
|
|
|
|
IStatement statement;
|
|
|
|
public WhileStatement(IExpression condition, IStatement statement) {
|
|
|
|
this.condition = condition;
|
|
|
|
this.statement = statement;
|
|
|
|
}
|
2024-05-02 13:12:39 +02:00
|
|
|
@Override
|
|
|
|
public TypeCheckResult typeCheck() throws Exception {
|
2024-05-02 14:31:37 +02:00
|
|
|
TypeCheckResult result = new TypeCheckResult();
|
|
|
|
|
|
|
|
TypeCheckResult conditionType = condition.typeCheck();
|
|
|
|
|
|
|
|
if (!conditionType.equals("bool")) {
|
|
|
|
throw new IllegalArgumentException("Expected boolean");
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeCheckResult statementType = statement.typeCheck();
|
|
|
|
|
|
|
|
result.type = statementType.type;
|
|
|
|
return result;
|
2024-05-02 13:12:39 +02:00
|
|
|
}
|
2024-04-25 13:27:38 +02:00
|
|
|
}
|