Flex/Bison-like functionality within PHP

百般思念 提交于 2019-12-04 17:52:08

问题


I'm looking for a way to get Flex/Bison (or Lex/Yacc, et. al.) support in PHP. Specifically, I'm implementing a boolean query parser in a web UI and would rather keep all operations inside of PHP (as opposed to calling a C parser, or passing things off to Python, etc.).


回答1:


LIME Parser Generator for PHP:

Complete LALR(1) parser generator and engine (like BISON or YACC) but it's all done in PHP, and the input grammar is easier and more maintainable. Write your actions in PHP. Generate PHP output code. Drive your parser with PHP. Wanna make a language?


update:

Since I wrote the above, I see that there are some other tools for parser generation, announced here:

http://wezfurlong.org/blog/2006/nov/parser-and-lexer-generators-for-php/

Not sure if these are any better maintained now in 2014, but I know Wez Furlong, he was the original developer of PDO, and he is a very good developer.




回答2:


The PEAR library has the classes LexerGenerator and ParserGenerator. The LexerGenerator syntax is compatible with re2c, ParserGenerator syntax is compatible with the Lemon Parser generator.




回答3:


Have you tried looking at PEG parser generators in PHP: https://github.com/maetl/php-peg ?

Or a parser combinator approach: http://qntm.org/locoparser ?



来源:https://stackoverflow.com/questions/1003923/flex-bison-like-functionality-within-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!