public int eval() { if (ifcanaddoperand()) { return(2); } List <IBooleanElement> scop = s; bool ans = false; IBooleanElement lastoperand = null; for (int i = 0; i < scop.Count; i++) { if (scop[i].GetType() == typeof(BooleanOperatorNot)) { if (scop[i + 1].GetType() == typeof(BooleanOperandTrue)) { scop[i + 1] = new BooleanOperandFalse(); } else { scop[i + 1] = new BooleanOperandTrue(); } } if (scop[i].GetType().IsSubclassOf(typeof(BooleanOperand)) || typeof(BooleanOperand) == scop[i].GetType()) { if (lastoperand == null) { ans = scop[i].GetType() == typeof(BooleanOperandTrue); } else { if (lastoperand.GetType() == typeof(BooleanOperatorAnd)) { ans = ans && scop[i].GetType() == typeof(BooleanOperandTrue); } if (lastoperand.GetType() == typeof(BooleanOperatorOr)) { ans = ans || scop[i].GetType() == typeof(BooleanOperandTrue); } if (lastoperand.GetType() == typeof(BooleanOperatorXor)) { ans = ans ^ scop[i].GetType() == typeof(BooleanOperandTrue); } lastoperand = null; } } else { lastoperand = scop[i]; } } if (ans) { return(1); } return(0); }
public void Add(IBooleanElement x) { s.Add(x); }