Start by adding the Expr
classes from the lecture slides into your project. You can put all declarations in "expr.h" and all implementations in an “expr.cpp” file, or you can have separate files for each class; it just depends on how much you prefer to split things into different files. Note that you need to break up the code on the slide into declaration and implementation parts, even if you use a single "expr.h" and "expr.cpp".
Implement the equals
method of Expr
in each subclass. Write tests to make sure that your equals
implementations work.
Change your command-line handler from the first assignment so that passing "--test"
causes all tests to be run. If "--test"
is not provided, then your tests should not run. When running tests, if Catch::Session().run
returns a non-0 value, then exit immediately with exit(1)
.
Finally, add a new kind of expression: variables. In the same way that a number expression can be represented with a number field, a variable expression can be represented by string. That is, the new abstract grammar of expressions is
<expr> = <number>
| <expr> + <expr>
| <expr> * <expr>
| <variable>
Be sure to implement equals
for the new variable class and have tests for it.