From 8774264207e7120192541e43d0a77146ceecd53d Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Tue, 23 Mar 2021 11:26:38 +1300 Subject: [PATCH] Added the continued execution logic --- Assignment 1/Program.cs | 48 +++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index e5e356f..f7afa91 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -78,6 +78,7 @@ namespace Assignment_1 parser.StartParsing(sourceStream, dynamicInput); Console.WriteLine(Environment.NewLine + new string('─', 40)); // Not strictly required, but could have problems if we try loading a large program immediately after unloading the last + // NB: parser is out-of-scope from now GC.Collect(); Console.WriteLine("\nProgram parsing complete."); if (dynamicInput == false) @@ -85,14 +86,49 @@ namespace Assignment_1 Thread.Sleep(2000); Environment.Exit(0); } - Console.WriteLine("Would you like to parse more programs?"); - string answer = Console.ReadLine(); - if (answer.ToLower() == "no") + ConsoleKeyInfo ck = new(); + while (ck.Key != ConsoleKey.Y || ck.Key != ConsoleKey.N) { - Environment.Exit(0); + Console.WriteLine("\nWould you like to parse more programs? Y/n:"); + ck = Console.ReadKey(); } - Console.WriteLine("Not yet implemented"); - Console.ReadLine(); + if (ck.Key == ConsoleKey.N) + { + exit = true; + } + else + { + // Need the logic to prep the next source stream + ck = new(); + while (ck.Key != ConsoleKey.Y || ck.Key != ConsoleKey.N) + { + Console.WriteLine("\nWould you like to pipe data from source file? Y/n:"); + ck = Console.ReadKey(); + } + if (ck.Key == ConsoleKey.N) + { + // Set the input to standard input stream + Console.SetIn(Console.In); + } + else + { + Console.WriteLine("Enter the source path:"); + string sourcePath = Console.ReadLine(); + if (File.Exists(sourcePath)) + { + try + { + Console.SetIn(File.OpenText(sourcePath)); + } + catch (Exception e) + { + Console.WriteLine("Encountered an error opening the source file: " + e.Message); + } + } + } + } + // GC already done, just loop back to program start + } }