Syntactic theory of mathematical expressions