package com.example.Models.Statements;

import com.example.Exceptions.BaseException;
import com.example.Models.Program.IDictionary;
import com.example.Models.Program.IStack;
import com.example.Models.Program.ProgramState;
import com.example.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
}
