Next: , Previous: Options Affecting Scanner Behavior, Up: Scanner Options


16.3 Code-Level And API Options

--ansi-definitions, %option ansi-definitions
instruct flex to generate ANSI C99 definitions for functions. This option is enabled by default. If %option noansi-definitions is specified, then the obsolete style is generated.


--ansi-prototypes, %option ansi-prototypes
instructs flex to generate ANSI C99 prototypes for functions. This option is enabled by default. If noansi-prototypes is specified, then prototypes will have empty parameter lists.


--bison-bridge, %option bison-bridge
instructs flex to generate a C scanner that is meant to be called by a GNU bison parser. The scanner has minor API changes for bison compatibility. In particular, the declaration of yylex is modified to take an additional parameter, yylval. See Bison Bridge.


--bison-locations, %option bison-locations
instruct flex that GNU bison %locations are being used. This means yylex will be passed an additional parameter, yylloc. This option implies %option bison-bridge. See Bison Bridge.


-L, --noline, %option noline
instructs flex not to generate #line directives. Without this option, flex peppers the generated scanner with #line directives so error messages in the actions will be correctly located with respect to either the original flex input file (if the errors are due to code in the input file), or lex.yy.c (if the errors are flex's fault – you should report these sorts of errors to the email address given in Reporting Bugs).


-R, --reentrant, %option reentrant
instructs flex to generate a reentrant C scanner. The generated scanner may safely be used in a multi-threaded environment. The API for a reentrant scanner is different than for a non-reentrant scanner see Reentrant). Because of the API difference between reentrant and non-reentrant flex scanners, non-reentrant flex code must be modified before it is suitable for use with this option. This option is not compatible with the ‘--c++’ option.

The option ‘--reentrant’ does not affect the performance of the scanner.


-+, --c++, %option c++
specifies that you want flex to generate a C++ scanner class. See Cxx, for details.


--array, %option array
specifies that you want yytext to be an array instead of a char*


--pointer, %option pointer
specify that yytext should be a char *, not an array. This default is char *.


-PPREFIX, --prefix=PREFIX, %option prefix="PREFIX"
changes the default ‘yy’ prefix used by flex for all globally-visible variable and function names to instead be ‘PREFIX’. For example, ‘--prefix=foo’ changes the name of yytext to footext. It also changes the name of the default output file from lex.yy.c to lex.foo.c. Here is a partial list of the names affected:
     
              yy_create_buffer
              yy_delete_buffer
              yy_flex_debug
              yy_init_buffer
              yy_flush_buffer
              yy_load_buffer_state
              yy_switch_to_buffer
              yyin
              yyleng
              yylex
              yylineno
              yyout
              yyrestart
              yytext
              yywrap
              yyalloc
              yyrealloc
              yyfree
     

(If you are using a C++ scanner, then only yywrap and yyFlexLexer are affected.) Within your scanner itself, you can still refer to the global variables and functions using either version of their name; but externally, they have the modified name.

This option lets you easily link together multiple flex programs into the same executable. Note, though, that using this option also renames yywrap(), so you now must either provide your own (appropriately-named) version of the routine for your scanner, or use %option noyywrap, as linking with ‘-lfl’ no longer provides one for you by default.


--main, %option main
directs flex to provide a default main() program for the scanner, which simply calls yylex(). This option implies noyywrap (see below).


--nounistd, %option nounistd
suppresses inclusion of the non-ANSI header file unistd.h. This option is meant to target environments in which unistd.h does not exist. Be aware that certain options may cause flex to generate code that relies on functions normally found in unistd.h, (e.g. isatty(), read().) If you wish to use these functions, you will have to inform your compiler where to find them. See option-always-interactive. See option-read.


--yyclass=NAME, %option yyclass="NAME"
only applies when generating a C++ scanner (the ‘--c++’ option). It informs flex that you have derived NAME as a subclass of yyFlexLexer, so flex will place your actions in the member function foo::yylex() instead of yyFlexLexer::yylex(). It also generates a yyFlexLexer::yylex() member function that emits a run-time error (by invoking yyFlexLexer::LexerError()) if called. See Cxx.