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