File: flex.info, Node: Options Affecting Scanner Behavior, Next: Code-Level And API Options, Prev: Options for Specifying Filenames, Up: Scanner Options 16.2 Options Affecting Scanner Behavior ======================================= '-e, --emit, '%option emit'' instructs 'flex' to generate code using a specific back end other than the default. The default is called "cpp", generates C or C++ code, supports all legacy interfaces, and generates either non-reentrant or re-entrant scanners. There is presently one alternate back end, C99; it drops a lot of legacy interfaces, generates only re-entrant scanners, and outputs modern C. The C99 back end is intended to be a launching point for as yet unwritten back ends generating scanners in other languages such as Go, Rust, Java, Python, etc. The C99 back end defines its interface as ordinary global functions such as 'yybegin()', 'yystart()', 'yyecho()', 'yyatbol()' and 'yysetbol()'. A program that has its own function with one of those names cannot use that back end in the same program, and should rename its function. The default back end does not have this limit, because it does not define those names. ''%option rewrite'' Back ends other than the default C generator can't assume they have the C preprocessor available. Therefore, Flex recognizes the following function calls - yyecho(), yyless(), yymore(), yyinput(), yystart(), yybegin(), yyunput(), yypanic() - and rewrites them adding a yyscanner final argument as though they were C macros. This optiion is set to false when you select or default to the C back end, and to true otherwise. You can turn it off (or on) explicitly after your emit option. '-i, --case-insensitive, '%option case-insensitive'' instructs 'flex' to generate a "case-insensitive" scanner. The case of letters given in the 'flex' input patterns will be ignored, and tokens in the input will be matched regardless of case. The matched text given in 'yytext' will have the preserved case (i.e., it will not be folded). For tricky behavior, see *note case and character ranges::. '-l, --lex-compat, '%option lex-compat'' turns on maximum compatibility with the original AT&T 'lex' implementation. Note that this does not mean _full_ compatibility. Use of this option costs a considerable amount of performance, and it cannot be used with the '--c++', '--full', '--fast', '-Cf', or '-CF' options. For details on the compatibilities it provides, see *note Lex and Posix::. It will usually be a no-op on back ends other than C/C++. This option also results in the name 'YY_FLEX_LEX_COMPAT' being '#define''d in the generated scanner. '-B, --batch, '%option batch'' instructs 'flex' to generate a "batch" scanner, the opposite of _interactive_ scanners generated by '--interactive' (see below). In general, you use '-B' when you are _certain_ that your scanner will never be used interactively, and you want to squeeze a _little_ more performance out of it. If your goal is instead to squeeze out a _lot_ more performance, you should be using the '-Cf' or '-CF' options, which turn on '--batch' automatically anyway. '-I, --interactive, '%option interactive'' instructs 'flex' to generate an interactive scanner. An interactive scanner is one that only looks ahead to decide what token has been matched if it absolutely must. It turns out that always looking one extra character ahead, even if the scanner has already seen enough text to disambiguate the current token, is a bit faster than only looking ahead when necessary. But scanners that always look ahead give dreadful interactive performance; for example, when a user types a newline, it is not recognized as a newline token until they enter _another_ token, which often means typing in another whole line. 'flex' scanners default to 'interactive' unless you use the '-Cf' or '-CF' table-compression options (*note Performance::). That's because if you're looking for high-performance you should be using one of these options, so if you didn't, 'flex' assumes you'd rather trade off a bit of run-time performance for intuitive interactive behavior. Note also that you _cannot_ use '--interactive' in conjunction with '-Cf' or '-CF'. Thus, this option is not really needed; it is on by default for all those cases in which it is allowed. You can force a scanner to _not_ be interactive by using '--batch' '-7, --7bit, '%option 7bit'' instructs 'flex' to generate a 7-bit scanner, i.e., one which can only recognize 7-bit characters in its input. The advantage of using '--7bit' is that the scanner's tables can be up to half the size of those generated using the '--8bit'. The disadvantage is that such scanners often hang or crash if their input contains an 8-bit character. Note, however, that unless you generate your scanner using the '-Cf' or '-CF' table compression options, use of '--7bit' will save only a small amount of table space, and make your scanner considerably less portable. 'Flex''s default behavior is to generate an 8-bit scanner, also with '-Cf' or '-CF', unless your site was configured to generate 7-bit scanners for those options. Only use '--7bit' if the scanner's input can never contain an 8-bit character. You can tell whether flex generated a 7-bit or an 8-bit scanner by inspecting the flag summary in the '--verbose' output as described above. '-8, --8bit, '%option 8bit'' instructs 'flex' to generate an 8-bit scanner, i.e., one which can recognize 8-bit characters. This is the default, so the flag is only needed to override an earlier '--7bit' or a site configured to generate 7-bit scanners for '-Cf' or '-CF'. See the discussion of '--7bit' above for 'flex''s default behavior and the tradeoffs between 7-bit and 8-bit scanners. '--default, '%option default'' generate the default rule. '--always-interactive, '%option always-interactive'' instructs flex to generate a scanner which always considers its input _interactive_. Normally, on each new input file the scanner calls 'isatty()' in an attempt to determine whether the scanner's input source is interactive and thus should be read a character at a time. When this option is used, however, then no such call is made. '--never-interactive, '%option never-interactive'' instructs flex to generate a scanner which never considers its input interactive. This is the opposite of 'always-interactive'. '-X, --posix, '%option posix'' turns on maximum compatibility with the POSIX 1003.2-1992 definition of 'lex'. Since 'flex' was originally designed to implement the POSIX definition of 'lex' this generally involves very few changes in behavior. At the current writing the known differences between 'flex' and the POSIX standard are: * In POSIX and AT&T 'lex', the repeat operator, '{}', has lower precedence than concatenation (thus 'ab{3}' yields 'ababab'). Most POSIX utilities use an Extended Regular Expression (ERE) precedence that has the precedence of the repeat operator higher than concatenation (which causes 'ab{3}' to yield 'abbb'). By default, 'flex' places the precedence of the repeat operator higher than concatenation which matches the ERE processing of other POSIX utilities. When either '--posix' or '-l' are specified, 'flex' will use the traditional AT&T and POSIX-compliant precedence for the repeat operator where concatenation has higher precedence than the repeat operator. '--stack, '%option stack'' enables the use of start condition stacks (*note Start Conditions::). '--stdinit, '%option stdinit'' if set (i.e., %option stdinit) initializes 'yyin' and 'yyout' to 'stdin' and 'stdout', instead of the default of 'NULL'. Some existing 'lex' programs depend on this behavior, even though it is not compliant with ANSI C, which does not require 'stdin' and 'stdout' to be compile-time constant. In a reentrant scanner, however, this is not a problem since initialization is performed in 'yylex_init' at runtime. '--yylineno, '%option yylineno'' directs 'flex' to generate a scanner that maintains the number of the current line read from its input in the global variable 'yylineno'. This option is implied by '%option lex-compat'. In a reentrant C scanner, 'yylineno' is accessible regardless of the value of '%option yylineno', however, its value is not modified by 'flex' unless '%option yylineno' is enabled. '--yywrap, '%option yywrap'' if unset (i.e., '--noyywrap)', makes the scanner not call 'yywrap()' upon an end-of-file, but simply assume that there are no more files to scan (until the user points 'yyin' at a new file and calls 'yylex()' again).
