/** * Interface for boolean operators of Propositional Logic. The required methods * are to provide a string representation of a proposition, to verify that a * proposition is well formed, and to return the precedence of the operation. * The first method supplies a string representation of a proposition formed by * applying the operator to an array containing its operands. The whole term * will be enclosed in brackets if the precedence of the operator is greater * than parameter prec; this parameter can be thought of as the * precedence of the operator immediately above this proposition, forcing it to * be put in brackets if necessary. The second method returns true if the term * is well formed; otherwise, it returns false. The third method simply returns * the integer that is its precedence. * */ public interface Operator { /** * Give a string representing a proposition with no unnecessary brackets. * The proposition will be formed by applying this operator to the given * operands, and the entire term will be enclosed in brackets if the * precedence of the operator is greater than parameter prec; * * @param args * the operands; e.g., for "and": this array should be of length * 2 * @param prec * the precedence of the operator above. * @return a string representing the proposition formed by applying the * operator to the operands in args; the entire string * will be enclosed in brackets if parameter prec is * less than the operator's precedence. */ public String toString(BoolTerm[] args, int prec); /** * Checks if the number of subterms of the proposition matches the expected * number of subterms for this operator; for example, a not * operator would only need an array of subterms of size 1, whereas an * or operator would need an array of subterms of size 2. * * @return true if the term is well formed; otherwise, * false. */ public boolean isWellFormed(BoolTerm[] args); /** * Return the precedence of the operator. The order of precedences of all Boolean * operators are specified in the Lectures and they are: * IMPLIES_PREC > OR_PREC > AND_PREC > NOT_PREC. * * This program uses: * IMPLIES_PREC = 7; * OR_PREC = 5; * AND_PREC = 4; * NOT_PREC = 1; * * @return the precedence of the operator */ public int getPrecedence(); }// Operator