i'm looking for a ready-made grammar and parser for php (at least 5.2), ideally an utility/library that can parse php code into a readable AST, e.g. xml. The parser itself doesn't have to be written in php, the source language doesn't matter much.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- Sorting 3 numbers without branching [closed]
- Multiple sockets for clients to connect to
- PHP Recursively File Folder Scan Sorted by Modific
To answer my own question I've managed to compile phc on my OSX box, the parser part seems to work well
creates an xml representation of the AST.
phpParseTree
Our DMS Software Reengineering Toolkit is generalized compiler technology used to parse/analyzer/transform arbitrary computer langauges. It parses to ASTs, and has support for building symbol tables, and various types of flow graphs.
It has a PHP Front End that is fully PHP 5.x compliant, automatically builds full ASTs, using DMS as a foundation. It can export XML, but our experience (and the design of DMS) says you get a lot more milage by staying "inside" DMS with the AST data structure, doing your work there, with DMS's huge library of AST manipulation and pattern matching facilities, and then generating your result, rather than trying to handle the huge amounts of XML that you will get.
This front end has been used in a number of production tools.
EDIT: October 2016: Now handles PHP 5.6 and PHP 7.