user187291 user187291 - 1 month ago 18
PHP Question

standalone grammar and parser for php

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.

Answer

To answer my own question I've managed to compile phc on my OSX box, the parser part seems to work well

 phc --dump-xml=ast foo.php > bar.xml

creates an xml representation of the AST.

Comments