0

I am interested in model an develop a new object pascal interpreter for web site scripting. We have PHP, Pearl, Java, Javabeans... But not Pascal as a option for web developers.

Since Delphi only works in Windows based servers...

I would like to do things like:

<input name="ClientName" value="<?pas write(ClintObj.Name); ?>">

or

<input name="ClientName" value="<?pas @ClintObj.GetName; ?>">

not just as a template, but just like PHP, something I could use with a MVC framework, or even create one:

<?pas
    System.Writeln('<html><head>...');
?>

Where should I start?

Or is it already done and I fail to find it? (for linux)

NaN
  • 8,596
  • 20
  • 79
  • 153

4 Answers4

2

Two existing products:

Oxygene

You can check out Oxygene, formerly known as Delphi Prism, formerly known as RemObjects Chrome.

They have found a way to compile a Pascal style language to Java. Not convert Pascal code to Java code, but actually compile it to the bytecode that runs in the Java runtime engine. Apart from that, they can also compile to the .NET runtime.

I don't know if you can use Oxygene for your purpose, but at least their product may give you some inspiration and some insight of the possibilities and difficulties of building something like that yourself.

PascalScript

Maybe you can use PascalScript, also by RemObjects. It is a script interpreter. So you can embed it in a server application. For instance, if you create an ISAPI application that embeds PascalScript, all you need to do is expose some 'write' method to the script to allow it to write output. All the application needs to do is output that output to ISS, and your basis server side Pascal scripting is done. After that, you can expose more convenience functions to the script to make it more useful.

PascalScript can be used in Delphi as well as FreePascal, so maybe you can make it work in Linux as well.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • How would it help to generate web site scripts? Java is not JavaScript. – mjn Jul 04 '13 at 14:38
  • It's about server side scripting. Doesn't have to be Javascript. Just saying that you could use a technique like that. You can also build a scripting engine from the ground up. Or you can use [PascalScript](http://www.remobjects.com/ps.aspx) also by RemObjects. No, I'm not affiliated. :D – GolezTrol Jul 04 '13 at 14:41
  • The requirements for web site scripting are quite specific, as a HTML page could have dozens of small script parts for all the various page elements, and doing it all in a mix of logic and presentation using Pascal quickly becomes fragile. Real world web frameworks OTOH are specially designed to solve this and support flexible and easy to understand composition of web pages. – mjn Jul 04 '13 at 14:54
  • *If* you decide to allow for mixing HTML and scripts, that is the case, but of course that's a design decision. And of course you could choose specific opening and closing tags to distinguish between HTML and the language, just as ASP and PHP have. I don't see how that would be more fragile using Pascal. I *do* see some obstacles when writing this yourself, since building a parser and lexical analizer is quite complicated, but that's more about writing a programming language in general and no specific obstacle for website scripting. – GolezTrol Jul 04 '13 at 14:58
  • Goleztrol: how is Oxygene scripted? Yes, it is serverside, but what runs is bytecode not source code. – Marco van de Voort Jul 05 '13 at 15:48
  • mjn: which is why I dislike website scripting, and prefer systems like ASP.NET that generate html+ client script from a consistent abstract representation – Marco van de Voort Jul 05 '13 at 15:50
  • @MarcovandeVoort I didn't say it's the same, but it is similar. Many steps from source to execution are the same. Both the script language and a compiled language need parsers, lexical analysers and expression trees. The main difference is that the compiler outputs instructions while the script engine immediately executes the statements. And if you don't like it, you can choose PascalScript. ;) – GolezTrol Jul 05 '13 at 16:01
  • GT: That hits the point I was trying to get across exactly. Is Prism closer to pascalscript or Delphi? I would say Delphi, not pascalscript or PHP or whatever. – Marco van de Voort Jul 06 '13 at 15:09
1

Writing such a interpreter is not a piece of cake:

  • your script files would need have be parsed, the contained Pascal code compiled / checked for syntax errors
  • as this compilation phase would be a CPU consuming task, the resulting object code would have to be cached for better performance
  • maybe you do not want to use / install the FPC or Delphi compiler on the server, then your language will be limited to what your compiler can suppport
  • the generated code needs access to "shared data" if different script parts need to interchange information or access global data, like a database

Also a critical functional requirement unless your application is stateless:

  • different users of the web site need their separate data (state), so your code needs to be session-aware (stateful)

Oh, one minor issue:

  • the application should not expose any vulnerabilites for malicious clients, see OWASP

So I guess this will be a long weekend ;-)

mjn
  • 36,362
  • 28
  • 176
  • 378
  • 2
    Baby steps. You can start by supporting single file only, and PHP 0.1 probably didn't support APC cache as well. The first version doesn't have to be fast nor have many features. Data is rarely shared, also in PHP. Two separate scripts don't have access to each others database connection. HTTP is stateless by definition, and sessions is just a trick in PHP. Also, once you've got your interpreter up and running, building state-support using session cookies will be trivial. :D It would be cool enough if you could just save a pas file on a server and run it. :) – GolezTrol Jul 04 '13 at 15:03
  • And a cool one. I hope you'll succeed, though the road will be long and slippery. ;) – GolezTrol Jul 04 '13 at 18:42
1

You are mixing embedding a scripting version of a language in templates with general web development in that language.

While Pascal isn't really used much as templating language, doing webdevelopment is perfectly possible, e.g. with http://brookframework.org/ and several Delphi component suites.

Some of the Delphi options also support Apache, and have supported Kylix in the past. I used webhub from http://www.href.com for a while.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
1

Don't forget about the free DelphiWebScript (DWS).

Though started as a Delphi-like WebScript language, it is a general purpose Delphi like language that can be used as a script, and also has a JIT compiler (though without it, the performance already is very good).

The main project compiles in Delphi (so it is Windows-only) but there is a FreePascal DelphiWebScript initiative to make it run on Linux too.

There are multiple demo web server projects to choose from so you can host your own DWS scripts, for instance the WebServer project which is based on http.sys version 2, then there are Indy based and Synopse based ones.

The development tool Smart Mobile Studio is using DWS to compile the forms and Pascal based source code into HTML5 and JavaScript then serve it from a web server to run in any HTML5/JavaScript compatible browser (including the mobile ones).

So there is a lot of power in DWS, demos and the eco system around it (:

Community
  • 1
  • 1
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154