Numbering of tokens inside Happy:
epsilon = 0
error = 1
dummy = 2
%start = 3..s
non-terminals = s..n
terminals = n..m
%eof = m
where n_nonterminals = n - 3 (including %starts)
n_terminals = 1{-error-} + (m-n) + 1{-eof-} (including error and %eof)
In normal and GHC-based parsers, these numbers are also used in the
generated grammar itself, except that the error token is mapped to -1.
In an array-based parser, things are a little different.
-----------------------------------------------------------------------------
Action Table
We have an action table, indexed by states in the y direction, and
terminal number in the x direction. ie. action = (state * n_terminals +
terminal). The terminal number is given by (for terminals only):
tok_number - n_nonterminals - 3
so we have
error = 0
terminals = 1..n
%eof = n+1
-----------------------------------------------------------------------------
Goto Table
The goto table is indexed by nonterminal number (without %starts), ie
(state * (n_nonterminals-s)) + tok_number - s