A library similar to pyparsing for PHP

I would like to know: is there something like pyparsing (recursive descent parser) for PHP?
I was already looking for him, but nobody seemed to do it. I hope I'm wrong.

Thanks in advance.

+7
source share
3 answers

I do not know the supported parser generators written in PHP. But there are parser generators written in other languages ​​with PHP as the target language. The one I personally used was kmyacc. There is PHP and a Windows compatible plug . The grammar for it is written in yacc format and can be compiled in PHP using this command:

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

Kmyacc already has a prototype procedural parser prototype file for PHP, but I personally use a modified version of the prototype based on OOP .

As an example: This grammar is compiled into this parser . (Note that the grammar is huge, so the generated parser has two and a half thousand lines. The "normal" grammar will obviously be much smaller.)

+5
source

If all you need to parse is “custom expressions”, you can probably easily encode the recursive descent parser manually if you have already written the grammar.

See this answer for more details: Is there an alternative for flex / bison that can be used on 8-bit embedded systems?

+2
source
0
source

All Articles