tags:

views:

32

answers:

3

I've been working in Javascript and PHP but I find that the hardest part isn't the implementation but the design of the webapp architecture [as usual . . .] In that direction, I wanted to create a sort of meta-language that takes PHP code as input but outputs JavaScript code thus making the design and implementation phase less painful [s.t. similar to GWT, Google Web Toolkit]. I found writing the this interpreter from scratch [parser, lexer, . . .] a viable option but an long one. Then I came across Processing.js [a library created by John Resig] where the user actually write java-like code that is transformed in Javascript by Processing.js then evaluated. I've searched the web for tutorials that introduces this powerful Javascript capability but didn't find even one! Can anyone PLEASE help me with any link, book title where I can get a least an intorduction? Thanx for your response!!!!

+1  A: 

How about creating some PHP-functions that generate JavaScript-code? I do not think that you really need to write an interpreter for a custom script language. Ruby on Rails used to generate some JavaScript with simple Ruby-code, for example.

elusive
Yeah, definitely a alternative. As you pointed out the Ruby example, it is what I actually want to achieve: it simplifies the implemetation to write in Ruby the server- and client-side code at once in one language. Any link about getting this done in PHP?
Eric
I do not know of anyone doing something like this. I would try to understand `rjs` (this is what its called in Rails) by looking at the documentation and implementing useful parts of it in PHP. It turns out that it is quite difficult to find a relevant documentation, though.
elusive
Actually if we can explore the solution provided by M28 bellow, I think its a good start for a project like this! Thanx again for grasping the interest and usefulness of the project quickly!
Eric
+1  A: 

I would say your best deal would be to go with haXe.

haXe is a language that is designed to target (be exported) into the following platforms:

  1. Javascript
  2. Flash
  3. PHP
  4. C++

Making it a very powerfull resource when creating web Apps as you can write in haXe and have all your code ported to Javascript, Flash, PHP or C++ without hassle.

Frankie
This the solution actually to the problem. But I really want the source language to be PHP [ok, only the syntax is necessary here since the target language is javascript] for mainly two reasons: it avoids me to learn a new language and my fellow PHP developers can benefit from my work. Any other suggestion is always useful!!!
Eric
A: 

Honestly, I think processing.js is not suitable for what you want, it was made to deal with the new canvas element, not the webpage.

Also, I think (honestly) think it sucks. They parse processing using Regex, it is totally wrong, you can't parse a programming language using Regex.

There is a javascript compiler compiler, called JS/CC, it is very easy to use, just learn the grammar and you can make a simple programming language.

But if you wanna make a complicated language (like processing, or php) by yourself, get ready for the nightmares.

PS: You'll need to know Javascript to implement a programming language in Javascript...

M28
Nice proposal with JS/CC! I'll definitely check it out. Actually I can't use Processing.js (it's for visual effects not what I mentionned). But you're 'half-rigth': John shouldn't use RegExp for parsing as 'context-free grammars' are the ideal tools for the task. But remember that context-free grammars are derived from RegExp and anything you can do with context-free grammars you can do it with RegExp. Thanx for the answer!
Eric