Since I am not about to add another language to the rather abundant number of scripting languages on offer, nor am I capable of doing such a development, I decided I could do a pre-compiler or, in this case a pre-interpreter, a program that would read and parse the source with the extended instructions and turn them into the plain base language. After some trials I settled (for the time being) on PHT, which is a merge of PHP and HTML though, of course, it generates XML, not just HTML. 

When I was satisfied with the syntax I tried to build the pre-compiler using YACC and Lex (actually, Bison and Flex) the same tools the PHP interpreter uses. It proved too much for me since I never had any formal training in computer science. Someone suggested I tried JavaCC, which I did, and in a couple of weeks I had a working parser, modified from a C parser which did nothing but go through the PHP source files parsing them. Two more weeks went by running the pre-compiler through the PHP 5.0 test suite fixing errors in the parser until I got to an acceptably short to-do list, and then added a single action to the whole parser, just a pass-through action for most of the code.

I modified the parser to add the <, & and ? instructions and the corresponding actions, which was unexpectedly easy, so in one more week I got to the point when I could actually write any of the previous examples into a .PHT file (then called .PhpSt) and pre-compile it to a .PHP file and it worked. So I started un-pre-compiling (going from regular PHP to PHT) some programs I had and running them through the pre-compiler and they worked! So far, I had my two blocks structures working nicely with each other, my editor a little confused but accepting it tolerably well and my pre-compiler running Ok. Even the PHP documenter ignored my added instructions and produced documentation without a problem.

But I realized I would never be able to grow this into what I wanted. Besides, the base I used for the pre-compiler was a C parser which might eventually prove not to work exactly as the PHP parser does and I was actually starting to find some cracks in it with some singular PHP constructs. Anyway, I learned a lot with it, which was good.

Fortunately, I saw an announcement for an open source PHP compiler, which seems to be defunct, not the equally open-source PHP interpreter, but a compiler which suited me far better. It provided me with a full parser for PHP version 5, which produced a very clear and sound tree representation of the program, and several unparsers, one of them back to cleaner PHP code and another two, a graphical representation and an XML representation, both of which give a clear view of how the tree is structured.

Most important of all, it has a very good programming interface to traverse and transform the tree. A few releases afterwards, the authors came with a plug-in interface, which made the whole project even easier, and that's what I used for the current release.

The original site for the PHP Compiler seems to be gone, as well as my link to the authors whom I meant to give credit for their work. Thus I dropped those links as well as my modified version of their compiler, which is now obsolete.

For details about the current release, you may follow the index below. To keep going with the overview, you may press Next > at the bottom.

< Previous: Formal Definition


Next: Validation >