I have written a simple assembler using flex+bison. I'd like to add a preprocessor (macros) to the assembly language. This is my first time trying to use flex+bison, I'm not sure how to go about this.
Is it appropriate to add a separate instance of flex+bison and do the preprocessing completely separately? Or do they support expressing different constructs for different phases of processing?
If curious, the assembler is here, for the DCPU-16 architecture.
You definitely want a separate parser. That's the way gcc does it - you can stop the compilation after just the preprocessing (-E
, I believe). It may be technically possible to write as a single parser, but it'll be a lot more trouble, and I don't see a particular reason why it would be useful, whereas keeping it separate will allow you to stop compilation after just preprocessing, making it easier to track down errors not just in the preprocessor/assembler itself, but any programs written with it.