int main () { // example expression: (true and x) or (y and (not x)) BooleanExp* expression; Context context; VariableExp* x = new VariableExp("X"); VariableExp* y = new VariableExp("Y"); expression = new OrExp(new AndExp(new Constant(true), x), new AndExp(y, new NotExp(x))); context.Assign(x, false); context.Assign(y, true); bool result = expression->Evaluate(context); VariableExp* z = new VariableExp("Z"); NotExp not_z(z); BooleanExp* replacement = expression->Replace("Y", not_z); context.Assign(z, true); result = replacement->Evaluate(context); return 0; }
main () { /* */ BooleanExp* expression; Context context; VariableExp* x = new VariableExp("X"); VariableExp* y = new VariableExp("Y"); expression = new OrExp( new AndExp(new Constant(true), x), new AndExp(y, new NotExp(x)) ); /* */ context.Assign(x, false); context.Assign(y, true); bool result = expression->Evaluate(context); /* */ BooleanExp* replacement; VariableExp* z = new VariableExp("Z"); replacement = new NotExp(z); expression->Replace("Y", *replacement); context.Assign(z, true); result = expression ->Evaluate(context); /* */ }
BooleanExp* AndExp::Replace (const char* name, BooleanExp& exp) { return new AndExp( _operand1->Replace(name, exp), _operand2->Replace(name, exp) ); }
int main(int argc, char ** argv) { BooleanExp *expression; Context context; VariableExp* x = new VariableExp("X"); VariableExp* y = new VariableExp("Y"); expression = new OrExp( new AndExp(new Constant(true),x), new AndExp(y,new NotExp(x))); context.Assign(x,false); context.Assign(y,true); bool result = expression->Evaluate(context); char *str; if(result == true) str = "true"; else str = "false"; printf("result is %s\n",str); system("pause"); return 0; }
BooleanExp* AndExp::Copy () const { return new AndExp(_operand1->Copy(), _operand2->Copy()); }
bool AndExp::Evaluate (Context& aContext) { return _operand1->Evaluate(aContext) && _operand2->Evaluate(aContext); }