Flex/Bison PHP AST 生成
这基本上是我的第一个问题的第二部分是关于制作源代码浏览器。阅读教程后,我发现我需要解析 PHP 文件并构建 AST,从那里我将获得我需要的符号。然而,几天来的搜索对我如何做到这一点没有任何帮助。是否有任何关于构建 PHP AST 的教程或问题已经得到解答? 抱歉,如果在某处得到回答,我的搜索没有找到任何有用的东西!
This is basically second part of my first Question which is about making source code browser. After reading tutorials I found that I need to parse PHP file and Build AST and from there I will have symbols I need. However, searching for days have brought nothing useful on how I can do that. Is there any tutorial or question already answered about building PHP AST?
Sorry if it is answered somewhere, my searches found nothing useful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以看看 PHP 是如何做到的: https:// svn.php.net/repository/php/php-src/trunk/Zend/zend_language_parser.y。请注意,PHP 使用 re2c 而不是 flex(语法在 ./zend_language_scanner.l 中)。
You can look at how PHP does it: https://svn.php.net/repository/php/php-src/trunk/Zend/zend_language_parser.y. Be advised though that PHP uses re2c instead of flex (grammar in ./zend_language_scanner.l).
2017 年有一个稳定且强大的工具 - PHP-Parser。
它允许对 PHP 源代码进行 TOKEN 解析和 AST 解析。
这是 AST 代码生成示例。
如果您寻找允许使用的 C 扩展,请检查 nikic/ast。
In 2017 there is stable and powerful tool for that - PHP-Parser.
It allows TOKEN parsing and AST parsing of the PHP source code.
Here is AST code generation example.
If you look for C extension that would allow it, check nikic/ast.