开源解析器用于从 C 生成数据绑定?

发布于 2024-10-17 12:47:51 字数 2611 浏览 2 评论 0 原文

是否有 C 头文件(和/或 Java jar)的数据绑定解析器/生成器来生成[可能] XML 数据绑定以供使用/导入(或生成包装器)到“其他”语言? (例如 pythonHaskell开始! < a href="http://sourceforge.net/projects/algol68/" rel="nofollow">其他) 该解析器将用于减少:

  1. 共享库中的程序
  2. 数据分流到/从磁盘
  3. 进程间消息

在最简单的情况下:是否已经有一个为 维护的“XML 数据绑定” glibc? (也许 GCC 中有一个神奇选项可以生成 XML 数据绑定?)

背景示例:在 Tandem Guardian 上有一个 DDL 编译器(“数据定义语言”),基本上是DDL 语言包含许多记录定义,可以由 DDL 编译器“编译”为生成 C/结构TAL/struct, Pascal/Record, Fortran/named-commonsCOBOL/Record 声明,在编译 C(或 TAL/Pascal/Fortran/COBOL)程序时可以“包含”然后。 DDL 语言使得库的创建和跨语言共享变得非常容易。 DDL 输出可用于将数据分流到磁盘或从磁盘分流数据以及在 进程间消息,因此可以轻松地在用不同语言编写的程序之间共享数据。

一些当代的例子:

C++ 允许直接导入 C 头文件,例如:

extern "C" {
    #include "header.h"
}

Python 特别允许解析 GTK C 库,并使用 PyGTK-Codegen 通过“Defs”文件:

(define-object name
  (in-module "module")
  (docstring "doc")
  (parent "parent")
  (c-name "name")
  (gtype-id "id")
  (fields
    ("type" "name")
    ...
  )
  (implements "interface")
)

在某种程度上 RPC一半解决了不同CPU架构之间的IPC问题。但对于其他语言来说,本地数据绑定声明不是问题。

在第一个实例中,一个只用 C 语言生成 XML 的开源工具就很好了(而且来自 java 的工具是真正的好处)。如果这个解析器已经在主要的 Linux 发行版上就更好了。

我在以下位置发现了解析器摘要:XML 数据绑定工具

Is there an Data Binding Parser/Generator of C header files (and/or Java jars) to generate [maybe] XML Data Binding for use/importing (or generating wrappers) into "other" languages? (eg python, Haskell, Go! and others) This parser would used for cut down:

  1. sharing procedures in libraries
  2. data shunting to/from disk
  3. inter-process messages

In the simplest case: Is there already a maintained "XML Data Binding" for glibc? (Maybe there is a magic option in GCC that generates the XML Data Bindings?)

Background example: On Tandem Guardian there is a DDL Compiler ("Data Definition Language") , basically the DDL language contains many record definitions , that can "compiled" by the DDL compiler to generate C/struct, TAL/struct, Pascal/Record, Fortran/named-commons or COBOL/Record declarations that can then be "included" when the C (or TAL/Pascal/Fortran/COBOL) program is compiled. The DDL language makes the creating and the inter-language sharing of libraries very easy. The DDL output could also be used for both shunting data to/from disk and in inter-process messages, hence easily sharing data between programs written in different languages.

Some close contemporary examples:

C++ permits the direct importing of C header files, eg:

extern "C" {
    #include "header.h"
}

Python specifically permits the parsing of GTK C libraries, and the generation of python wrapper modules with PyGTK-Codegen via "Defs" files:

(define-object name
  (in-module "module")
  (docstring "doc")
  (parent "parent")
  (c-name "name")
  (gtype-id "id")
  (fields
    ("type" "name")
    ...
  )
  (implements "interface")
)

In a way RPCs half solve the problem of IPC between different CPU architectures. But not local data binding declarations problem to other languages.

In the first instance an open-source tool parsing for just C generating XML would be great (and one from java a real bonus). If it this parser is already on a major Linux distribution even better.

I have spotted Parser summary at: XML Data Binding Tools

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终陌 2024-10-24 12:47:51

引用:

SWIG 是一个软件开发工具
连接用 C 编写的程序
C++ 以及各种高级
编程语言。使用SWIG
具有不同类型的目标
语言,包括通用脚本
语言,例如 PerlPHPPython
Tcl红宝石。支持的列表
语言还包括非脚本语言
语言,例如 C#、Common Lisp
CLISPAllegro CLCFFIUFFI), D
Go 语言, JavaLuaModula-3OCAML
八度派克(?)和R。还有几种解读
并编译Scheme实现
GuileMzScheme/Racket)是
支持。

SWIG 最常用
创建高级解释或
编译的编程环境,
用户界面,并作为一个工具
C/C++ 测试和原型设计
软件。 SWIG 通常用于
解析C/C++接口并生成
上述所需的“粘合代码”
调用的目标语言
C/C++ 代码。 SWIG 还可以导出其
XML 和 Lisp 形式解析树
s-表达式

支持:

  • FreeBSD/OpenBSD/NetBSD
  • HP-UX
  • Linux
  • Mac OS X
  • Solaris
  • Windows 95/98/NT/2000/XP/Vista

另外:对于 C 的序列化"序列化" ( s11n/c11n) 可以使用。它包括
funtxt(文本)、funxml(基本 XML 方言)、simplexml(精简 XML 方言)、compact(非人类) )、括号(emacs-友好)、韦斯诺斯外国人sqlite & mysql

Quote:

SWIG is a software development tool
that connects programs written in C
and C++ with a variety of high-level
programming languages. SWIG is used
with different types of target
languages including common scripting
languages such as Perl, PHP, Python,
Tcl and Ruby. The list of supported
languages also includes non-scripting
languages such as C#, Common Lisp
(CLISP, Allegro CL, CFFI, UFFI), D,
Go language, Java, Lua, Modula-3, OCAML,
Octave, Pike(?) and R. Also several interpreted
and compiled Scheme implementations
(Guile, MzScheme/Racket, Chicken) are
supported.

SWIG is most commonly used
to create high-level interpreted or
compiled programming environments,
user interfaces, and as a tool for
testing and prototyping C/C++
software. SWIG is typically used to
parse C/C++ interfaces and generate
the 'glue code' required for the above
target languages to call into the
C/C++ code. SWIG can also export its
parse tree in the form of XML and Lisp
s-expressions.

Supports:

  • FreeBSD/OpenBSD/NetBSD
  • HP-UX
  • Linux
  • Mac OS X
  • Solaris
  • Windows 95/98/NT/2000/XP/Vista

Also: For Serialisation of C the package "Cerialization" (s11n/c11n) can be used. It includes
funtxt (text), funxml (basic XML dialect), simplexml (leaner XML dialect), compact (non-human), parens (emacs-friendly), wesnoth, expat, sqlite & mysql.

今天小雨转甜 2024-10-24 12:47:51

我的朋友通过 python 脚本手动解析 C 文件并通过 cog 生成必要的输出。

ragel 已经有 C 解析器,但生成功能必须亲自添加。

my friend parse C files manually via python script and generate necessary output via cog.

ragel already have C-parser, but generate feature must be added personally.

站稳脚跟 2024-10-24 12:47:51

我不确定你想要什么,但可能 Antlr 可以用于此目的,并且已经有 为C编写的语法,所以你可以直接使用这个。

I'm not sure what you want but may be Antlr can be used for this purpose and there is already grammar written for C, so you can directly use this one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文