• PHP Lexer and Parser Generator Project
    11/13/2010 7:46PM

    Something very interesting I came across recently. A lexer and parser generator written in PHP that outputs PHP code. 



    In my efforts to improve the efficiency of the formVista Markup Language I've come to realize that contrary to what I thought, using PHP's "eval()" call even on a simple constant expression such as "$a=(bool)(3 < 4)" is ridiculously slow.

    So the thought is to write my own expression parser and on the first pass reduce these expression, using the original variable references into execution trees. I would write the lexer and parser by hand but would rather use a parser generator. It's less error prone.

    The upside of this is that parsing of expression is the one and only place in the many thousands of lines of PHP code I've written where I use eval(). Once I can replace it with my own expression parser the opportunity opens up to attempt to compile all this code using Facebook's PHP to C++ translator/compiler which would be interesting. Or I could run it on top of one of the java stacks.