private static bool returnCheck(Logic[] logicOrder, int lineNumber) { if (logicOrder.Length < 2) { ErrorMessage.sendErrorMessage(lineNumber, "Du måste returnera något"); } ValidSumCheck.checkIfValidSum((InternalParseFunctions.getSubArray(logicOrder, 1, logicOrder.Length - 1, lineNumber)), lineNumber); return(true); }
internal static bool checkForVariableDecleration(Logic[] logicOrder, int lineNumber) { if (logicOrder.Length < 3) { return(false); } if (logicOrder [0].currentType != WordTypes.variable) { return(false); } int equalPos = 0; for (int i = 0; i < logicOrder.Length; i++, equalPos++) { if (logicOrder [i].currentType == WordTypes.equalSign) { break; } } if (equalPos != 1 && equalPos != 2) { return(false); } if (equalPos == 2 && logicOrder [1].currentType != WordTypes.mathOperator) { ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "Du kan bara ha matte operatorer i special deklareringar!"); } Logic[] afterEqualSign = new Logic[logicOrder.Length - (equalPos + 1)]; for (int i = equalPos + 1; i < logicOrder.Length; i++) { afterEqualSign [i - (equalPos + 1)] = logicOrder [i]; } ValidSumCheck.checkIfValidSum(afterEqualSign, lineNumber); return(true); }
internal static bool validPartStatement(Logic[] logicOrder, int lineNumber) { #region findOperators int operatorLow = 0; int operatorHigh = 0; int operatorAmount = 0; for (int i = 0; i < logicOrder.Length; i++) { if (isStatementOperator(logicOrder [i])) { if (operatorLow == 0) { operatorLow = i; } else { operatorHigh = i; } operatorAmount++; } } #endregion if (operatorAmount > 2) { ErrorMessage.sendErrorMessage(lineNumber, "Operatorerna i ditt expression går inte att tyda"); } if (operatorAmount == 0) { return(true); } if (operatorAmount == 2) { if (operatorHigh - operatorLow != 1) { ErrorMessage.sendErrorMessage(lineNumber, "Operatorerna måste komma 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); ComparisonType operatorType = ComparisonOperatorParser.parseOperators(operators); if (operatorType == ComparisonType.unknown) { ErrorMessage.sendErrorMessage(lineNumber, "Operatorerna går inte att tyda"); } ValidSumCheck.checkIfValidSum(leftSide, lineNumber); ValidSumCheck.checkIfValidSum(rightSide, lineNumber); return(true); }