import java.util.Vector; /** * Implementation of Program using a Vector for storage. * See Program interface for more information */ public class SamProgram implements Program, java.io.Serializable { /* Program Definition: A Sequence of valid SaM instructions, labels, and comments, consisting of at least one instruction. */ protected Vector Iarr = new Vector(); protected SymbolTable syms = new SamSymbolTable(); private static final String BR = System.getProperty("line.separator"); /* Instructions */ public Instruction getInst(int pos) { return (Instruction)Iarr.get(pos); } public void addInst(Instruction i) { Iarr.add(i); } public void addInst(Instruction[] arr) { for (int a = 0; a < arr.length; a++) Iarr.add(arr[a]); } public int getLength() { return Iarr.size(); } /* Symbolic Table */ public SymbolTable getTable() { return syms; } public void setTable(SymbolTable table) { syms = table; } /* Print everything */ public String toString() { String toReturn = "Instructions: " + BR; for (int i = 0; i < Iarr.size(); i++) toReturn += (i) + ": " + Iarr.get(i).toString() + BR; toReturn += BR + "Symbol Table:" + BR + syms.toString(); return toReturn; } }