开发者

Compiling a (flex/bison) parser with NDK

开发者 https://www.devze.com 2023-02-17 17:34 出处:网络
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:

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-teth开发者_如何学Cer/) 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


You can find the definition of:

YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str  );
YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len  );

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:

int yyparse (void *YYPARSE_PARAM);

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:

  • mylex.l
  • mygrammar.y

And then run:

  • flex mylex.l ==> gives you lex.yy.c
  • bison --defines=parser.h --output=parser.c mygrammar.y ==> gives you parser.h parser.c

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号