help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bison/Flex - C++ - String input


From: John W. Millaway
Subject: Re: Bison/Flex - C++ - String input
Date: Mon, 18 Feb 2002 08:42:18 -0800 (PST)

> I am looking for a good example of integration of Bison with Flex++ or a
> good
> example of threadsafe integration of bison/flex. This example needs to
> parse
> a string as input and should completly ban global variables.

There are a few ways. One way is to get bison to call yyFlexLexer::yylex() by
proxy through a global function "yylex()". Bison will call some global function
"yylex()", optionally passing in a user-defined parameter "void * YYLEX_PARAM".
The trick is to let YYLEX_PARAM be your scanner object. Your yylex() function
will cast the parameter to the appropriate object type, and call the yylex()
method of yyFlexLexer.

// In foo.c
int yylex(void* pscanner){
    return static_cast<yyFlexLexer*>(scanner)->yylex();
}

//In foo.y:
#define YYPARSE_PARAM pscanner
#define YYLEX_PARAM pscanner
extern int yylex(void*);

See the bison manual for more details. Search for YYLEX_PARAM.


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]