2
votes

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!

2

2 Answers

1
votes

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).

1
votes

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.