I experienced before parser and lexer using PHP but without success, Wez have made this dream come true using Lemon and JLex. The parser and Lexer he made are available under BSD license. You need a C compiler to build lemon and a java compiler and runtime to build and run JLexPHP, but after having translated your .y and .lex files with these tools, you’re left with a pure PHP parser and lexer implementation. Thanks Wez for sharing this code with the community.

From time to time, I find that I need to put a parser together. Most of the time I find that I need to do this in C for performance, but other times I just want something convenient, like PHP, and have been out of luck. This thanksgiving I set out to remedy this and adapted lemon to optionally emit PHP code, and likewise with JLex.