public static BoolAlgebraWord[] parseIntoBoolAlgebra(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            List <BoolAlgebraWord> algebraList = new List <BoolAlgebraWord> ();

            int lastOperatorPos = -1;

            for (int i = 0; i < logicOrder.Length; i++)
            {
                if (logicOrder [i] is AndOrOperator)
                {
                    Logic[] partStatement = InternalParseFunctions.getSubArray(logicOrder, lastOperatorPos + 1, i - 1, lineNumber);

                    bool tempResult = StatementParser.parseExpression(partStatement, lineNumber, currentScope);
                    algebraList.Add(new BoolAlgebraWord(tempResult.ToString()));
                    algebraList.Add(new BoolAlgebraWord(logicOrder [i].word));

                    lastOperatorPos = i;
                }
            }


            Logic[] finalStatement = InternalParseFunctions.getSubArray(logicOrder, lastOperatorPos + 1, logicOrder.Length - 1, lineNumber);
            bool    finalResult    = StatementParser.parseExpression(finalStatement, lineNumber, currentScope);

            algebraList.Add(new BoolAlgebraWord(finalResult.ToString()));

            return(algebraList.ToArray());
        }
Example #2
0
        private static Logic[] splitAtAndOr(Logic[] logicOrder, int lineNumber)
        {
            if (hasAndOr(logicOrder, lineNumber) == false)
            {
                return new Logic[1] {
                           new Package(logicOrder, lineNumber)
                }
            }
            ;

            List <Logic> compressedOrder = new List <Logic> ();
            int          lastFound       = 0;

            for (int i = 0; i < logicOrder.Length; i++)
            {
                if (logicOrder [i] is AndOrOperator)
                {
                    if (i == 0 || i == logicOrder.Length - 1)
                    {
                        ErrorMessage.sendErrorMessage(lineNumber, "Kan inte börja eller sluta med And/Or");
                    }

                    Logic[] subArray = InternalParseFunctions.getSubArray(logicOrder, lastFound, i - 1, lineNumber);
                    compressedOrder.Add(new Package(subArray, lineNumber));

                    if (logicOrder [i + 1] is AndOrOperator)
                    {
                        ErrorMessage.sendErrorMessage(lineNumber, "Kan inte ha 2 And/Or direkt efter varandra");
                    }

                    lastFound = i + 1;
                    compressedOrder.Add(logicOrder [i]);
                }
            }
            Logic[] endArray = InternalParseFunctions.getSubArray(logicOrder, lastFound, logicOrder.Length - 1, lineNumber);
            compressedOrder.Add(new Package(endArray, lineNumber));


            return(compressedOrder.ToArray());
        }
    }
        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);
        }
Example #4
0
        public static Logic parseStatement(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            if (logicOrder.Length < 3)
            {
                ErrorMessage.sendErrorMessage(lineNumber, ErrorType.IfStatements, IfErrorType.unknownFormat.ToString(), null);
            }

            if (logicOrder [logicOrder.Length - 1].currentType != WordTypes.indentOperator)
            {
                ErrorMessage.sendErrorMessage(lineNumber, ErrorType.IfStatements, IfErrorType.missingIndentOperator.ToString(), null);
            }


            Logic[] statementLogic = InternalParseFunctions.getSubArray(logicOrder, 1, logicOrder.Length - 2, lineNumber);
            (logicOrder [0] as ScopeStarter).doEnterScope = StatementParser.parseAndCheckStatement(statementLogic, lineNumber, currentScope);
            (logicOrder [0] as ComparisonScope).initNextstatement();

            if (logicOrder[0] is IfStatement)
            {
                return(logicOrder[0] as IfStatement);
            }

            return(logicOrder[0] as ElifStatement);
        }