Tuesday, June 20, 2006

PHP source code analysis: PHPCompiler versus Yaxx

The original PHP compiler doesn’t use AST representation of a source code so in the previous versions of phpAspect I had to fill the php grammar with my own AST constructions. It was a painful job and moreover I had to do it in each major version of PHP. For this new version, I'm using the yaxx project written by Dr. Yijun Yu. The yaxx tool is a yacc skeleton which build an xml ast representation of a source code according to his grammar.
For example, the following php source code:


We will obtain the following Tree (with the php lexer & grammar in input):


Using this compiler structure, the common visitors of a traditional compiler becomes xslt style sheet. A toEval visitor becomes a toEval xslt style sheet etc... I already wrote a very simple toWrite visitor which just take care of writing the text into tokens.

The hardest part is now to perform weaving using xslt and the main limitation is that xslt variables are constants.

I keep you in touch ;o)

No comments:

Post a Comment