Partial
We could build upon the reflection solution by doing something like:
\require{begingroup}\begingroup \def\C#1#2|{\D#1|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\T} \def\stars#1{\G|#1|} \def\G#1|#2|{\R :#2|\R|\S} \def\R#1:#2#3|#4{#4 #2#1:#3|#4} \def\S|#1:#2\S{\C#1|} \def\T#1{terminate} \stars{123} \endgroup
For \stars{123}:
$$\require{begingroup}\begingroup\def\C#1#2|{\D#1|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\M#2|\T}\def\stars#1{\G|#1|}\def\G#1|#2|{\R :#2|\R|\S}\def\R#1:#2#3|#4{#4 #2#1:#3|#4}\def\S|#1:#2\S{\C#1|}\def\T#1{terminate}\stars{123}\endgroup$$
But I'm not quite sure how to:
- recurse to \C with \M by implementing \T correctly (like \S); or
- make \D3| produce *\D2| and similar for all the digits such that \D| and \D0| yield empty strings.