Either build (maybe abstract) syntax trees explicitly, for example, `print 3+(2*f)`, where `f` is a construct outside of the programming language, so usually indicated by not using colors (or a different one) may look like `\xprint[\xcol]{\xadd[\xcol]{\xcol{3}}{\lrpars{\xmul[\xcol]{\xcol{2}}{f}}}}`, or just rely on syntax and define shorthand macros that are locally scoped, like `\xlang{\xprint \n3 + \l( \n2 * f\r)}`.
Both have their pros and cons.