Prolog 作为 DSL 来生成 perl 代码?

发布于 2024-10-18 13:43:55 字数 47 浏览 2 评论 0原文

有谁知道用 prolog 编写的代码示例来实现 DSL 来生成 perl 代码?

Does anyone know of any examples of code written in prolog to implement a DSL to generate perl code?

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

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

发布评论

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

评论(4

娇俏 2024-10-25 13:43:55

DCG 可能是一个不错的选择!

我使用了类似的方法从简单的英语句子(无耻的插件:论文在这里)。应该可以通过生成 Perl 代码来执行类似的操作。

在上面的论文中,我们使用约束存储(CHR)作为中间表示,它允许一些额外的推理能力。或者,您可以构建表示作为 DCG 的输出特征/参数。

请注意,DCG 对于解析句子和生成 Perl 代码都很有用。

DCGs might be an excellent choice!

I have used a similar approach for generation of UML class diagrams (really, graphviz code for such diagrams) from simple English sentences (shameless-plug: paper here). It should be possible to do something similar with generation of Perl code instead.

In the paper above, we use a constraint store (CHR) as intermediate representation which allows some extra reasoning power. Alternatively you can build a representation as an output feature/argument of the DCG.

Note that DCGs can be useful both for the parsing of your sentences and the generation of your Perl code.

殊姿 2024-10-25 13:43:55

好吧,不完全是你所要求的,但也许你可以使用 AI::Prolog 查找您正在寻找的内容。这样您就可以使用 Perl 并生成您想要的 Perl 代码。

Well, not exactly what you are asking for, but maybe you can use AI::Prolog for what you are looking for. That way you may be able to use Perl and generate the Perl code you want.

灵芸 2024-10-25 13:43:55

我不确定你为什么要这样做?

Perl 是一种非常具有表现力的语言,我不确定为什么你想尝试从 Prolog 生成 Perl 代码;为了使其有用,您将在“DSL”中越来越接近 Perl,到那时您最好只编写一些 Perl,当然吗?

我认为您需要稍微扩展一下这个问题,以更详细地涵盖您想要实现的目标。

I'm not sure why you would want to do that?

Perl is a very expressive language, I'm not sure why you'd want to try to generate Perl code from Prolog; in order to make it useful, you'd be getting closer and closer to Perl in your "DSL", by which point you'd be better off just writing some Perl, surely?

I think you need to expand this question a bit to cover what you're trying to achieve in a little more detail.

酒解孤独 2024-10-25 13:43:55

SWI-Prolog library(http/html_write) 库基于 DCG 构建,用于页面布局的 DSL。

它展示了一个用于集成 Prolog 和 HTML 的强硬模型,但并不试图涵盖整个问题。客户端的“剩余逻辑”仍未明确,但这是合理的,面向 RDF“报告”的实际问题。

因此,“小细节”客户端交互逻辑以“黑匣子”方式处理,这对已发布应用程序中的 YUI 组件有这样的要求(获奖者 Cliopatria)。

该库是可扩展的,但非常详细,我想对于您的任务,您最终应该重用背后的想法。

SWI-Prolog library(http/html_write) library builds on DCG a DSL for page layout.

It shows a well tought model for integrating Prolog and HTML, but doesn't attempt to cover the entire problem. The 'residual logic' on the client side remains underspecified, but this is reasonable, being oriented on practical issues 'reporting' from RDF.

Thus the 'small detail' client interaction logic is handled in a 'black box' fashion, and such demanded to YUI components in the published application (the award winner Cliopatria).

The library it's extensible, but being very detailed, I guess for your task you should eventually reuse just the ideas behind.

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