在使用flex创建词法分析器之前,我已经编写了几个解析器,但是这次我希望flex生成一个Lexer类而不是经典的C文件,即我希望flex生成一个C++扫描器类...问题是它没有为我生成 yyFlexLexer.h,只生成 lex.yy.cc
我已阅读 the Flex manual C++ chapter ...所以我不知道该怎么办...是我的 windows 的 Flex 无法正常工作吗?
这些是我当前使用的弹性选项:
%option outfile="cmdsLexer.cpp"
%option stdinit
%option case-insensitive
%option c++
%{
#include "global-scope.h"
%}
ANDIGIT [a-zA-Z0-9]
IDNTIFIER [a-zA-Z_]({ANDIGIT}|_|-)*
INTEGER [-+]?[0-9]+
STRING \"[^\n\"]*\"
....
最佳答案
没有yyFlexLexer.h
文件。相反,cmdsLexer.cpp
文件将包含一行
#include <FlexLexer.h>
请注意使用尖括号而不是双引号。该文件应该安装在您的系统上,例如如/usr/include/FlexLexer.h
。对于每个词法分析器来说都是相同的。对于 Windows,路径显然会有所不同。只需在 Flex 安装中找到该文件,并将其添加到编译器搜索头文件的路径中,例如使用-I
gcc 的选项。
另请注意 the document you referenced 的最后一段对于该 header 的高级使用:
If you want to create multiple (different) lexer classes, you use the ‘
-P
’ flag (or theprefix=
option) to rename eachyyFlexLexer
to some other ‘xxFlexLexer
’. You then can include<FlexLexer.h>
in your other sources once per lexer class, first renamingyyFlexLexer
as follows:#undef yyFlexLexer #define yyFlexLexer xxFlexLexer #include <FlexLexer.h> #undef yyFlexLexer #define yyFlexLexer zzFlexLexer #include <FlexLexer.h>
if, for example, you used
%option prefix="xx"
for one of your scanners and%option prefix="zz"
for the other.
关于c++ - flex 没有生成 yyFlexLexer.h header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367545/