Alex Rivera | Logout

Generate AST of a PHP source file

Asked 2011-05-27T14:24:45.543
18

I want to parse a PHP source file, into an AST (preferably as a nested array of instructions).

I basically want to convert things like

f($a, $b + 1)

into something like

array( 'function_call',
    array(
        array( 'var', '$a' ),
        array( 'expression',
            array(
                array( 'binary_operation',
                    '+',
                    array ('var', '$b'),
                    array( 'int', '1' )
                )
            )
        )
    )
)

Are there any inbuilt PHP library or third party libraries (preferably in PHP) that would let me do this?

Edit
Report

1 Answer

2

Pfff is an OCaml library for parsing and manipulating PHP code. See the manual of Pfff for more details.

answered 2012-01-04T05:18:18.553

Your Answer