NULL pointer constant

How are we supposed to implement the NULL pointer constant? I added a rule to the variable evaluation for this, but I’m not sure: Are we were supposed to add it as a separate constant (base) expression?

One way is to add a function to the constant expression classes (char and int) to check whether their value is 0. (@Tutor is a char constant with value 0 also a null pointer constant? The specification says “integer constant with value 0”)

The only problem with this is, that something like 0 + 0 will not be regarded as a null pointer constant. But I think this is out of scope for this project. (Since constant folding is an optional task)

The null pointer constant is exactly Const_0. Adding a method isNullPointer() makes a lot of sense.

Remember that “null pointer” is not a type but an expression.

Good question. The C standard just says (in 6.3.2.3p3) that

An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.

This references integer constant expression, which are constrained such that it includes expressions which must be evaluable during compile time. Having your type checker evaluate things is a weird decision, and so we do not force you to implement it.

We however do not test whether 0+0 is rejected as a non-(null pointer). So you can implement it if you want, but I recommend you do not.

Your optimizer should never affect the results of your type checker. So whether or not constant folding happens should not matter for detecting integer constant expressions.