Set a basic loop for multiple runs of the program
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
f7203440a8
commit
60d81c6332
@ -44,47 +44,56 @@ 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
|
||||||
MemoryStream sourceStream = new(1024);
|
bool exit = false;
|
||||||
Parser parser = new();
|
while (!exit)
|
||||||
bool dynamicInput = false;
|
|
||||||
foreach (var arg in args)
|
|
||||||
{
|
{
|
||||||
if (arg == "-ns")
|
MemoryStream sourceStream = new(1024);
|
||||||
|
Parser parser = new();
|
||||||
|
bool dynamicInput = false;
|
||||||
|
foreach (var arg in args)
|
||||||
{
|
{
|
||||||
nonStrict = true;
|
if (arg == "-ns")
|
||||||
|
{
|
||||||
|
nonStrict = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// From https://stackoverflow.com/questions/3453220/how-to-detect-if-console-in-stdin-has-been-redirected
|
||||||
|
// Reading from pipes is equivalent to reading user input, though the input is redirected
|
||||||
|
if (Console.IsInputRedirected)
|
||||||
|
{
|
||||||
|
// To simplify reading, we read all input bytes from the piped input to the stream.
|
||||||
|
// 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
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sourceStream.Write(Encoding.UTF8.GetBytes("{ \r\n"));
|
||||||
|
sourceStream.Position = 0;
|
||||||
|
dynamicInput = true;
|
||||||
|
}
|
||||||
|
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.");
|
||||||
|
if (dynamicInput == false)
|
||||||
|
{
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
Console.WriteLine("Would you like to parse more programs?");
|
||||||
|
string answer = Console.ReadLine();
|
||||||
|
if (answer.ToLower() == "no")
|
||||||
|
{
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
Console.WriteLine("Not yet implemented");
|
||||||
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
// From https://stackoverflow.com/questions/3453220/how-to-detect-if-console-in-stdin-has-been-redirected
|
|
||||||
// Reading from pipes is equivalent to reading user input, though the input is redirected
|
|
||||||
if (Console.IsInputRedirected)
|
|
||||||
{
|
|
||||||
// To simplify reading, we read all input bytes from the piped input to the stream.
|
|
||||||
// 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
|
|
||||||
sourceStream.Write(Encoding.UTF8.GetBytes(Console.In.ReadToEnd()));
|
|
||||||
sourceStream.Position = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sourceStream.Write(Encoding.UTF8.GetBytes("{ \r\n"));
|
|
||||||
sourceStream.Position = 0;
|
|
||||||
dynamicInput = true;
|
|
||||||
}
|
|
||||||
parser.StartParsing(sourceStream, dynamicInput);
|
|
||||||
Console.WriteLine("\nProgram parsing complete.");
|
|
||||||
if (dynamicInput == false)
|
|
||||||
{
|
|
||||||
Thread.Sleep(2000);
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
Console.WriteLine("Would you like to parse more programs?");
|
|
||||||
string answer = Console.ReadLine();
|
|
||||||
if (answer.ToLower() == "no")
|
|
||||||
{
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
Console.WriteLine("Not yet implemented");
|
|
||||||
Console.ReadLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Parser
|
public class Parser
|
||||||
|
Loading…
x
Reference in New Issue
Block a user