Example #1
0
        //show the nand value of the proposition tree
        private void ShowNand(NandProposition nandProposition)
        {
            //set the nand value
            nandProposition.SetNandString(nandProposition.GetInputTree());
            //check whether the value is too long to show
            var nandLength = nandProposition.GetNandString().Length;

            tb_NAND.Text = nandLength <= 200 ? nandProposition.GetNandString() : "The length of the NANDs is larger than 200, unable to show in the text box.";
        }
Example #2
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);
        }