I have to switch lexer context from parser. In order to do this I added set or #define's for each context defined using %s/%x, and function which calls BEGIN() with appropriate value. This is a bit inconvenient - I would like to use defines generated by flex itself, or provide my defines. The simplest solutions would be to protect context defines generated by flex with #ifdef SOME_MACRO - this will let me to redefine them in some header file. More complex solution would be to generate header file with these defines. You can also take a look how such feature is implemented in bison.