views:

113

answers:

3

See http://stackoverflow.com/questions/3243285/how-to-escape-quote-pph-strings-generated-by-delphi

I am just interested to hear if anyone has used Delphi (or possibly BCB) as a code generator for PHP ...

(or thoughts about code generation from one language to another in general)

Hmm, any good books about code generation ?

+1  A: 

I've generated javascript, SQL and Delphi many times. But mostly is basic substitution, (and the example in the post you mention looks the same), not really codegeneration in the "compiler" sense of the word.

But there are also many real compilers in Pascals and Delphi like dialects. The biggest one I think is Free Pascal (http://www.freepascal.org), which is a compiler for Object Pascal (aka delphi)

(added later:) Besides variable substitution, basic templating engines also fall in this category. Templates are sometimes easier maintainable than the same fragement code. Specially in html/cgi land this is used a lot.

Marco van de Voort
+1 Agreed, thanks for the difnition - yup, although I am "generating code", it is basically "substituting variables in strings"
Mawg
+1  A: 

You can generate anything from a tool which can export text files no?

You can write all by the hand, or in a "delphi style" by using Delphi for PHP http://www.embarcadero.com/products/delphi-for-php

best regards,

Radu Barbu
+1 for replying. Thanks. The problem is that I am eliant on some VCL compnents (and underlying Delphi code) which would require man years to rewrite - so I have to use a Delphi program to generate the PHP, alas
Mawg
+1  A: 

anyone has used Delphi (or possibly BCB) as a code generator for PHP

PHP - no, but I'm generating a lot of Delphi/Pascal code from Delphi. I've also generated all other things used for a web application: HTML, JavaScript, CSS - but never PHP because I didn't need that. So it's possible, but simply knowing it's possible is not going to help you much.

thoughts about code generation from one language to another in general

You need to look into "text template engines" for Delphi. I can't suggest any because I wrote my own (and I'm not planing on releasing my own under any license).

Cosmin Prund