I'm writing a preprocessor, and I've come across a problem.
If a macro is used in an expansion of itself, it won't be processed. So somehow, I've got to check this in the expansion. This can lead to two models:
1) Total Expansion
The function that expands the macro also fully expands the result of the macros. This way the entire expansion progress can be kept in a single function stack..
2) Gradual Expansion
The function that expands the macro does a basic expansion job, pushes the macro expanded onto what is pretty much a global stack (inside the preprocessor structure), and leaves a token at the end of the expanded macro ordering the preprocessor to pop off a level of nesting.
The gradual expansion might actually be easier to write, but I'd like to know what any experienced coders think about the cleaness and simplicity of each option. Maybe even suggest something else.. I'd like to make it possible to change things without everything blowing up, btw.
So, tia for everybody who takes a look.
edit: a fun example
#define x(y) z(y)
#define z(y) x(y)
x(y) should process to x(y), and z(y) should process to z(y) (very useful, no?)