unistd.h相关的困难时编译bison& flex程序在vc ++下 [英] unistd.h related difficulty when compiling bison & flex program under vc++

查看:784
本文介绍了unistd.h相关的困难时编译bison& flex程序在vc ++下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用野牛& flex(通过cygwin下载)与vc ++。当我编译程序时,我得到一个错误:

I'm using bison & flex (downloaded via cygwin) with vc++. When I compile the program I got an error:

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

flex生成的文件中的相应代码是: p>

The corresponding code in the flex-generated file is:

#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,这个错误会消失,但是我得到了一些其他错误:

If I define YY_NO_UNISTD_H in the flex file(.l) this error will disappear, but I get several other errors:

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


b $ b

我如何解决这个问题?

How can I fix this problem?

所有这些错误发生在flex生成的扫描程序中。

All these errors occur in the flex-generated scanner.

我知道这是因为unistd.h在windows中不存在。我必须写我自己的unistd.h吗?

I know it's because unistd.h doesn't exist in windows. Do I have to write my own unistd.h? If so how to write it in order to eliminate those errors?

推荐答案

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

isatty is used by the lexer to determine if the input stream is a terminal or a pipe/file. The lexer uses this information to change its caching behavior (the lexer reads large chunks of the input when it is not a terminal). If you know that your program will never be used in an interactive kind, you can add %option never-interactive to you lexer. When the program is run with user input, use %option interactive. When both uses are desired, you can either generate an interactive lexer, which gives a performance loss when used in batch mode, or provide your own isatty function.

这篇关于unistd.h相关的困难时编译bison&amp; flex程序在vc ++下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆