Search code examples
phpyacclexparser-generator

Lex and Yacc in PHP


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...


Solution

  • 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.