Grammar types constraint after adding a couple of types (and a statement involving them) to a "typeless" language
There is no way to express that constraint with a context-free grammar. (It is, almost by definition, context-sensitive since the validity of z @ … depends on the presence of underlying z.)

So you are left with two choices:


Perform the validity check as a semantic action.
Modify the lexical scanner's categorization of tokens on the fly, by recategorizing z after underlying z is seen.


Option 2 is usually called the "lexical feedback hack" and that is precisely what it is. Sometimes it cannot be conveniently avoided, but this is not one of them.