Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

  • Print
  • + Share This
Like this article? We recommend

Running the Code

Figure 2 shows the debug output from running the program.

Figure 2

Figure 2 Debug output.

The Figure 2 output is produced by a few calls to printf() in the Evaluate() member functions of the classes AndExpression, AndExpression, and NotExpression. As Figure 2 shows, the first AND evaluation takes two true parameters to produce true. The NOT evaluation takes a true parameter to produce false. Then, the next AND evaluation takes two false parameters to produce false. After that, the OR expression takes one true and one false parameter to produce true. This gives us the overall result of true (or 1).

Feel free to change the Boolean values assigned to the context in Listing 8. Then just recompile and run the program and you should see the new result. For completeness, Listing 9 provides the Constant class.

Listing 9 The Constant class.

class Constant : public BooleanExpression
{
public:
  explicit Constant(bool);
  virtual ~Constant();

  virtual bool Evaluate(Context&);

private:
  bool _operand1;
};

The Constant class follows the model of AndExpression, OrExpression, and NotExpression.

  • + Share This
  • 🔖 Save To Your Account