The Algebraic Structure of Morphosyntax