使用 NDK 编译(flex/bison)解析器
更新 我现在知道 parser.h 应该由 make 系统从 parser.y 生成。 Android.mk 文件甚至有这样的条目:
edify_src_files := \ 词法分析器.l \ 解析器.y \ expr.c
但我似乎仍然无法从中获取可执行文件。 (是的,可执行,不是共享库)
我正在尝试编译 Android Wifi Tether (http ://code.google.com/p/android-wifi-tether/)我自己在尝试编译一些与项目的 JNI 部分相关的 C 代码时,有一些奇怪的 lex/yacc 使用。
我以前从未处理过解析器,所以我在这里真的很紧张。在使用最新的 ndk-build 脚本(ndk-r5b)并解决其他一些问题后,我发现自己正在寻找 parser.h 头文件。我尝试在不包含它的情况下进行编译,并且具有未定义引用的函数调用是:
- yy_scan_string
- yy_scan_bytes
- yyparse
因此,我显然需要找到应在其中声明这些函数的此 parser.h 文件的路径。问题是,通过发出定位命令,我在系统中获得了大量同名文件的列表,但似乎没有一个是我要查找的文件。
有人可以在这里给我一盏灯吗?也许我需要安装开发者包?
谢谢!
纳尔逊
UPDATE
I know now that parser.h should be generated by the make system from parser.y. The Android.mk file even has an entry like this:
edify_src_files := \
lexer.l \
parser.y \
expr.c
But I still can't seem to get the executable out of it.
(Yes, excecutable, not shared library)
I'm trying to compile Android Wifi Tether (http://code.google.com/p/android-wifi-tether/) by myself and while trying to compile some C code related to the JNI part of the project there is some weird use of lex/yacc.
I've never dealt with parsers before so I'm really with my hands tight here. While using the latest ndk-build script (ndk-r5b) and after sorting some other problems I find myself looking for a parser.h header file. I tryied to compile without including it and the function calls that had undefined references were:
- yy_scan_string
- yy_scan_bytes
- yyparse
So I clearly need to find the path to this parser.h file where these functions should be declared. Problem is that by issuing a locate command I get a huge list of files with the same name in my system, but it seems like none of them is the one I'm looking for.
Can someone give me a light here? maybe I need to install a developer package?
Thanks!
Nelson
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到以下定义:
您可以在名为“lex”(或 flex)的词法扫描器自动生成的“.c”文件中 因此,如果您不打算自己编写它们,则需要一个 mylex.l 来应用于 lex,它通常会创建一个名为 lex.yy.c 的文件。
该文件可以与描述语法的语法解析器“.y”一起使用。在由名为“bison”或“yacc”的其他工具自动生成的另一个“.c”中,您会发现:
您可以指示 yacc 创建 2 个文件:parser.c 和 parser.h,它们都来自您需要的另一个文件比如说,写 mygrammar.y。
因此,简单来说,您需要编写:
然后运行:
你可以尝试在项目文件中找到像 mylex.l 和 mygrammar.y (可能有更好的名字)。如果项目没有给你源代码(.l 和 .y),也没有给你扫描器/解析器(lex.yy.c 和 parse.c/parser.h),你需要编写它们。
我希望这对你有帮助。
贝科
You can find the definition of:
in a ".c" automatically generated file by the lexical scanner called "lex" (or flex). So, if you do not intend to write them by yourself, you need a mylex.l to apply to lex, and it will usually create a file called lex.yy.c.
This file can be used together with a syntactical parser ".y" that describes your grammar. In the other ".c" generated automatically by this other tool called "bison" or "yacc", you will find:
You can instruct yacc to create 2 files: parser.c and parser.h, both coming from another file you need to write, lets say, mygrammar.y.
So, briefly, you need to write:
And then run:
You can try to find in the project files like mylex.l and mygrammar.y (probably with better names). If the project don't give you the sources (.l and .y) neither the scanner/parser (lex.yy.c and parse.c/parser.h), you need to write them.
I hope this helps you.
Beco