예제 #1
0
        private void BuildElse(string[] sourceCodeLines, ref int i, ref GNode currentPreviousNode, ref GNode actualNode, ref ProcedureCfg actualCfgStructure, ref int programLineNumber, ref int howManyStatementsEnd)
        {
            string[] lineWords;

            for (++i; i < sourceCodeLines.Length; i++)
            {
                lineWords = sourceCodeLines[i].Split(' ');

                switch (lineWords[0])
                {
                case "while":
                {
                    BuildWhile(sourceCodeLines, ref i, ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber, ref howManyStatementsEnd);
                    if (howManyStatementsEnd > 0)
                    {
                        --howManyStatementsEnd;
                        return;
                    }
                }
                break;

                case "if":
                {
                    BuildIf(sourceCodeLines, ref i, ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber, ref howManyStatementsEnd);

                    if (howManyStatementsEnd > 0)
                    {
                        --howManyStatementsEnd;
                        return;
                    }
                }
                break;

                default:
                {
                    BuildAssignCall(ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber);

                    if (EndOfStatement(lineWords, ref howManyStatementsEnd))
                    {
                        --howManyStatementsEnd;
                        return;
                    }
                }
                break;
                }
            }
        }
예제 #2
0
        private void BuildWhile(string[] sourceCodeLines, ref int i, ref GNode currentPreviousNode, ref GNode actualNode, ref ProcedureCfg actualCfgStructure, ref int programLineNumber, ref int howManyStatementsEnd)
        {
            string[] lineWords;
            GNode    whileNodeMain;

            #region create node for while and remember it
            currentPreviousNode = actualNode;

            actualNode = new GNode(GNodeTypeEnum.While, ++programLineNumber, actualCfgStructure.GNodeList.Count());
            actualCfgStructure.GNodeList.Add(actualNode);

            //zapamietaj
            whileNodeMain = actualNode;

            if (currentPreviousNode != null)
            {
                currentPreviousNode.nextGNodeList.Add(actualNode);
                actualNode.previousGNodeList.Add(currentPreviousNode);
            }
            currentPreviousNode = actualNode;
            #endregion

            for (++i; i < sourceCodeLines.Length; i++)
            {
                lineWords = sourceCodeLines[i].Split(' ');

                switch (lineWords[0])
                {
                case "while":
                {
                    BuildWhile(sourceCodeLines, ref i, ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber, ref howManyStatementsEnd);
                    if (howManyStatementsEnd > 0)
                    {
                        CloseWhileLoop(ref whileNodeMain, ref actualNode, ref currentPreviousNode, ref howManyStatementsEnd);
                        return;
                    }
                }
                break;

                case "if":
                {
                    BuildIf(sourceCodeLines, ref i, ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber, ref howManyStatementsEnd);
                    if (howManyStatementsEnd > 0)
                    {
                        CloseWhileLoop(ref whileNodeMain, ref actualNode, ref currentPreviousNode, ref howManyStatementsEnd);
                        return;
                    }
                }
                break;

                default:
                {
                    BuildAssignCall(ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber);

                    if (EndOfStatement(lineWords, ref howManyStatementsEnd))
                    {
                        CloseWhileLoop(ref whileNodeMain, ref actualNode, ref currentPreviousNode, ref howManyStatementsEnd);
                        return;
                    }
                }
                break;
                }
            }
        }
예제 #3
0
        private void BuildIf(string[] sourceCodeLines, ref int i, ref GNode currentPreviousNode, ref GNode actualNode, ref ProcedureCfg actualCfgStructure, ref int programLineNumber, ref int howManyStatementsEnd)
        {
            string[] lineWords;
            GNode    ifNodeMain, endNodeThenSection = null, ghostNode;

            #region create node for if and remember this node and endNodeThenSection
            currentPreviousNode = actualNode;

            actualNode = new GNode(GNodeTypeEnum.If, ++programLineNumber, actualCfgStructure.GNodeList.Count());
            actualCfgStructure.GNodeList.Add(actualNode);

            // zapamietaj
            ifNodeMain = actualNode;

            if (currentPreviousNode != null)
            {
                currentPreviousNode.nextGNodeList.Add(actualNode);
                actualNode.previousGNodeList.Add(currentPreviousNode);
            }
            #endregion

            for (++i; i < sourceCodeLines.Length; i++)
            {
                lineWords = sourceCodeLines[i].Split(' ');

                switch (lineWords[0])
                {
                case "else":
                {
                    BuildElse(sourceCodeLines, ref i, ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber, ref howManyStatementsEnd);

                    ghostNode = new GNode(GNodeTypeEnum.Ghost, actualCfgStructure.GNodeList.Count());
                    actualCfgStructure.GNodeList.Add(ghostNode);

                    actualNode.nextGNodeList.Add(ghostNode);
                    endNodeThenSection.nextGNodeList.Add(ghostNode);

                    ghostNode.previousGNodeList.Add(actualNode);
                    ghostNode.previousGNodeList.Add(endNodeThenSection);

                    currentPreviousNode = null;
                    actualNode          = ghostNode;

                    return;
                }
                break;

                case "while":
                {
                    BuildWhile(sourceCodeLines, ref i, ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber, ref howManyStatementsEnd);

                    if (howManyStatementsEnd > 0)         // end of then section
                    {
                        endNodeThenSection = actualNode;
                        actualNode         = ifNodeMain;
                        --howManyStatementsEnd;
                    }
                }
                break;

                case "if":
                {
                    BuildIf(sourceCodeLines, ref i, ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber, ref howManyStatementsEnd);


                    if (howManyStatementsEnd > 0)         // end of then section
                    {
                        endNodeThenSection = actualNode;
                        actualNode         = ifNodeMain;
                        --howManyStatementsEnd;
                    }
                }
                break;

                default:
                {
                    BuildAssignCall(ref currentPreviousNode, ref actualNode, ref actualCfgStructure, ref programLineNumber);

                    if (EndOfStatement(lineWords, ref howManyStatementsEnd))         // end of then section
                    {
                        endNodeThenSection = actualNode;
                        actualNode         = ifNodeMain;
                        --howManyStatementsEnd;
                    }
                }
                break;
                }
            }
        }