Prolog as a DSL to generate perl code?
Asked Answered
L

4

5

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

Llywellyn answered 22/2, 2011 at 12:31 Comment(2)
I'm not sure why you want a DSL here. Why not just have the Prolog emit Perl?Wun
It's not difficult to find DSL's written in Prolog or DSL's which generate Perl code, but it's a bit harder to search for their intersection. What kind of DSL (domain specific language) do you have in mind as an application?Lichtenfeld
P
4

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.

Pervert answered 25/2, 2011 at 20:48 Comment(1)
Thanks Christian, I will give the paper a read. Best Regards -TyLlywellyn
I
3

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.

Inapposite answered 22/2, 2011 at 21:51 Comment(1)
My hope was to find a way to describe the model with some extra descriptors such as display of columns and position etc. Then have this generate model classes as well as aspects of the view and control as well as some unit tests. DCG just looked very suited for this as you could literally use English sentences, but I needed to see some examples. I almost would consider using Parse::RecDescent. The hope was that I could rapidly prototype with this.Llywellyn
O
1

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.

Osterhus answered 22/2, 2011 at 12:59 Comment(1)
Prolog can do some things that are not trivially expressed in other language.Wun
C
1

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.

Chaos answered 22/12, 2011 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.