YACC interface
Previous: <User variables=>Uservariab> * Next: <Options=>Options> * Up: <Top=>!Root>

#Wrap on
{fH3}Interfacing with {fCode}yacc{f}{f}

One of the main uses of {fCode}flex{f} is as a companion to the {fCode}yacc{f}
parser-generator.  {fCode}yacc{f} parsers expect to call a routine
named {fEmphasis}yylex(){f} to find the next input token.  The routine
is supposed to return the type of the next token as well
as putting any associated value in the global {fCode}yylval{f}.  To
use {fCode}flex{f} with {fCode}yacc{f}, one specifies the {fEmphasis}-d{f} option to {fCode}yacc{f} to
instruct it to generate the file {fCite}y.tab.h{f} containing
definitions of all the {fEmphasis}%tokens{f} appearing in the {fCode}yacc{f} input.
This file is then included in the {fCode}flex{f} scanner.  For
example, if one of the tokens is "TOK\_NUMBER", part of the
scanner might look like:

#Wrap off
#fCode
%\{
\#include "y.tab.h"
%\}

%%

[0-9]+        yylval = atoi( yytext ); return TOK\_NUMBER;
#f
#Wrap on

