From ac6a192fb07b8c4673c5dd27bc36eb4db1b265c7 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Wed, 17 Mar 2021 17:27:48 +1300 Subject: [PATCH] Added multi-line parsing --- Assignment 1/Program.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index 7ce071a..cc8f93a 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -88,20 +88,35 @@ namespace Assignment_1 long initSourceLength = source.Length; if ((byte)source.ReadByte() == '{') { + long lastLinePos = 0; + long initPos = 0; + bool cont = false; while (true) { if (dynamicInput) { - Console.WriteLine("Enter a command: "); + lastLinePos = source.Position; + if (!cont) + { + Console.WriteLine("Enter a command: "); + } string s = Console.ReadLine(); long pos = source.Position; source.Write(Encoding.UTF8.GetBytes(s)); source.Position = pos; + } // parse the statement or list of statements; // This is done by reading the next word + if (!cont) + { + initPos = source.Position; + } + else + { + source.Position = initPos; + } SkipWhitespace(source); - long initPos = source.Position; long position = FindNextWord(source, out string word); try { @@ -165,6 +180,7 @@ namespace Assignment_1 if (IsNextEoS(source)) { // Increment the source pos past the semi-colon + cont = false; source.Position++; if (dynamicInput) { @@ -173,6 +189,13 @@ namespace Assignment_1 } result(); } + else if(source.Position != lastLinePos) + { + // In the case that we expect some more data, we must keep tabs of our current line, and keep accumulating data until we're finished + cont = true; + source.WriteByte((byte)' '); + Console.Write(">"); + } else { throw new ParserException("expected a semi-colon", 0, source.Position);