Files
School/Anul 2/Semestrul 1/Metode avansate de programare/Interpretor/Models/Statements/CompoundStatement.java
T
2024-08-31 12:07:21 +03:00

41 lines
1.1 KiB
Java

package Models.Statements;
import Exceptions.BaseException;
import Models.Program.IDictionary;
import Models.Program.IStack;
import Models.Program.ProgramState;
import Models.Types.IType;
public class CompoundStatement implements IStatement {
//region Fields
private IStatement first;
private IStatement second;
//endregion
//region Exposed Methods
public CompoundStatement(IStatement first, IStatement second){
this.first = first;
this.second = second;
}
public String toString(){
return "(" + first.toString() + ";" + second.toString() + ")";
}
public IStatement copy(){
return new CompoundStatement(first.copy(), second.copy());
}
public ProgramState execute(ProgramState state){
IStack<IStatement> stack = state.getStack();
stack.push(second);
stack.push(first);
return null;
}
public IDictionary<String, IType> typeCheck(IDictionary<String, IType> typeTable) throws BaseException{
return second.typeCheck(first.typeCheck(typeTable));
}
//endregion
}