Set a basic loop for multiple runs of the program
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded

This commit is contained in:
Brychan Dempsey 2021-03-19 12:42:38 +13:00
parent f7203440a8
commit 60d81c6332

View File

@ -44,6 +44,9 @@ namespace Assignment_1
Console.WriteLine("│ Submitted by Brychan Dempsey, 14299890 │"); Console.WriteLine("│ Submitted by Brychan Dempsey, 14299890 │");
Console.WriteLine("└──────────────────────────────────────────┘"); Console.WriteLine("└──────────────────────────────────────────┘");
// Parse the source from the memory stream // Parse the source from the memory stream
bool exit = false;
while (!exit)
{
MemoryStream sourceStream = new(1024); MemoryStream sourceStream = new(1024);
Parser parser = new(); Parser parser = new();
bool dynamicInput = false; bool dynamicInput = false;
@ -62,6 +65,8 @@ namespace Assignment_1
// This is by far not the best way to do it; reading line-by-line would reduce memory space, // This is by far not the best way to do it; reading line-by-line would reduce memory space,
// but it allows a simple read into the console // but it allows a simple read into the console
sourceStream.Write(Encoding.UTF8.GetBytes(Console.In.ReadToEnd())); sourceStream.Write(Encoding.UTF8.GetBytes(Console.In.ReadToEnd()));
// Dispose will close a piped input, or piped file in further iterations of the program
Console.In.Dispose();
sourceStream.Position = 0; sourceStream.Position = 0;
} }
else else
@ -71,6 +76,9 @@ namespace Assignment_1
dynamicInput = true; dynamicInput = true;
} }
parser.StartParsing(sourceStream, dynamicInput); 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
GC.Collect();
Console.WriteLine("\nProgram parsing complete."); Console.WriteLine("\nProgram parsing complete.");
if (dynamicInput == false) if (dynamicInput == false)
{ {
@ -86,6 +94,7 @@ namespace Assignment_1
Console.WriteLine("Not yet implemented"); Console.WriteLine("Not yet implemented");
Console.ReadLine(); Console.ReadLine();
} }
}
public class Parser public class Parser
{ {