I am thinking about possibility to parse LaTeX document. What I really need is to track category codes of symbols. As I understand TeX expands all of macros in his mouth and tracks changes of category codes without executing anything. Is it possible to check if the next token is a macro, collect it unexpanded (together with arguments), execute it and move to next token?
It is not clear what you want to do however this detects whether or not the following token is a macro. It distinguishes
Plain TeX example (Change