//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); } } }
private static Variable handeTextValue(Logic[] cloneLogicOrder, Variable returnVar, Variable afterEqualSign, string originalStringValue, int lineNumber) { if (cloneLogicOrder [1].word != "+") { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "När du använder extra operatorer på en text variabel med en annan text kan du endast använda \"+\""); } returnVar.setValue(originalStringValue + afterEqualSign.getString()); return(returnVar); }
private static Logic insertTheValue(Variable returnVar) { Print.print("Var type: " + returnVar.variableType); if (returnVar.variableType == VariableTypes.boolean) { return(new BooleanValue(returnVar.getBool())); } else if (returnVar.variableType == VariableTypes.number) { return(new NumberValue(returnVar.getNumber())); } else if (returnVar.variableType == VariableTypes.textString) { return(new TextValue(returnVar.getString())); } return(new Variable("Nill")); }
public static bool parseAndCheckStatement(Logic[] logicOrder, int lineNumber, Scope currentScope) { Variable sum = SumParser.parseIntoSum(logicOrder, lineNumber, currentScope); if (sum.variableType == VariableTypes.number) { if (sum.getNumber() == 0) { return(false); } else { return(true); } } if (sum.variableType == VariableTypes.textString) { if (sum.getString() == "") { return(false); } else { return(true); } } if (sum.variableType == VariableTypes.None) { return(false); } if (sum.variableType != VariableTypes.boolean) { ErrorMessage.sendErrorMessage(lineNumber, ErrorType.IfStatements, IfErrorType.expressionNotCorrectType.ToString(), null); } return(sum.getBool()); }
private static Variable handleNumberValue(Logic[] cloneLogicOrder, Variable returnVar, Variable afterEqualSign, string originalStringValue, int lineNumber) { if (cloneLogicOrder [1].word != "*") { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "När du använder extra operatorer på en text variabel med en siffra kan du endast använda \"*\""); } if (afterEqualSign.getNumber() % 1 != 0) { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "Du kan endast multiplicera strängar med heltal"); } if (afterEqualSign.getNumber() <= 0) { return(returnVar); } for (int i = 0; i < afterEqualSign.getNumber(); i++) { returnVar.setValue(returnVar.getString() + originalStringValue); } return(returnVar); }
public static bool makeComparison(Variable var1, Variable var2, ComparisonType theOperator, int lineNumber) { if (var1.variableType == VariableTypes.unknown || var1.variableType == VariableTypes.unsigned || var2.variableType == VariableTypes.unknown || var2.variableType == VariableTypes.unsigned) { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "En eller flera av operatorerna går inte att tyda"); } if (var1.variableType != var2.variableType) { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "Kan inte utföra jämförelse mellan " + var1.variableType + " och " + var2.variableType); } if (theOperator == ComparisonType.equalsTo) { if (var1.variableType == VariableTypes.boolean) { if (var1.getBool() == var2.getBool()) { return(true); } else { return(false); } } if (var1.variableType == VariableTypes.number) { if (var1.getNumber() == var2.getNumber()) { return(true); } else { return(false); } } if (var1.variableType == VariableTypes.textString) { if (var1.getString() == var2.getString()) { return(true); } else { return(false); } } } if (theOperator == ComparisonType.notEqualsTo) { if (var1.variableType == VariableTypes.boolean) { if (var1.getBool() != var2.getBool()) { return(true); } else { return(false); } } if (var1.variableType == VariableTypes.number) { if (var1.getNumber() != var2.getNumber()) { return(true); } else { return(false); } } if (var1.variableType == VariableTypes.textString) { if (var1.getString() != var2.getString()) { return(true); } else { return(false); } } } if (theOperator == ComparisonType.greaterThenOrEqaulsTo && var1.variableType == VariableTypes.number) { if (var1.getNumber() >= var2.getNumber()) { return(true); } else { return(false); } } if (theOperator == ComparisonType.lessThenOrEqualsTo && var1.variableType == VariableTypes.number) { if (var1.getNumber() <= var2.getNumber()) { return(true); } else { return(false); } } if (theOperator == ComparisonType.lessThen && var1.variableType == VariableTypes.number) { if (var1.getNumber() < var2.getNumber()) { return(true); } else { return(false); } } if (theOperator == ComparisonType.greaterThen && var1.variableType == VariableTypes.number) { if (var1.getNumber() > var2.getNumber()) { return(true); } else { return(false); } } ErrorMessage.sendErrorMessage(lineNumber, ErrorType.System, SystemFailureErrorType.unknownLogic.ToString(), new string[] { "4" }); return(false); }