Checking the Semantics Semantic checking is done to make sure that not only the syntax of the program is correct, but the statements also make sense. The number of parameters supplied to a function, for example, should be the number this function expects. This is called a coercion. In our sample compiler I've only allowed bool to string coercion, but you could easily add string to bool coercion if you think that's useful. The code for our semantic checker is not complicated.
Check sets a new member variable called rettype, the 'return type' of the expression.
A condition, for example, has boolean as its return type, while a string concatenation returns another string. Rettype is used to check the semantics of the parent node. For a simple compiler this is easy, but generally it's not. So yes, in this case it's simple, and it's a useful learning experience to try to expand this system with some more types, but at some point you'll want to take a more general approach. The rest of the code pretty much explains itself.