Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog as a DSL to generate perl code?

Tags:

perl

dsl

prolog

dcg

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

like image 517
Bestfoodnearme.com Avatar asked Feb 22 '11 12:02

Bestfoodnearme.com


4 Answers

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.

like image 75
cth Avatar answered Nov 19 '22 11:11

cth


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.

like image 27
adamo Avatar answered Nov 19 '22 09:11

adamo


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.

like image 37
David Precious Avatar answered Nov 19 '22 10:11

David Precious


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.

like image 1
CapelliC Avatar answered Nov 19 '22 10:11

CapelliC