Search code examples
cbisonlex

The functions and variables generated by flex start with yy, how to change them to start with other letters


For example,the default is "yytext",but I want to rename it to "aatext",how can I do this?


Solution

  • It seems like the Flex manual would be the natural place to look. Google offers several versions of Lexical Analysis with Flex, for various versions of Flex. For example, https://westes.github.io/flex/manual/.

    The manual has a nice table of contents, which lists a chapter "Scanner options", which sounds promising, and a section within named "Code-Level and API Options", which seems like it would be just the thing.

    And Lo! In that section we can find documented the prefix option, which can be spelled -PPREFIX or --prefix=PREFIX on the Flex command line, or %option prefix="PREFIX" in the input file, and which

    changes the default 'yy' prefix used by flex for all globally-visible variable and function names to instead be 'PREFIX'.

    Do read the rest of the documentation for that option, too.