From 34601492586a77d503dc339cfe3d3632b5e0f68c Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Thu, 11 Mar 2021 17:18:02 +1300 Subject: [PATCH] Added Set Function --- Assignment 1/Program.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index 35bac08..65f3606 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -180,6 +180,40 @@ namespace Assignment_1 return true; } + bool Set(Stream source) + { + string identifier; + long resultPos = FindIdentifier(source, out identifier); + if (resultPos < 0) + { + // Couldn't match an identifier + // If ID Doesn't exist, we should make it + return false; + } + source.Position = resultPos; + string expression; + resultPos = FindExpression(source, out expression); + if (resultPos < 0) + { + // Couldn't match expression + return false; + } + if (Symbols.ContainsKey(identifier)) + { + if (Symbols[identifier].Item2 == VariableFlags.Reserved) + { + Console.WriteLine("Error: Cannot assign to {0} as it is a reserved constant."); + return false; + } + Symbols[identifier] = new Tuple(expression, Symbols[identifier].Item2); + } + else + { + Symbols.Add(identifier, new Tuple(expression, VariableFlags.Empty)); + } + return true; + } + #endregion #region Data Handling // Data Handling