[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 forbison
compatibility. In particular, the declaration ofyylex
is modified to take an additional parameter,yylval
. See section C Scanners with Bison Parsers.- ‘--bison-locations,
%option bison-locations
’ instruct flex that
GNU bison
%locations
are being used. This meansyylex
will be passed an additional parameter,yylloc
. This option implies%option bison-bridge
. See section C Scanners with Bison Parsers.- ‘-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 originalflex
input file (if the errors are due to code in the input file), or ‘lex.yy.c’ (if the errors areflex
’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 section Reentrant C Scanners). 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 section Generating C++ Scanners, 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 achar *
, not an array. This default ischar *
.- ‘-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 ofyytext
tofootext
. 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
andyyFlexLexer
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 renamesyywrap()
, 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 callsyylex()
. This option impliesnoyywrap
(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 derivedNAME
as a subclass ofyyFlexLexer
, soflex
will place your actions in the member functionfoo::yylex()
instead ofyyFlexLexer::yylex()
. It also generates ayyFlexLexer::yylex()
member function that emits a run-time error (by invokingyyFlexLexer::LexerError())
if called. See section Generating C++ Scanners.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on November 4, 2011 using texi2html 5.0.