Beispiel #1
0
        public formattedCodeView getFormattedProgram()
        {
            formattedCodeView formattedProgram = new formattedCodeView();

            CommonAST walker = BoolProgramAst;

            while ((walker != null) && (walker.Type == BoolParserTokenTypes.LITERAL_decl))
            {
                formattedProgram.addLine(HelperFunctions.DeclToString(walker));

                walker = (CommonAST)walker.getNextSibling();
            }

            formattedProgram.addLine("");

            while ((walker != null) && (walker.Type == BoolParserTokenTypes.PROC))
            {
                formattedProgram = getFormattedProcedure(walker, formattedProgram);

                formattedProgram.addLine("");

                walker = (CommonAST)walker.getNextSibling();
            }

            return(formattedProgram);
        }
Beispiel #2
0
        private formattedCodeView getFormattedSSEQ(CommonAST sseq, formattedCodeView formattedCode, string tab)
        {
            CommonAST walker = (CommonAST)sseq.getFirstChild();

            while (walker != null)
            {
                CommonAST statement;
                if (walker.Type == BoolParserTokenTypes.STMT)
                {
                    statement = (CommonAST)walker.getFirstChild();
                }
                else
                {
                    statement = (CommonAST)walker.getFirstChild().getNextSibling();
                }

                CFGNode stmtNode;
                if (AstToCfgMapping.TryGetValue(walker, out stmtNode))
                {
                    if ((stmtNode is CFGNodeStmtIf) || (stmtNode is CFGNodeStmtWhile))
                    {
                        if (stmtNode is CFGNodeStmtIf)
                        {
                            string line = tab + stmtNode.ToString() + " then";
                            formattedCode.addLine(line, stmtNode);

                            statement     = (CommonAST)statement.getFirstChild().getNextSibling();
                            formattedCode = getFormattedSSEQ(statement, formattedCode, tab + "  ");

                            formattedCode.addLine(tab + "else");

                            statement     = (CommonAST)statement.getNextSibling();
                            formattedCode = getFormattedSSEQ(statement, formattedCode, tab + "  ");

                            formattedCode.addLine(tab + "fi");
                        }
                        else
                        {
                            formattedCode.addLine(tab + stmtNode.ToString(), stmtNode);
                            formattedCode.addLine(tab + "do");

                            statement     = (CommonAST)statement.getFirstChild().getNextSibling();
                            formattedCode = getFormattedSSEQ(statement, formattedCode, tab + "  ");

                            formattedCode.addLine(tab + "od");
                        }
                    }
                    else
                    {
                        formattedCode.addLine(tab + stmtNode.ToString(), stmtNode);
                    }
                }

                walker = (CommonAST)walker.getNextSibling();
            }

            return(formattedCode);
        }
Beispiel #3
0
        private formattedCodeView getFormattedProcedure(CommonAST procedure, formattedCodeView formattedCode)
        {
            CommonAST walker = (CommonAST)procedure.getFirstChild();

            string procedureHead = string.Empty;

            procedureHead += walker.getText() + "(";
            walker         = (CommonAST)walker.getFirstChild();

            bool first = true;

            while (walker.Type == BoolParserTokenTypes.ID)
            {
                if (!first)
                {
                    procedureHead += ", ";
                }
                procedureHead += walker.getText();

                walker = (CommonAST)walker.getNextSibling();
                first  = false;
            }
            procedureHead += ")";

            formattedCode.addLine(procedureHead);
            formattedCode.addLine("begin");

            while (walker.Type == BoolParserTokenTypes.LITERAL_decl)
            {
                formattedCode.addLine("  " + HelperFunctions.DeclToString(walker));

                walker = (CommonAST)walker.getNextSibling();
            }

            formattedCode = getFormattedSSEQ(walker, formattedCode, "  ");

            formattedCode.addLine("end");

            return(formattedCode);
        }
Beispiel #4
0
        private void buttonTrajectory_Click(object sender, EventArgs e)
        {
            if (MyBMC.isLabelValid(labelsComboBox.Text))
            {
                BooleanModelChecker.ControlFlowGraph.formattedCodeView formattedCode = MyBMC.getFormattedCode();

                TrajectoryViewForm.codeView.Clear();
                TrajectoryViewForm.codeView.AppendText(formattedCode.getProgramTextNumbered());

                Trajectory labelTrajectory = MyBMC.BuildTrajectory(MyBMC.GetLabeledCFGNode(labelsComboBox.Text));

                TrajectoryViewForm.trajectorDescription.Clear();
                TrajectoryViewForm.trajectorDescription.AppendText("Trajectory printed with matching line numbers:\n\n");
                TrajectoryViewForm.trajectorDescription.
                AppendText(Trajectory.getTrajectoryPrintout(labelTrajectory, formattedCode.nodeToLine, MyBMC.BddToName));

                TrajectoryViewForm.Show();
                TrajectoryViewForm.WindowState = FormWindowState.Normal;
            }
            else
            {
                labelsComboBox.Text = "Invalid Label Selected!";
            }
        }