diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index 24c0177..d25c459 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -77,7 +77,8 @@ namespace Assignment_1 printwordcount, set, reverse, - h + h, + writeout } public void StartParsing(Stream source, bool dynamicInput = false) { @@ -97,6 +98,7 @@ namespace Assignment_1 // parse the statement or list of statements; // This is done by reading the next word SkipWhitespace(source); + long initPos = source.Position; long position = FindNextWord(source, out string word); object statementType; if (Enum.TryParse(typeof(statements), word, out statementType)) @@ -138,9 +140,20 @@ namespace Assignment_1 Console.WriteLine("\t{0}", ((statements)item).ToString()); } break; + case statements.writeout: + // Writes the full command history to the stream. + Console.WriteLine("Writing input commands to {0}..."); + break; } } - else Console.WriteLine("Failed parsing statement"); + else + { + // Statement parse failed, + // Ensure stream gets trimmed back to the correct position + Console.WriteLine("Failed parsing statement"); + source.Position = initPos; + source.SetLength(initPos); + } } }