private Statement statement; // as opposed to the java version, i have added an initial state here // so there is no need for a manual push of the statement to the stack public ProgramState( ExecutionStackInterface <Statement> execStack, SymbolTableInterface <string, int> symTable, OutputListInterface <int> outList, FileTableInterface <int, FileDescriptor> fTable, Statement initialStatement ) { executionStack = execStack; symbolTable = symTable; outputList = outList; fileTable = fTable; statement = initialStatement; execStack.push(initialStatement); // push the initial statement onto the stack }
public void LogProgramState() { using (StreamWriter logFile = new StreamWriter(File.Open(fileName, FileMode.Append))) { ProgramState programState = Current; ExecutionStackInterface <Statement> executionStack = programState.ExecutionStack; SymbolTableInterface <string, int> symbolTable = programState.SymbolTable; OutputListInterface <int> cout = programState.OutputList; FileTableInterface <int, FileDescriptor> fileTable = programState.FileTable; logFile.WriteLine("ExecStack:"); foreach (Statement stm in executionStack.Content) { logFile.WriteLine(stm); } logFile.WriteLine("SymTable:"); foreach (KeyValuePair <string, int> entry in symbolTable.Content) { logFile.WriteLine(entry.Key + " -> " + entry.Value); } logFile.WriteLine("Output:"); foreach (int k in cout.Content) { logFile.WriteLine(k); } logFile.WriteLine("FileTable:"); foreach (KeyValuePair <int, FileDescriptor> entry in fileTable.Content) { logFile.WriteLine(entry.Key + " -> " + entry.Value); } logFile.WriteLine(); } }