static void setNewExpectVariable(expectType expect, VariableTypes newType, int lineNumber, Logic[] logicOrder) { if (expect.currentType == VariableTypes.unknown) { return; } if (expect.currentType == VariableTypes.unsigned) { expect.currentType = newType; } else if (expect.currentType != newType) { var firstSumType = SumParser.TypeToString(expect.currentType); var secondSumType = SumParser.TypeToString(newType); string errorMessage; if (firstSumType == "" || secondSumType == "") { errorMessage = "Misslyckades med att para ihop " + expect.currentType + " med " + newType; } else { errorMessage = "Kan inte para ihop " + firstSumType + " med " + secondSumType + "."; } ErrorMessage.sendErrorMessage(lineNumber, errorMessage); } if (expect.currentType == VariableTypes.boolean) { BooleanSumParser.validBoolSum(logicOrder, lineNumber); } }
static bool handleOnlyValueStatement(Logic[] logicOrder, int lineNumber, Scope currentScope) { Variable sum = SumParser.parseIntoSum(logicOrder, lineNumber, currentScope); if (sum.variableType != VariableTypes.boolean) { ErrorMessage.sendErrorMessage(lineNumber, "När du skriver in endast ett värde, måste det vara Sant eller Falskt"); } return(sum.getBool()); }
private static Variable[] parseInputVariables(List <Logic[]> packedLogics, int lineNumber, Function calledFunction, Scope currentScope) { Variable[] inputVariables = new Variable[packedLogics.Count]; for (int i = 0; i < packedLogics.Count; i++) { inputVariables [i] = SumParser.parseIntoSum(packedLogics [i], lineNumber, currentScope); } foreach (Variable v in inputVariables) { if (v.variableType == VariableTypes.unknown) { ErrorMessage.sendErrorMessage(lineNumber, "En eller flera av inparametrarna till: " + calledFunction.name + " är korrupta"); } } return(inputVariables); }
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 string convertIntoBoolAlgebra(Logic[] logicOrder, int lineNumber, Scope currentScope) { string boolString = ""; for (int i = 0; i < logicOrder.Length; i++) { if (logicOrder [i] is AndOrOperator) { if (logicOrder[i].currentType == WordTypes.andOperator) { boolString += "*"; } else { boolString += "+"; } continue; } if (logicOrder [i].currentType == WordTypes.package) { Variable tempSum = SumParser.parseIntoSum((logicOrder [i] as Package).logicOrder, lineNumber, currentScope); if (tempSum.getBool()) { boolString += "1"; } else { boolString += "0"; } } else { ErrorMessage.sendErrorMessage(lineNumber, "Korrupt uttryck"); } } return(boolString); }
public static Compiler.Variable[] getValueOfParameters(string trimmedPara, Compiler.Function calledFunction, int lineNumber, Compiler.Scope currentScope) { string[] words = Compiler.WordParser.parseWords(trimmedPara); if (words.Length != 0) { Compiler.Logic[] logicOrder = WordLogic.determineLogicFromWords(words, lineNumber, currentScope); List <List <Compiler.Logic> > packedLogics = convertIntoParameterLogic(words, logicOrder, lineNumber); if (packedLogics != null) { Compiler.Variable[] inputVariables = new Compiler.Variable[packedLogics.Count]; for (int i = 0; i < packedLogics.Count; i++) { inputVariables [i] = SumParser.parseIntoSum(packedLogics [i].ToArray(), lineNumber, currentScope); } foreach (Compiler.Variable v in inputVariables) { if (v.variableType == Compiler.VariableTypes.unkown) { ErrorMessage.sendErrorMessage(lineNumber, "one or several of the input parameters to function: " + calledFunction.name + " are corrupt!"); } } if (calledFunction.inputParameters.Contains(inputVariables.Length)) { return(inputVariables); } } } return(new Compiler.Variable[0]); }
public static Logic parseReturnStatement(Logic[] logicOrder, int lineNumber, Scope currentScope) { if (logicOrder.Length <= 1) { } Variable returnSum; if (logicOrder.Length <= 1) { // Should return None if there is no sum to return returnSum = new Variable(); //This error should not exist ErrorMessage.sendErrorMessage(lineNumber, "I detta moment måste du returnera något ur funktionen"); } else { Logic[] followOrder = InternalParseFunctions.getSubArray(logicOrder, 1, logicOrder.Length - 1, lineNumber); returnSum = SumParser.parseIntoSum(followOrder, lineNumber, currentScope); } ReturnStatement theReturn = (logicOrder [0] as ReturnStatement); theReturn.findFunctionParent(currentScope, lineNumber); CodeLine parentLine = theReturn.FunctionParent.parentScope.codeLines [theReturn.FunctionParent.parentScope.lastReadLine]; ReturnMemoryControll.insertReturnValue(parentLine, lineNumber, returnSum); currentScope.isReturning = true; CodeWalker.setReturnTarget(theReturn.FunctionParent.parentScope); return(logicOrder [0] as ReturnStatement); }
public static bool parseExpression(Logic[] logicOrder, int lineNumber, Scope currentScope) { #region findOperators int operatorLow = -1; int operatorHigh = -1; int operatorAmount = 0; for (int i = 0; i < logicOrder.Length; i++) { if (isStatementOperator(logicOrder [i])) { if (operatorLow == -1) { operatorLow = i; } else { operatorHigh = i; } operatorAmount++; } } #endregion if (operatorAmount > 2 && operatorHigh - operatorLow != 1) { ErrorMessage.sendErrorMessage(lineNumber, "I detta moment är det inte tillåtet att gör flera jämförelser direkt efter varandra. Använd \"and\" och \"or\" istället."); } if (operatorAmount == 0) { return(handleOnlyValueStatement(logicOrder, lineNumber, currentScope)); } if (operatorAmount == 2) { if (operatorHigh - operatorLow != 1) { ErrorMessage.sendErrorMessage(lineNumber, "Operatorerna måste komma direkt efter varandra"); } } else { operatorHigh = operatorLow; } Logic[] leftSide = new Logic[operatorLow]; Logic[] rightSide = new Logic[logicOrder.Length - 1 - operatorHigh]; Logic[] operators = new Logic[operatorAmount]; setSidesOfStatement(logicOrder, leftSide, rightSide, operators, operatorLow, operatorHigh); Variable firstSum = SumParser.parseIntoSum(leftSide, lineNumber, currentScope); Variable secondSum = SumParser.parseIntoSum(rightSide, lineNumber, currentScope); ComparisonType operatorType = ComparisonOperatorParser.parseOperators(operators); if (operatorType == ComparisonType.unknown) { if (operators[0].currentType == WordTypes.equalSign) { ErrorMessage.sendErrorMessage(lineNumber, "Fel vid tilldelning. Kom ihåg att använda == om du vill jämföra om två värden är lika."); } else { ErrorMessage.sendErrorMessage(lineNumber, "Operatorerna går inte att tyda"); } } if (firstSum.variableType == VariableTypes.unknown || secondSum.variableType == VariableTypes.unknown) { ErrorMessage.sendErrorMessage(lineNumber, "Korrupt värde"); } if (firstSum.variableType != secondSum.variableType) { var firstSumType = SumParser.TypeToString(firstSum.variableType); var secondSumType = SumParser.TypeToString(secondSum.variableType); string errorMessage; if (firstSumType == "" || secondSumType == "") { errorMessage = "Misslyckades med att jämföra " + firstSum.variableType + " med " + secondSum.variableType; } else { errorMessage = "Kan inte jämföra " + firstSumType + " med " + secondSumType + "."; } ErrorMessage.sendErrorMessage(lineNumber, errorMessage); } if (ComparisonOperatorParser.checkSumsToOperator(firstSum.variableType, operatorType, lineNumber)) { bool resultOfComparison = ComparisonOperatorParser.makeComparison(firstSum, secondSum, operatorType, lineNumber); return(resultOfComparison); } ErrorMessage.sendErrorMessage(lineNumber, "Korrupt expression!"); return(false); }