Is it possible to parse PHP using PEG?

950 views Asked by At

The question is very straightforward: Is it possible to parse PHP using PEG? I want to use a PEG parser-generator to parse PHP. Please kindly advise. Thank you!

1

There are 1 answers

5
Ira Baxter On BEST ANSWER

You can make most parser technologies parse most languages, with sufficient effort.

Whether PEG will parse PHP without a lot of effort is a different question.

AFAIK, PHP itself uses Bison (LALR) so I assume PEG will likely handle the grammar supplied by the PHP distribution or something similar. And if you're going to use the PHP distribution, why not just use their supplied parser?

If you don't use the PHP distribution, your problems with parsing PHP are likely to be hard because you'll have to guess the language syntax from the online reference manual, (I've been there, and done that) which is frankly one of the worst ways to define a langauge I've ever seen: all it is is a bunch of examples.