symbols: move unique code into a mixin template so it can be used elsewhere.
Used mixin template rather than a class as that would cause all inheritors
to share the same next_id and hence the same numeric series.

Signed-off-by: Peter Williams <pwil3058@gmail.com>
grammar: split grammar items into two parts and use associative array for sets
of grammar items as it will better suit the algorithms to come.

Signed-off-by: Peter Williams <pwil3058@gmail.com>