Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++中使用FraceLever重载YLYEXE() 我试图在LeX中编写一个简单的解析器,并用C++来做。我按照指示出发_C++_Lex_Flex Lexer - Fatal编程技术网

C++中使用FraceLever重载YLYEXE() 我试图在LeX中编写一个简单的解析器,并用C++来做。我按照指示出发

C++中使用FraceLever重载YLYEXE() 我试图在LeX中编写一个简单的解析器,并用C++来做。我按照指示出发,c++,lex,flex-lexer,C++,Lex,Flex Lexer,我不理解这个错误。发生了什么事?我在网上找到了这个FlexLexer.h include文件,似乎yylex的签名有一个参数FLEXFIX 但是,该文件的其他版本(如)则不是 顺便说一下,yylex函数没有返回int值 另请参见@Gir comment,其中包含一个bug报告的链接 问题是FlexLexer.h头有一种奇怪的方式 处理自身的多个内含物。tokenizer.l tokenizer.cc 和ClassParser.cc都间接地包含此标头,并且 单独编辑,效果良好;但在编译级联时 源,

我不理解这个错误。发生了什么事?

我在网上找到了这个FlexLexer.h include文件,似乎yylex的签名有一个参数FLEXFIX

但是,该文件的其他版本(如)则不是

顺便说一下,yylex函数没有返回int值

另请参见@Gir comment,其中包含一个bug报告的链接

问题是FlexLexer.h头有一种奇怪的方式 处理自身的多个内含物。tokenizer.l tokenizer.cc 和ClassParser.cc都间接地包含此标头,并且 单独编辑,效果良好;但在编译级联时 源,由插入的定义yyFlexLexer yyFlexLexer声明 flex从tokenizer.cc传输到ClassParser.cc,并导致 破坏第二次包容。在上面引用的错误消息中 两条FlexLexer.h线是第二条和第一条夹杂物, 分别

/A解决方案是在tokenizer.l的末尾取消yyFlexLexer的定义, 我会附上一个补丁,解释原因

h include文件中的注释提到对多个实例和include使用bug报告中的内容。但我不知道为什么这么简单明了的东西需要它

// This file defines FlexLexer, an abstract class which specifies the
// external interface provided to flex C++ lexer objects, and yyFlexLexer,
// which defines a particular lexer class.
//
// If you want to create multiple lexer classes, you use the -P flag
// to rename each yyFlexLexer to some other xxFlexLexer.  You then
// include <FlexLexer.h> in your other sources once per lexer class:
//
//  #undef yyFlexLexer
//  #define yyFlexLexer xxFlexLexer
//  #include <FlexLexer.h>
//
//  #undef yyFlexLexer
//  #define yyFlexLexer zzFlexLexer
//  #include <FlexLexer.h>
//  ...

查看您提供的链接,我想知道您是否需要删除FlexLexer.h include,因为您只有一个解析器。

标题中有什么?那里有门卫吗?没有,我没有头球。到目前为止,我的代码只有这些。。。meh这是2003年的。@Olzhabay,我试图通过其他链接以及引用一些实际的评论来改进这个答案。实际上,FlexLexer.h文件有几种不同的版本,有些带有FLEXFIX参数,有些没有。
In file included from tmp.cpp:12:0:
/usr/include/FlexLexer.h:112:7: error: redefinition of ‘class yyFlexLexer’
/usr/include/FlexLexer.h:112:7: error: previous definition of ‘class yyFlexLexer’
tmp.cpp: In member function ‘virtual int yyFlexLexer::yylex()’:
tmp.cpp:33:29: error: ‘listOfLinks’ was not declared in this scope
virtual int yylex(FLEXFIX) = 0;

// Call yylex with new input/output sources.
int yylex(FLEXFIX, istream* new_in, ostream* new_out = 0 )
    {
    switch_streams( new_in, new_out );
    return yylex(FLEXFIX2);
    }
virtual int yylex() = 0;

// Call yylex with new input/output sources.
int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 )
    {
    switch_streams( new_in, new_out );
    return yylex();
    }
// This file defines FlexLexer, an abstract class which specifies the
// external interface provided to flex C++ lexer objects, and yyFlexLexer,
// which defines a particular lexer class.
//
// If you want to create multiple lexer classes, you use the -P flag
// to rename each yyFlexLexer to some other xxFlexLexer.  You then
// include <FlexLexer.h> in your other sources once per lexer class:
//
//  #undef yyFlexLexer
//  #define yyFlexLexer xxFlexLexer
//  #include <FlexLexer.h>
//
//  #undef yyFlexLexer
//  #define yyFlexLexer zzFlexLexer
//  #include <FlexLexer.h>
//  ...