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
}
