Lex and Yacc in PHP

Rik Heywood picture Rik Heywood · Jan 19, 2010 · Viewed 10.6k times · Source

Is there an implementation of Lex and Yacc in PHP?

If not, can anyone suggest a lexical analyser and parser generator (ie, anything like Lex and Yacc) that will create PHP code. I'm not too worried about the performance of the resulting parser.

I am sick of using regex to parse things that really shouldn't be parsed with regex...

Answer

John Carter picture John Carter · Jan 19, 2010

There's JLexPHP: https://github.com/wez/JLexPHP/blob/master/jlex.php

I've not used it, but there's this: http://pear.php.net/package/PHP_ParserGenerator , which creates a PHP Parser from a Lemon grammar. The project seems to be inactive though.

I also found this project: http://code.google.com/p/antlrphpruntime/ , which uses Antlr. Again inactive though.