Esempio n. 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);
        }
Esempio n. 2
0
        public DisjunctiveNormalForm(TruthTable truthTable, SimplifiedTruthTable simplifiedTruthTable)
        {
            this._inpuTruthTable            = truthTable;
            this._inputSimplifiedTruthTable = simplifiedTruthTable;

            //initialize the disjunctive form formulas list
            _disjunctiveFormFormulas = new List <string>();
            //initialize the prefix notation of the disjunctive form in the Truth table
            DisjunctiveNormalFormPrefix = string.Empty;
            //initialize the infix notation of the disjuctive form in the Truth table
            DisjunctiveNormalFormInfix = string.Empty;
            //initialize the prefix notation of the disjunctive form in the Simplified Truth table
            SimpDisjunctiveNormalFormPrefix = string.Empty;
            //initialize the infix notation of the disjuctive form in the Simplified Truth table
            SimpDisjunctiveNormalFormInfix = string.Empty;
        }
Esempio n. 3
0
        //show the simplified truth table
        private void ShowSimplifiedTfTable(SimplifiedTruthTable table)
        {
            //create the truth table based on the generated tree
            table.CreateSimplifiedTruthTable();

            listBox_Simplified_TfTable.Items.Clear();

            //add the column names to the list box

            listBox_Simplified_TfTable.Items.Add(table.SimpColumnNames);

            //add the rows to the list box
            foreach (var r in table.SimpRows)
            {
                listBox_Simplified_TfTable.Items.Add(r);
            }
        }