Example #1
0
        //parse the input
        private void btn_Parse_Click(object sender, EventArgs e)
        {
            //get the input text
            var input = this.tb_Input.Text;

            //check the input text is valid or not
            if (input == "")
            {
                MessageBox.Show("Please enter a propositon");
                return;
            }
            if (input.Any(c => !System.Text.RegularExpressions.Regex.IsMatch(c.ToString(), "^[a-zA-Z~|&>=(),%]") && c != ' '))
            {
                this.lb_input.Text      = "Invalid input! Hints: only a-z, A-Z, ~, |, &, >, =, (, ), ,, % are valid";
                this.lb_input.ForeColor = Color.Red;
                this.tb_Input.Focus();
                return;
            }
            //reset the text of the hints when the input is valid
            this.lb_input.Text = "";
            //initialize an empty binary tree
            _binaryTree = new BinaryTree();
            //generate the proposition tree
            _binaryTree.IniBinaryTreeByInputString(input);

            //initialize a graph with the generated binary tree
            var graph = new Graph(_binaryTree);

            this.ShowGraphOfTheTree(graph);

            //show the infix notation of the proposition tree
            this.ShowInfix(_binaryTree);

            //show the prefix notation of the proposition tree
            this.ShowPrefix(_binaryTree);

            //initialize a truth table with the generated binary tree
            var tfTable = new TruthTable(_binaryTree);

            this.ShowTfTableAndHashCode(tfTable);

            //initialize a simplified truth table with the generated truth table
            var simpTfTable = new SimplifiedTruthTable(tfTable);

            this.ShowSimplifiedTfTable(simpTfTable);

            //initialize a disjunctive normal form with the generated truth table and the generated simplified truth table
            var dnf = new DisjunctiveNormalForm(tfTable, simpTfTable);

            this.ShowDisjunctiveNormalForm(dnf);

            //initialize a nand value with the generated binary tree
            var nand = new NandProposition(_binaryTree);

            this.ShowNand(nand);
        }
Example #2
0
        //show the disjunctive normal form
        private void ShowDisjunctiveNormalForm(DisjunctiveNormalForm dnf)
        {
            //in truth table
            dnf.GetDisjunctiveNormalForm(false);
            tb_TFDisj_Infix.Text  = dnf.DisjunctiveNormalFormInfix;
            tb_TFDisj_Prefix.Text = dnf.DisjunctiveNormalFormPrefix;

            //in simplified truth table
            dnf.GetDisjunctiveNormalForm(true);
            tb_STFDisj_Infix.Text  = dnf.SimpDisjunctiveNormalFormInfix;
            tb_STFDisj_Prefix.Text = dnf.SimpDisjunctiveNormalFormPrefix;
        }