Search code examples
conditional-statementsflex-lexer

Is conditional FLEX/BISON code generation possible?


Can i use something like #ifdef in FLEX and/or BISON source code? I would want to control what options my scanner recognizes depending on different compilation parameters.

Also, is there a way to use multiple sources at the same time? (for example scanner1.lex and scanner2.lex to be combined into lex.yy.c)


Solution

  • Neither flex nor bison come with a preprocessor, and it would be unwise to use the C preprocessor, since your source files are likely to contain C preprocessor directives intended to be passed through to the generated code.

    But nothing stops you from writing your own preprocessor, or using a macro language like m4. (m4 must be available because both flex and bison depend on it.)