Re: yylex(int a) in flex -+?

sandip@earthling.net
7 Mar 1998 22:15:48 -0500

          From comp.compilers

Related articles
yylex(int a) in flex -+? schmitt@ti.informatik.uni-frankfurt.de (Holger Schmitt) (1998-03-03)
Re: yylex(int a) in flex -+? sandip@earthling.net (1998-03-07)
| List of all articles for this month |

From: sandip@earthling.net
Newsgroups: comp.compilers
Date: 7 Mar 1998 22:15:48 -0500
Organization: Compilers Central
References: 98-03-017
Keywords: lex, C++

To achieve the desired result, one has to do the following :
1. use #define YY_DECL
2. use %option yyclass AND optionally %option prefix
3. create an inherited class and override the function yylex


e.g. I use the following to use it with bison (A2.6 Andrew) and mkparserclass


class cSQLLexer : public yyFlexLexer {
private :
        istrstream *SQLbuf ;
public :
        cSQLLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
                {
                        yyFlexLexer( arg_yyin, arg_yyout ) ;
                }
        void Set_SQL( char *str )
                {
                        SQLbuf = new istrstream( str ) ;
                        yyFlexLexer::switch_streams( SQLbuf ) ;
                }
          int yylex( void *lexrock, YYSTYPE *yylval );
} ;
4. #define yyflexerlexer as usual.




    Holger Schmitt <schmitt@ti.informatik.uni-frankfurt.de> wrote:
> I use flex (Version 2.5) with the option -+ to generate different
> Scanner-classes. I would like to use the different Scanner-routines
> yylex with different parameter like yylex(int a).
> A new yylex definition with the macro #define YY_DECL doesn't work,
> because these funktion isn't defined in the class definition.
> Is there a good way for defining a new funktion yylex(int a) in the
> different Scanner-classes?
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.