The \trap:base is to catch empty bases of exponents like, e.g., in $a^{^b}$.
The \MathRow requests a <|.mrow\Hnewline>...</|.mrow>, instead of the contributions of \mathop, \mathrel,...., for the next parameter.
Definitions like \def\mathbf#1{\a:mathbf#1\b:mathbf} can’t be done on a global level, because \mathbf is just a name of a font. So, for instance, \bf expands to \mathbf, and so $\bf R$ indirectly brings up the latter command.
The default \left and \right in their default definition with tex produce multi-part delimiters, from cmex, on large subformulas. Hence, the ‘’.’ below is needed.
The \HCode{} in \sideset is for catching superscripts and subscripts