i need help in evaluation of logical clauses(DNF and CNF) using c++.
wat i wan is :
user input a logical clauses as in DNF, then i have to convert it to CNF. and the truth table for both dnf n cnf has to be evaluated.
input is !(A&&!B) , then i will get !A||B as the conversion result, and a truth table evaluating all the true n false with regard to A and B.
A B !(A&&!B) !A||B
1 1 1 1
1 0 0 0
0 1 1 1
0 0 1 1
i was thinking of getting user input as a line of string but then i do not know wat to do next.perhaps further dissecting the string into smallest component and then evaluate one by one and join them ?
such as !(A&&!B) , i break it down into evaluate A first, then !B, and then (A AND !B), finaly evaluate !(A AND B)?
this works for simple clauses. to deal with complicated clauses, a lot of conditions which might seem tedious to do.
i do not require reply of whole programming code,but a reference would be great. Pls suggest any functions n syntaxes which u think are relavent.
thx for ur help.
1. Get line in memory
2. Read characters until a space or an operator
3. If you have found a variable (operand), store its name
4. If you have found an operator, call a function handling that operation
You have unary operations (! not) and binary operations (&& and, || or). You can also have parentheses.
You can build a stack and use a Reverse Polish algorithm.
Or you can have a recursive approach.