|
QUESTION:I made good progress recently with my Cocoa bridge for Lisp and I'm
emboldened to start on the OCaml version. I would like to use a
parser for header files to build wrappers for Cocoa classes by first
building up the OCaml AST and then pretty-printing it.
I understand that there are ForkLift and CIL but it seems to me that
FL is more for generating FFI wrappers whereas I just need a parser.
I'm not familiar with CIL.
I want to grab a parser, add the Objective-C grammar and run the
result over Cocoa headers. What would be the best parser code base to
start with?
ANSWER: If you want to struggle through it: there is a CIL based wrapper
generator already for Felix. Clearly, you'd need to replace the code
that generates Felix with code that generates two files: an Ocaml
file with the 'extern' and 'type' definitions, and a C file
containing the glue logic.
My wrapper flxcc is a batch processor. It uses a control file
to parse and wrap complete systems, for example, it was designed
to wrap the WHOLE of /usr/include in a single pass, with a few
annotations in the control file.
The problem wrapping C is that you have process everything,
including all extremely non-conformant and weirdly structured
GNU system headers. You cannot wrap just a single file, because
it is too hard parse it with a LA(k) parser like Ocamlyacc.
It MAY be possible to do this with a GLR parser eg Dypgen.
. that is the EASY part... then you have to generate
the glue logic. For Felix that isn't too hard because it is
basically just a front end for C++ .. I think you'll find
doing this for Ocaml is fairly daunting.
|
|
|
|