public void changeExistingVariable(int index, double newValue, ExpressionParser scopeParser) { removeFromParser(variableList [index].name, scopeParser); variableList [index].setValue(newValue); scopeParser.AddConst(variableList [index].name, () => variableList [index].getNumber()); }
//Later fix! //Should be possible to avoid all the else if statements. public void addVariable(Variable newVar, ExpressionParser scopePareser, int lineNumber) { //First we check if the variable we are trying to add already exists, if it does we change the value of it. //Otherwise create a new variable int tempCont = containsVariable(newVar.name); if (tempCont >= 0) { variableList [tempCont] = newVar; if (newVar.variableType == VariableTypes.boolean) { changeExistingVariable(tempCont, newVar.getBool(), scopePareser); } else if (newVar.variableType == VariableTypes.number) { changeExistingVariable(tempCont, newVar.getNumber(), scopePareser); } else if (newVar.variableType == VariableTypes.textString) { changeExistingVariable(tempCont, newVar.getString(), scopePareser); } else if (newVar.variableType == VariableTypes.None) { changeExistingVariable(tempCont, newVar.getString(), scopePareser); } else { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, ErrorType.System, SystemFailureErrorType.addOrChangeUnsupportedVariableType.ToString(), null); } } else { if (newVar.variableType != VariableTypes.unknown && newVar.variableType != VariableTypes.unsigned) { variableList.Add(newVar); if (newVar.variableType == VariableTypes.number) { scopePareser.AddConst(newVar.name, () => newVar.getNumber()); } } else { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, ErrorType.System, SystemFailureErrorType.addOrChangeUnsupportedVariableType.ToString(), null); } } }