简体   繁体   中英

Multiple lexers with flex++

I am trying to link various Flex++ Lexers in the same executable. However, I get compile errors as a result because of symbol redefinition. I tried to set different prefixes but it was no use: These are my options:

Lexer1:

%option c++
%option noyywrap
%option yyclass="SendmailScanner"
%option prefix="zz"

Lexer2:

%option c++
%option noyywrap
%option yyclass="SSHDFailureScanner"
%option prefix="xx"

According to the manual, I should only unset the variable yyFlexLexer and change it into zzFlexLexer (in the source file that uses that lexer) or xxFlexerLexer. Unfortunately, I got the following errors:

/usr/include/FlexLexer.h:103: error: redefinition of ‘class zzFlexLexer’
/usr/include/FlexLexer.h:103: error: previous definition of ‘class zzFlexLexer’

This error also appears even when I have only one Lexer... I do not know what to do.

Thank you in advance,

Though I didn't test thoroughly, the redefinition error didn't occur when I tested with simple files. My flex 's version is 2.5.35. For your information, my test files are configured like the following:

Lexer1.h:

struct SendmailScanner : yyFlexLexer {
  int yylex();
};

Lexer2.h:

struct SSHDFailureScanner : yyFlexLexer {
  int yylex();
};

Lexer1.l:

%{
#include "Lexer1.h"
%}

%option c++
%option noyywrap
%option yyclass="SendmailScanner"
%option prefix="zz"

%%
...

Lexer2.l:

%{
#include "Lexer2.h"
%}

%option c++
%option noyywrap
%option yyclass="SSHDFailureScanner"
%option prefix="xx"

%%
...

The above files don't include #undef yyFlexLexer and #define yyFlexLexer ... directives. Probably those directives aren't needed when flex-generated files are compiled.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM