2011-04-18 19:02:30 +02:00
|
|
|
This is a PHP parser written in PHP.
|
|
|
|
|
|
|
|
This project is work in progress, but it basically works and was tested on a large code base.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
$parser = new Parser();
|
2011-04-20 13:40:29 +02:00
|
|
|
$stmts = $parser->yyparse(
|
2011-04-18 19:02:30 +02:00
|
|
|
new Lexer('<?php // some code'),
|
|
|
|
function($msg) {
|
2011-04-20 13:40:29 +02:00
|
|
|
// this is the error callback, which is fired in case of
|
|
|
|
// a parse error. It is passed the error message.
|
2011-04-18 19:02:30 +02:00
|
|
|
echo $msg, "\n";
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2011-04-20 13:40:29 +02:00
|
|
|
// the return value of Parser->yyparse will either be false (which
|
|
|
|
// signifies that an error occured) or an array of statements (Nodes)
|
|
|
|
if (false !== $stmts) {
|
|
|
|
// dump the AST
|
|
|
|
foreach ($stmts as $stmt) {
|
|
|
|
echo $stmt, "\n";
|
|
|
|
}
|
|
|
|
}
|