This is for an assignment. I have to convert the set of statements to CNF and implement them. I know that I need to convert the input in prefix notation it to infix first and then repeatedly apply De Morgans's Laws. However, I don't know how to proceed with the implementation after converting it to infix notation.
Thanks!
There is no need to convert this to infix - you want to get out of the domain of strings as quickly as possible, for example
public abstract class Expression
public abstract class BinaryExpression extends Expression {
private Expression expr1;
private Expression expr2;
public Expression getExpr1() { return expr1; }
public void setExpr1(Expression expr) { expr1 = expr; }
}
public abstract class UnaryExpression extends Expression
public class Or extends BinaryExpression
public class Not extends UnaryExpression
and so on. To parse the input into Expressions
you may find it useful to use a Recursive Descent Parser, although this is certainly not the only way to parse your input. Once you have your input converted to a symbolic Expression
format it should be much easier to apply the boolean laws to convert it to CNF.