Example #1
0
 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;
 }
Example #2
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);
/*
*/
}
Example #3
0
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;
}
Example #4
0
bool AndExp::Evaluate (Context& aContext) {
    return
        _operand1->Evaluate(aContext) &&
        _operand2->Evaluate(aContext);
}