
package cz.karry.dop.parser;

import java.util.ArrayList;

/**
 *
 * @author karry
 */
public class Block {
    ArrayList<MInstruction> instructions = new ArrayList<MInstruction>();
    private int maxRequiredLength=1;
    
    Block(){
        
    }
    
    public void addMInstruction(MInstruction instr) throws SyntaxError{
        instructions.add(instr);
    }
        
    public String getFirstLabel(){
        return this.instructions.get(0).getLabel();
    }
    
    public void requiredLength(int length, int srcLine) throws SyntaxError{
        if (length > this.maxRequiredLength){
            if (length>this.instructions.size()){
                throw new SyntaxError("Block \""+this.getFirstLabel().substring(2)+"\" is too small! (Error on line "+srcLine+", length is "+this.instructions.size()+" required "+length+")",srcLine);
            }else
                this.maxRequiredLength = length;
        }
    }
    
    public int getRequiredLength(){
        return this.maxRequiredLength;
    }
}
