This page describes how to do some common tasks with Flex, a tool for generating programs that perform pattern-matching on text.
To suppress the warning message "yyunput defined but not used" when compiling the flex output with gcc -Wall, use a line
%option nounputin the options section (the part after
%}).
To make flex generate line numbers, use a line
%option yylinenoin the options section (the part after
%}). This makes a
global variable, yylineno, available. You need to
set yylineno to the first line of the file being read.
See also the Flex manual on the prefix option.
To make flex generate a header file with a declaration of a prototype for yylex, use the --header-file option,
flex --header-file=my.lex.h my.lwhere
my.l is the name of your input file, and my.lex.h is the name of the header file you want to create.
To change the prefix used on all of Flex's functions, use a line
%option prefix="myprefix_"in the options section (the part after
%}). This changes
everything; yylex
becomes myprefix_lex, yylineno
becomes myprefix_lineno, etc.
See also the Flex manual on the prefix option.
To stop the error "undefined reference to `yywrap'" from Flex, use
%option noyywrapin the options section (the part after
%}), or link with
the Flex library, -lfl, to use the
default yywrap function which comes with Flex.
To stop the error message "warning: 'yy_top_state' defined but not used", use
%option noyy_top_statein the options section.