private static Variable handleNumberVariable(Logic[] cloneLogicOrder, int lineNumber, Variable tempSum, Scope currentScope) { Logic[] calcSum = new Logic[3]; calcSum [0] = cloneLogicOrder [0]; calcSum [1] = cloneLogicOrder [1]; calcSum [2] = new NumberValue(tempSum.getNumber().ToString()); Variable tempVar = SumParser.parseIntoSum(calcSum, lineNumber, currentScope); tempVar.name = (calcSum [0] as Variable).name; return(tempVar); }
public static Logic checkForVariableDecleration(Logic[] logicOrder, int lineNumber, Scope currentScope) { //We use a shallow copy because we alter logicOrder in case of speciall operators Logic[] cloneLogicOrder = (Logic[])logicOrder.Clone(); if (couldBeVariableDec(cloneLogicOrder, lineNumber) == false) { return(new UnknownLogic(lineNumber)); } Logic[] afterEqualSign = getAfterEqualSign(cloneLogicOrder, lineNumber, currentScope); if (afterEqualSign == null || afterEqualSign.Length == 0) { return(new UnknownLogic(lineNumber)); } Variable afterEqualSignSum = SumParser.parseIntoSum(afterEqualSign, lineNumber, currentScope); //Determine whether to use speciallOperators or not if (cloneLogicOrder [1].currentType != WordTypes.equalSign) { afterEqualSignSum = SpeciallVariableDeclareParser.speciallVariableDeclare(cloneLogicOrder, lineNumber, afterEqualSignSum, currentScope); } else { afterEqualSignSum.name = (cloneLogicOrder[0] as Variable).name; } //Add the newly declared variable if (afterEqualSignSum.variableType != VariableTypes.unknown) { currentScope.scopeVariables.addVariable(afterEqualSignSum, currentScope.scopeParser, lineNumber); return(afterEqualSignSum); } ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "Något gick fel i variabeldeklareringen"); return(new UnknownLogic(lineNumber)); }