Finally, we arrive at the last main component of a parser, the
so-called ``semantic actions''. While the constructive parsing
approach does produce a parse \emph{tree}, it is not usually the case
that this parse tree is \emph{the same} as the desired typed of
ASTs. Instead, we need only that there is a \emph{function} from parse
trees to ASTs. In general this might fail to be injective (such as
forgetting whether parentheses were used) or surjective (if there are
internal compiler forms that do not directly correspond to source
programs).
We can formalize this by noting that there is a functor, the constant
functor $\Delta$ from $\Set$ to $\Set^{\Sigma^*}$ that sends a set $A$
to the constant presheaf $\Delta(A)_w = A$. Then we can take the comma
category $\Set^{\Sigma^*}/K$. The objects of this category are pairs
of a grammar $g$ and a set $A$ with a function
\[ \prod_{w \in \Sigma^*} g_w \to A \]