From 1bd6b1b040c539e5ed2c87c15a52939b94d62694 Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Fri, 19 Mar 2021 12:20:01 +1300 Subject: [PATCH] Moved Symbols to the Parser class, made it non-static, therefore instancing it instead of being a static global --- Assignment 1/Program.cs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index fbf6bc1..bb95ec8 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -23,14 +23,6 @@ namespace Assignment_1 Static = 4, Undef = 8 } - - static Dictionary> Symbols = new() - { - { "SPACE", new Tuple(" ", VariableFlags.Reserved | VariableFlags.NoPrint) }, - { "TAB", new Tuple("\t", VariableFlags.Reserved | VariableFlags.NoPrint) }, - { "NEWLINE", new Tuple("\n", VariableFlags.Reserved | VariableFlags.NoPrint) }, - { "CARRIAGE_RETURN", new Tuple("\r", VariableFlags.Reserved | VariableFlags.NoPrint) } - }; /// /// Characters that cannot appear in a normal string /// @@ -80,6 +72,14 @@ namespace Assignment_1 } public class Parser { + Dictionary> Symbols = new() + { + { "SPACE", new Tuple(" ", VariableFlags.Reserved | VariableFlags.NoPrint) }, + { "TAB", new Tuple("\t", VariableFlags.Reserved | VariableFlags.NoPrint) }, + { "NEWLINE", new Tuple("\n", VariableFlags.Reserved | VariableFlags.NoPrint) }, + { "CARRIAGE_RETURN", new Tuple("\r", VariableFlags.Reserved | VariableFlags.NoPrint) } + }; + public enum statements { exit, @@ -225,7 +225,6 @@ namespace Assignment_1 { throw new ParserException("expected a semi-colon", 0, source.Position); } - } else { @@ -256,9 +255,7 @@ namespace Assignment_1 Environment.Exit(-1); } } - } - } else { @@ -267,7 +264,14 @@ namespace Assignment_1 } #region Function Handling - + /// + /// Checks if the next expression in the source meets the requirements of being a key, + /// and optionally verify that key exists. + /// Also contracts the key is not reserved or constant + /// + /// + /// + /// private string ValidateKey(Stream source, bool checkExist) { long keyEndPos = FindIdentifier(source, out string key); @@ -290,6 +294,11 @@ namespace Assignment_1 return key; } + /// + /// Checks if the next expression meets the requirements of being a value + /// + /// + /// private string ValidateValue(Stream source) { long valuePos = FindExpression(source, out string value); @@ -303,6 +312,7 @@ namespace Assignment_1 } return value; } + /// /// Handles the 'append x y [ + z];' case & /// And the 'set x y [ + z];' case @@ -337,8 +347,8 @@ namespace Assignment_1 { int keyWidth = 21; int valueWidth = 50; - int flagWidth = 9; // 80 char total - StringBuilder consoleOutput = new StringBuilder(); + int flagWidth = 9; + StringBuilder consoleOutput = new(); consoleOutput.Append(string.Format("┌" + new string('─', keyWidth) + "┬" + new string('─', valueWidth) + "┬" + new string('─', flagWidth) + "┐\n")); consoleOutput.Append(string.Format("│{0}│{1}│{2}│\n", CenterString("Symbol", keyWidth), CenterString("Value", valueWidth), CenterString("Flags", flagWidth))); // Figure out how many symbols are eligible for printing