Question

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.

Était-ce utile?

La solution

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.

Autres conseils

You can take a look at mine. I got in the same idea you have:P You can find it here It supports expressions but I realized that you must have an ast if you want to support forward references. Maybe when Notch figures out that unfixed sized op codes are harder to make an assembler for he will change it:)

A decent book on the subject is Flex and Bison It shows how you can do "states" that is you can push the lexer state and change out the file buffers. It shows a rudimentarily parser/lex for just that. It helped alot in my learning:)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top