I know question Lex and Yacc in PHP was asked before but 1 year ago.
Is there any new mature PHP parser generator now? My searches drove me to the following ones, what do you think about them, any others?
- code.google.com/p/antlrphpruntime/ : The ANTLR PHP version but it seems to be very beta version and I think there is a lot of work to do. The advantage is that I can write the grammar in the ANTLR Works tool.
- pear.php.net/package/PHP_ParserGenerator/docs/0.1.7/ : I tried but it seems very complicated, to be used with the PHP_LexerGenerator.
- sourceforge.net/projects/lime-php/ : I didn't try
- bitbucket.org/wez/lemon-php/downloads : I didn't try
- bitbucket.org/wez/jlexphp/downloads : I didn't try
[Answer :] Somebody gave me this wonderful link to an old question : Is there an alternative for flex/bison that is usable on 8-bit embedded systems?
This posts allowed me to understand most of the ANTLR code generated. So my choice keeps being the same : ANTLR although the project seems dead. I hope I wont have to alter the code as I would like to keep it maintainable.
I will wait a bit to see if there is another answer otherwise I'll accept your advise to keep using ANTLR
I'd propose to give ANTLR a try. ANTLRWorks might be helpful.
I wrote an LL(1) parser generator myself in pure PHP, since I wasn't aware of other PHP-based solutions.
I've ported Jison, a Bison clone in javascript, to php. The results are a killer parser, able to handle very simple and very complex lexing/parsing. It is now part of Jison, but there are a few updates in my fork.
The files are here. See the readme in that page, you create a javascript and php parser at the same time that are capable of doing the same or different things.
It is stable, fast, easy and fun to use.
There is PEG for php https://github.com/hafriedlander/php-peg
There's latest grammar file for PHP 7.4: https://github.com/php/php-src/blob/af12aa8124232b8fb6e96736e1232f6e0d2554e8/Zend/zend_language_parser.y
PHP using re2c parser generator, but as I know its syntax compatible with ANTLR.
来源:https://stackoverflow.com/questions/8002617/php-lexer-and-parser-generator