开发者

Multiple lexers with flex++

开发者 https://www.devze.com 2023-02-14 14:43 出处:网络
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 a

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 whe开发者_开发问答n 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

0

精彩评论

暂无评论...
验证码 换一张
取 消