The macro processor detects macro triggers like % and & in the code and handles macro code and variable substitution. It stores macro variables and their values in a symbol table. When it detects a macro variable reference &variable, it looks up the variable name in the symbol table and substitutes the variable value into the code before passing it to the compiler. This allows macros to generate dynamic code with variable data.