不幸的是我必须解析一种语言(JScript)。我开始研究如何使用 Flex,因为知道 Qt 提供了一个名为 QLALR 的有用工具来生成解析器。
在 \util\qlalr\examples\qparser 中,我发现了一个非常有趣的示例,集成了 Flex 生成的扫描器和 qlalr 生成的解析器。另外,根据我的理解(但这不可能是真的......),该示例引入了一个有用的 QParser 接口,以避免重写解析函数。为了编译它,我必须从 http://sourceforge.net/projects/gnuwin32/files/flex/2.5.4a-1/flex-2.5.4a-1-lib.zip/download。它位于目录 include 中。无论如何,它只不过是:
/*
This file is part of the Mingw32 package.
*
unistd.h maps (roughly) to io.h
*/
#ifndef _STRICT_ANSI_
#include <io.h>
#include <process.h>
#endif
使用这个文件,我能够编译 qparser 示例,但是当我运行它时,我在进入主函数之前发生崩溃,并显示错误消息:程序 '[3736] qparser.exe: Native'已退出,代码为 2 (0x2)。
我还收到以下警告消息:
1>lex.calc.c(903) : warning C4003: not enough actual parameters for macro 'calcwrap'
1>lex.calc.c(1056) : warning C4018: '<' : signed/unsigned mismatch
1>lex.calc.c(1238) : warning C4003: not enough actual parameters for macro 'calcwrap'
1>lex.calc.c(1402) : warning C4996: 'isatty': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _isatty. See online help for details.
1> c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\io.h(312) : see declaration of 'isatty'
1>lex.calc.c(1402) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
1> c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(722) : see declaration of 'fileno'
1>Linking...
1>LINK : debug
qparser.exe not found or not built by the last incremental link; performing full link
我正在 Windows 7 上使用 Visual Studio 2008,而 Qt 4.8.0 是从我获得 QLALR 的同一包编译的。
一些建议?
谢谢
Unfortunately I have to parse a language (JScript). I started to study how to use Flex knowing that Qt is providing a useful tool called QLALR in order to generate parser.
In \util\qlalr\examples\qparser I found a very interesting example integrating a flex generated scanner and qlalr generated parser. Also, from what I understood (but it couldn't be true...) the example introduces a useful QParser interface to avoid to rewrite parse function. In order to compile it I had to download a unistd.h for windows from http://sourceforge.net/projects/gnuwin32/files/flex/2.5.4a-1/flex-2.5.4a-1-lib.zip/download. It is in the directory include. In any case it is nothing more than:
/*
This file is part of the Mingw32 package.
*
unistd.h maps (roughly) to io.h
*/
#ifndef _STRICT_ANSI_
#include <io.h>
#include <process.h>
#endif
Using this file I was able to compile the qparser example but when I run it I get a crash before entering in main function with error message: The program '[3736] qparser.exe: Native' has exited with code 2 (0x2).
I'm getting also the following warning messages:
1>lex.calc.c(903) : warning C4003: not enough actual parameters for macro 'calcwrap'
1>lex.calc.c(1056) : warning C4018: '<' : signed/unsigned mismatch
1>lex.calc.c(1238) : warning C4003: not enough actual parameters for macro 'calcwrap'
1>lex.calc.c(1402) : warning C4996: 'isatty': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _isatty. See online help for details.
1> c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\io.h(312) : see declaration of 'isatty'
1>lex.calc.c(1402) : warning C4996: 'fileno': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _fileno. See online help for details.
1> c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(722) : see declaration of 'fileno'
1>Linking...
1>LINK : debug
qparser.exe not found or not built by the last incremental link; performing full link
I'm using Visual Studio 2008 on Windows 7 and Qt 4.8.0 compiled from the same package where I got QLALR.
Some suggestions?
Thanks
发布评论
评论(1)
好吧,我自己解决了这个问题。
问题是提供的 .pro 未包含 win32-msvc2008:CONFIG += console 指令。
我还建议您在 calc.l 的开头添加 %option nounistd 和 #include ,以便使用默认包含目录中提供的 atty 函数。
Ok I resolved the thing by myself.
The problem is that the provided .pro has not included the win32-msvc2008:CONFIG += console directive.
I suggest you, also, to add an %option nounistd at the beginning of the calc.l and an #include in order to use the atty function provided in the default include directory.