Add _true, _false, ==, and _if..._then..._else to your MSD script implementation.

Some details on the forms:

As an example, the MSDscript program

_let same = 1 == 2
_in _if 1 == 2
_then _false + 5
_else 88

should interp to the value 88, and it should not complain about false being added to 5.

The example

_if 4 + 1
_then 2
_else 3

does not have a value; interpreting it should raise an exception, because 5 is not a boolean.

 

This is a big change to your MSDscript code base, involving a lot of method and function definitions and well as tests. Fortunately, with the possible exception of pretty printing (see further below), the changes should be straightforward; they follow recipes and patterns that we've used already.

You should break down this big change into manageable steps, and here are some suggested steps:

  1. Add a new Val class to represent boolean values. You can implement and test the new class without changing anything else about your MSDcript implementation, except that you can't complete a to_expr method to convert a value back to an expression (because you haven't added boolean expressions, yet). For to_expr, just return NULL and save it for testing later — but make sure you have good test coverage for the new code otherwise.
  2. Add new Expr classes for booleans, equality expressions, and conditionals. Add one class at a time, and get back to good test coverage before writing more. Save pretty printing for last, perhaps just using print as the operation temporarily.
  3. Change your parser to recognize the new forms. Again, you can add them one at a time and test along the way.
  4. After you're finished, consider updating your random tester to try to new language forms.

Here are some observations and advice on pretty-print with the expanded language: