开发者

Library like pyparsing for PHP

I would like to know: is there something like开发者_C百科 pyparsing (a recursive descent parser) for PHP?

I already looked for it, but it seems no one did it yet. I hope I am wrong.

Thank you in advance.


I don't know any maintained parser generators written in PHP. But there are parser generators written in other languages with PHP as a target language. One I have personally used is kmyacc. There is a PHP and Windows compatible fork of it. The grammar for it is written in yacc format and can be compiled to PHP using this command:

kmyacc -l -m %PARSER_PROTOTYPE_FILE% -p %NAME% %GRAMMAR_FILE%

Kmyacc already comes with a procedural parser prototype file for PHP, but I personally use a modified version of an OOP based prototype.

As an example: This grammar get's compiled into this parser. (Note that the grammar is huge, that's why the generated parser has two and a half thousand lines. A "normal" grammar would obviously be far smaller.)


If all you need to parse are "custom expressions", you can probably code a recursive descent parser by hand fairly easily, if you have already written down your grammar.

See this SO answer for details: Is there an alternative for flex/bison that is usable on 8-bit embedded systems?


You can try this:

http://pyparsing.wikispaces.com/message/view/home/41772107

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜