diff --git a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs
index 44dc947..ba00219 100644
--- a/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs
+++ b/Advanced Software Engineering/Advanced Software Engineering/SettingsAndHelperFunctions.cs
@@ -3,6 +3,24 @@ using System.Windows.Forms;
namespace Advanced_Software_Engineering {
+ public class CommandAndParameterParserResult {
+ string command;
+ string[] parameters;
+
+ public CommandAndParameterParserResult(string command, string[] parameters) {
+ this.command = command;
+ this.parameters = parameters;
+ }
+
+ public string getCommand() {
+ return command;
+ }
+
+ public string[] getParameters() {
+ return parameters;
+ }
+ }
+
///
/// This class simply provides settings and some functions that are used across many components.
///
@@ -98,39 +116,39 @@ namespace Advanced_Software_Engineering {
///
/// A string command
/// Directory with the command and its parameters cleanly separated
- public static Dictionary CommandAndParameterParser(string text) {
- Dictionary commandAndParameters = new Dictionary();
+ public static CommandAndParameterParserResult CommandAndParameterParser(string text) {
//prepare the parameters by stripping them of spaces
string prepParameters = Strip(text);
- if (prepParameters.Length == 0) return commandAndParameters;
+ if (prepParameters.Length == 0) return null;
//split the command from the parameters
- string[] parameters = prepParameters.Split(new char[] { " "[0] }, 2);
+ string[] splitCommand = prepParameters.Split(new char[] { " "[0] }, 2);
+ string command = null;
+ string[] parameters = null;
//There are parameters, make the command
- if (parameters.Length > 0) {
+ if (splitCommand.Length > 0) {
//set command var
- string command = Strip(parameters[0]);
- commandAndParameters["command"] = new string[] { command };
+ command = Strip(splitCommand[0]);
}
//There is at least one parameter
- if (parameters.Length > 1) {
+ if (splitCommand.Length > 1) {
//seperate all of the parameters by a comma
- parameters = parameters[1].Split(","[0]);
+ splitCommand = splitCommand[1].Split(","[0]);
//Remove spaces around parameters
- parameters = StripStringArray(parameters).ToArray();
+ splitCommand = StripStringArray(splitCommand).ToArray();
//We don't want parameters if there aren't any
- if (!(parameters.Length == 1 && parameters[0] == "")) {
+ if (!(splitCommand.Length == 1 && splitCommand[0] == "")) {
//set parameter list
- commandAndParameters["parameters"] = parameters;
+ parameters = splitCommand;
}
}
- return commandAndParameters;
+ return new CommandAndParameterParserResult(command, parameters);
}
}
}
\ No newline at end of file
diff --git a/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs b/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs
index dc2c2d9..563382a 100644
--- a/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs
+++ b/Advanced Software Engineering/Advanced Software Engineering/Verbs/VerbFactory.cs
@@ -23,28 +23,27 @@ namespace Advanced_Software_Engineering {
/// The command as a string
/// A IVerb that maches the command
public static IVerb MakeVerb(Drawer drawer, string fullCommand) {
- Dictionary commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand);
+ CommandAndParameterParserResult result = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand);
- if (!commandAndParameters.Keys.Contains("command")) throw new Exception("There is no command to process");
-
- string command = commandAndParameters["command"][0];
+ string command = result.getCommand();
+ string[] commandParameters = result.getParameters();
+ if (command == null) throw new Exception("There is no command to process");
//process declarations first
- if(commandAndParameters.ContainsKey("parameters"))
-
+ if(!(commandParameters == null))
switch (command) {
case "int":
case "double":
case "bool":
case "color":
- if (commandAndParameters["parameters"].Length == 1) {
- return new DeclareVariable(drawer, command, commandAndParameters["parameters"][0]);
+ if (commandParameters.Length == 1) {
+ return new DeclareVariable(drawer, command, commandParameters[0]);
} else throw new Exception(command + "s need to be initialised");
default:
//assignment
- if (command.Contains("=") && !command.Contains("==")) {
+ if (drawer.CheckVariableExists(command)) {
string[] assignmentCommands = command.Split("="[0]);
if (assignmentCommands.Length > 2) throw new Exception("Cannot have two assignments");
return new UpdateVariable(drawer, assignmentCommands[0], ValueFactory.CreateValue(drawer, assignmentCommands[1]));
@@ -54,7 +53,7 @@ namespace Advanced_Software_Engineering {
List parameters = new List();
- if( commandAndParameters.ContainsKey("parameters") ) foreach(string parameter in commandAndParameters["parameters"]) {
+ if( !(commandParameters == null) ) foreach(string parameter in commandParameters) {
parameters.Add(ValueFactory.CreateValue(drawer, parameter));
}
int parameterLength = parameters.Count;