vc++下编译bison和flex程序时unistd.h相关困难

2024-03-21

我正在使用 bison & flex(通过 cygwin 下载)和 vc++。当我编译程序时,出现错误:

...: fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory

flex生成的文件中对应的代码是:

#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
 * down here because we want the user's section 1 to have been scanned first.
 * The user has a chance to override it with an option.
 */
/* %if-c-only */
#include <unistd.h>
/* %endif */
/* %if-c++-only */
/* %endif */
#endif

如果我在 Flex 文件(.l)中定义 YY_NO_UNISTD_H,此错误将会消失,但我会收到其他几个错误:

...: error C2447: '{' : missing function header (old-style formal list?)
...: warning C4018: '<' : signed/unsigned mismatch
...: error C3861: 'isatty': identifier not found

我该如何解决这个问题?

所有这些错误都发生在 Flex 生成的扫描仪中。

我知道这是因为 unistd.h 在 Windows 中不存在。我必须编写自己的 unistd.h 吗?如果是这样,如何编写才能消除这些错误?


isatty词法分析器使用它来确定输入流是终端还是管道/文件。词法分析器使用此信息来更改其缓存行为(词法分析器在不是终端时读取大量输入)。如果您知道您的程序永远不会以交互方式使用,您可以添加%option never-interactive给你词法分析器。当程序通过用户输入运行时,使用%option interactive。当需要两种用途时,您可以生成一个交互式词法分析器,这在批处理模式下使用时会带来性能损失,或者提供您自己的isatty功能。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

vc++下编译bison和flex程序时unistd.h相关困难 的相关文章

随机推荐