c++ - flex 没有生成 yyFlexLexer.h header

标签 c++ c flex-lexer flex++

在使用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 the prefix= option) to rename each yyFlexLexer to some other ‘xxFlexLexer’. You then can include <FlexLexer.h> in your other sources once per lexer class, first renaming yyFlexLexer 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/

相关文章:

c - Linux上 `ru_maxrss`的单位是什么?

c - 在 C 中管理多个进程以完成相同的工作

c - strncat() 上的段错误

c - ubuntu 12.04 yylex() 调用中的段错误(核心转储)

c++ - 如何将 API 从 lex yacc 设置为 Program

c++ - 我如何以编程方式确定我的 C++ 运行时库在哪里?

C++:我可以强制我的程序员为每个类定义复制构造函数吗?

编译时的 C++ 类型标识

c++ - 错误:没有用于调用 QSortFilterProxyModel::setSourceModel(NavaidsModel&

c++ - 制作可重入解析器的错误