Flex/Bison PHP AST 生成

发布于 2024-12-25 13:22:37 字数 270 浏览 2 评论 0原文

这基本上是我的第一个问题的第二部分是关于制作源代码浏览器。阅读教程后,我发现我需要解析 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦行僧 2025-01-01 13:22:37

你可以看看 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).

雪落纷纷 2025-01-01 13:22:37

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文